diff --git a/src/changes.rs b/src/changes.rs index 95e9076..2c75b80 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -25,13 +25,18 @@ use crate::remote::Remote; pub struct RepoChangeset { pub name: String, pub remote: Remote, - pub base_commit: String, + pub base_commit: Option, pub head_commit: String, pub changes: Vec, } impl RepoChangeset { - pub fn new(name: String, remote: crate::Remote, base_commit: String, head_commit: String) -> RepoChangeset { + pub fn new( + name: String, + remote: crate::Remote, + base_commit: Option, + head_commit: String, + ) -> RepoChangeset { Self { name, remote, @@ -45,12 +50,15 @@ impl RepoChangeset { impl RepoChangeset { pub async fn analyze_commits(mut self) -> anyhow::Result { // if this is a newly introduced source, compare the commit to itself - if self.head_commit.is_empty() { - self.head_commit.clone_from(&self.base_commit); - self.base_commit += "^1"; + if self.base_commit.is_none() { + self.base_commit = Some(self.head_commit.clone()); + self.head_commit += "^1"; } - let compare_commits = self.remote.compare(&self.base_commit, &self.head_commit).await?; + let compare_commits = self + .remote + .compare(self.base_commit.as_deref().unwrap_or(""), &self.head_commit) + .await?; let mut join_set = JoinSet::new(); let remote = Arc::new(self.remote); diff --git a/src/main.rs b/src/main.rs index 5acb0d7..01e44fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -111,7 +111,7 @@ async fn main() -> Result<(), anyhow::Error> { let repo = RepoChangeset { name: remote.repository.clone(), remote, - base_commit: cli.base, + base_commit: Some(cli.base), head_commit: cli.head, changes: Vec::new(), }; @@ -181,8 +181,8 @@ fn find_values_yaml( changes.push(RepoChangeset::new( name.clone(), remote::Remote::parse(&new_source.repo)?, + None, new_source.commit.clone(), - String::new(), )); continue; } @@ -193,15 +193,15 @@ fn find_values_yaml( changes.push(RepoChangeset::new( name.clone(), remote::Remote::parse(&new_source.repo)?, + Some(old_source.commit.clone()), new_source.commit.clone(), - old_source.commit.clone(), )); } else { changes.push(RepoChangeset::new( name.clone(), remote::Remote::parse(&new_source.repo)?, + None, new_source.commit.clone(), - String::new(), )); } } @@ -228,7 +228,10 @@ fn print_changes(repo_changeset: &[RepoChangeset]) -> Result<(), any for change in repo_changeset { println_or_redirect(format!( "Name {} from {} moved from {} to {}", - change.name, change.remote.original, change.base_commit, change.head_commit, + change.name, + change.remote.original, + change.base_commit.as_deref().unwrap_or(""), + change.head_commit, ))?; println_or_redirect("| Commit link | Pull Request link | Approvals | Reviewer's verdict |".to_string())?; println_or_redirect("|-------------|-------------------|-----------|--------------------|".to_string())?;