Skip to content

Commit

Permalink
wip: package changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
ABWassim committed Mar 14, 2024
1 parent 01cfa4a commit 3d8f3ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
20 changes: 15 additions & 5 deletions src/bin/cog/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ enum Command {
/// Name of the repository used during template generation
#[arg(long, requires_all = ["owner", "remote"])]
repository: Option<String>,

/// Generate the changelog for the specified package
#[arg(short, long)]
package: Option<String>,
},

/// Get current version
Expand Down Expand Up @@ -557,6 +561,7 @@ fn main() -> Result<()> {
remote,
owner,
repository,
package,
} => {
let cocogitto = CocoGitto::get()?;

Expand All @@ -569,15 +574,20 @@ fn main() -> Result<()> {
Template::default()
};

// TODO: fallback to tag here
let pattern = pattern.as_deref().unwrap_or("..");
let result = match at {
Some(at) => cocogitto.get_changelog_at_tag(&at, template)?,
let pattern = at.unwrap_or(pattern.as_deref().unwrap_or("..").to_string());

let result = match package {
Some(package) => {
let changelog =
cocogitto.get_changelog_for_package(&pattern, &package, true)?;
changelog.into_markdown(template)?
}
None => {
let changelog = cocogitto.get_changelog(pattern, true)?;
let changelog = cocogitto.get_changelog(&pattern, true)?;
changelog.into_markdown(template)?
}
};

println!("{result}");
}
Command::Init { path } => {
Expand Down
19 changes: 10 additions & 9 deletions src/command/changelog.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::conventional::changelog::release::Release;
use crate::conventional::changelog::template::Template;

use crate::CocoGitto;
use anyhow::anyhow;
use anyhow::Result;

impl CocoGitto {
Expand All @@ -14,11 +11,15 @@ impl CocoGitto {
Release::try_from(commit_range).map_err(Into::into)
}

pub fn get_changelog_at_tag(&self, tag: &str, template: Template) -> Result<String> {
let changelog = self.get_changelog(tag, false)?;

changelog
.into_markdown(template)
.map_err(|err| anyhow!(err))
pub fn get_changelog_for_package(
&self,
pattern: &str,
package: &str,
_with_child_releases: bool,
) -> Result<Release> {
let commit_range = self
.repository
.get_commit_range_for_package(pattern, package)?;
Release::try_from(commit_range).map_err(Into::into)
}
}

0 comments on commit 3d8f3ca

Please sign in to comment.