Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] comment-changes: Stop at a Given Git Tag #797

Merged
merged 9 commits into from
Oct 17, 2023
8 changes: 8 additions & 0 deletions changelog.d/20231010_200141_GitHub_Actions_stop-at-tag.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(
references: {},
changes: {
"Added": [
"comment-changes: stop at a given Git tag",
],
},
)
41 changes: 38 additions & 3 deletions src/changelog/comment_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
\******************************************************************************/

use crate::{FragmentExportFormat, PatternWriter, ToMd, ToRon, ToRst};
use git2::Repository;
use git2::{Oid, Repository};
use indexmap::IndexMap;
use sysexits::{ExitCode, Result};

Expand Down Expand Up @@ -88,7 +88,11 @@ pub struct CommentChanges {

/// The commit to stop at.
#[arg(long, short = 'S')]
stop_at: Option<git2::Oid>,
stop_at: Option<Oid>,

/// The tag to stop at.
#[arg(long, short = 'T')]
tag: Option<String>,
kevinmatthes marked this conversation as resolved.
Show resolved Hide resolved

/// The hyperlinks' targets.
#[arg(long, short)]
Expand Down Expand Up @@ -124,6 +128,7 @@ impl CommentChanges {
link: Vec::new(),
output_directory: ".".to_string(),
stop_at: None,
tag: None,
target: Vec::new(),
}
}
Expand All @@ -136,6 +141,7 @@ impl CommentChanges {
cli: self.clone(),
hyperlinks: IndexMap::new(),
repository: None,
stop_at_tag_oid: None,
user: String::new(),
}
}
Expand All @@ -148,6 +154,7 @@ struct Logic {
cli: CommentChanges,
hyperlinks: crate::RonlogReferences,
repository: Option<Repository>,
stop_at_tag_oid: Option<Oid>,
user: String,
}

Expand Down Expand Up @@ -280,7 +287,29 @@ impl Logic {
},
|r| {
self.repository = Some(r);
Ok(())

if let Some(tag) = &self.cli.tag {
if let Some(repository) = &self.repository {
if let Ok(target) =
repository.resolve_reference_from_short_name(tag)
{
if target.is_tag() {
self.stop_at_tag_oid = target.target();
Ok(())
kevinmatthes marked this conversation as resolved.
Show resolved Hide resolved
} else {
eprintln!("{tag} does not seem to be a tag.");
Err(ExitCode::Usage)
}
kevinmatthes marked this conversation as resolved.
Show resolved Hide resolved
} else {
eprintln!("Tag {tag} does not seem to exist.");
Err(ExitCode::Usage)
}
kevinmatthes marked this conversation as resolved.
Show resolved Hide resolved
} else {
Err(ExitCode::Software)
}
} else {
Ok(())
}
},
)
}
Expand All @@ -305,6 +334,12 @@ impl Logic {
if stop_at == oid {
break;
}
} else if let Some(stop_at) =
self.stop_at_tag_oid
{
if stop_at == oid {
break;
}
kevinmatthes marked this conversation as resolved.
Show resolved Hide resolved
}

if let Ok(commit) = repository.find_commit(oid)
Expand Down