|
|
@ -1,56 +1,21 @@ |
|
|
|
use crate::AppContext; |
|
|
|
use crate::AppContext; |
|
|
|
use crate::config::ChannelName; |
|
|
|
use crate::config::ChannelName; |
|
|
|
use crate::git::{BranchName, get_branch_name}; |
|
|
|
use crate::git::get_branch_name; |
|
|
|
use crate::store::{Release, Store}; |
|
|
|
use crate::store::{Release, Store}; |
|
|
|
use anyhow::bail; |
|
|
|
use anyhow::bail; |
|
|
|
use colored::Colorize; |
|
|
|
use colored::Colorize; |
|
|
|
|
|
|
|
|
|
|
|
pub fn pack_resolve_and_show_preview( |
|
|
|
/// Perform the action of packing changelog entries for a release
|
|
|
|
ctx: &AppContext, |
|
|
|
pub(crate) fn cl_pack(ctx: AppContext, channel: Option<ChannelName>) -> anyhow::Result<()> { |
|
|
|
user_chosen_channel: Option<ChannelName>, |
|
|
|
let mut store = Store::new(&ctx, false)?; |
|
|
|
branch: Option<&BranchName>, |
|
|
|
let branch = get_branch_name(&ctx); |
|
|
|
) -> anyhow::Result<Option<(Release, ChannelName)>> { |
|
|
|
|
|
|
|
let channel = resolve_channel(&ctx, user_chosen_channel, branch)?; |
|
|
|
|
|
|
|
let store = Store::new(&ctx, false)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let unreleased = store.find_unreleased_changes(&channel)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if unreleased.is_empty() { |
|
|
|
|
|
|
|
eprintln!("No unreleased changes."); |
|
|
|
|
|
|
|
return Ok(None); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!(); |
|
|
|
|
|
|
|
println!("Changes waiting for release:"); |
|
|
|
|
|
|
|
for entry in &unreleased { |
|
|
|
|
|
|
|
println!("+ {}", entry.cyan()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
println!(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let release = Release { |
|
|
|
|
|
|
|
version: "Unreleased".to_string(), |
|
|
|
|
|
|
|
entries: unreleased, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let rendered = store.render_release(&release)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("\nPreview:\n\n{}", rendered); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(Some((release, channel))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Resolve channel from current branch or other context info, ask if needed
|
|
|
|
let (channel_detected, channel_explicit) = match channel { |
|
|
|
fn resolve_channel( |
|
|
|
|
|
|
|
ctx: &AppContext, |
|
|
|
|
|
|
|
user_chosen_channel: Option<ChannelName>, |
|
|
|
|
|
|
|
branch: Option<&BranchName>, |
|
|
|
|
|
|
|
) -> anyhow::Result<ChannelName> { |
|
|
|
|
|
|
|
let (channel_detected, channel_explicit) = match user_chosen_channel { |
|
|
|
|
|
|
|
Some(ch) => (Some(ch), true), // passed via flag already
|
|
|
|
Some(ch) => (Some(ch), true), // passed via flag already
|
|
|
|
None => ( |
|
|
|
None => ( |
|
|
|
branch |
|
|
|
branch |
|
|
|
.as_ref() |
|
|
|
.as_ref() |
|
|
|
.map(|b| b.parse_channel(ctx)) |
|
|
|
.map(|b| b.parse_channel(&ctx)) |
|
|
|
.transpose()? |
|
|
|
.transpose()? |
|
|
|
.flatten(), |
|
|
|
.flatten(), |
|
|
|
false, |
|
|
|
false, |
|
|
@ -63,6 +28,22 @@ fn resolve_channel( |
|
|
|
bail!("No such channel: {ch}"); |
|
|
|
bail!("No such channel: {ch}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the branch is named rel/3.40, this can extract 3.40.
|
|
|
|
|
|
|
|
// TODO try to get something better from git!
|
|
|
|
|
|
|
|
let version_base = branch |
|
|
|
|
|
|
|
.as_ref() |
|
|
|
|
|
|
|
.map(|b| b.parse_version(&ctx)) |
|
|
|
|
|
|
|
.transpose()? |
|
|
|
|
|
|
|
.flatten(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO detect version from git query?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO remove this
|
|
|
|
|
|
|
|
eprintln!( |
|
|
|
|
|
|
|
"Branch name: {:?}, channel: {:?}, version: {:?}", |
|
|
|
|
|
|
|
branch, channel_detected, version_base |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Ask for the channel
|
|
|
|
// Ask for the channel
|
|
|
|
let channel = if ctx.config.channels.len() > 1 { |
|
|
|
let channel = if ctx.config.channels.len() > 1 { |
|
|
|
if channel_explicit { |
|
|
|
if channel_explicit { |
|
|
@ -85,31 +66,19 @@ fn resolve_channel( |
|
|
|
}; |
|
|
|
}; |
|
|
|
println!("Channel: {}", channel.green().bold()); |
|
|
|
println!("Channel: {}", channel.green().bold()); |
|
|
|
|
|
|
|
|
|
|
|
Ok(channel) |
|
|
|
let unreleased = store.find_unreleased_changes(&channel)?; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Perform the action of packing changelog entries for a release
|
|
|
|
if unreleased.is_empty() { |
|
|
|
pub(crate) fn cl_pack( |
|
|
|
eprintln!("No unreleased changes."); |
|
|
|
ctx: AppContext, |
|
|
|
|
|
|
|
user_chosen_channel: Option<ChannelName>, |
|
|
|
|
|
|
|
) -> anyhow::Result<()> { |
|
|
|
|
|
|
|
let branch = get_branch_name(&ctx); |
|
|
|
|
|
|
|
let Some((mut release, channel)) = |
|
|
|
|
|
|
|
pack_resolve_and_show_preview(&ctx, user_chosen_channel, branch.as_ref())? |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
// No changes
|
|
|
|
|
|
|
|
return Ok(()); |
|
|
|
return Ok(()); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let mut store = Store::new(&ctx, false)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If the branch is named rel/3.40, this can extract 3.40.
|
|
|
|
println!(); |
|
|
|
// TODO try to get something better from git!
|
|
|
|
println!("Changes waiting for release:"); |
|
|
|
let version_base = branch |
|
|
|
for entry in &unreleased { |
|
|
|
.as_ref() |
|
|
|
println!("+ {}", entry.cyan()); |
|
|
|
.map(|b| b.parse_version(&ctx)) |
|
|
|
} |
|
|
|
.transpose()? |
|
|
|
println!(); |
|
|
|
.flatten(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ask for the version
|
|
|
|
// Ask for the version
|
|
|
|
let mut version = version_base.unwrap_or_default(); |
|
|
|
let mut version = version_base.unwrap_or_default(); |
|
|
@ -130,7 +99,14 @@ pub(crate) fn cl_pack( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
release.version = version; |
|
|
|
let release = Release { |
|
|
|
|
|
|
|
version, |
|
|
|
|
|
|
|
entries: unreleased, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let rendered = store.render_release(&release)?; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("\n\nPreview:\n\n{}\n", rendered); |
|
|
|
|
|
|
|
|
|
|
|
if !inquire::Confirm::new("Continue - write to changelog file?") |
|
|
|
if !inquire::Confirm::new("Continue - write to changelog file?") |
|
|
|
.with_default(true) |
|
|
|
.with_default(true) |
|
|
|