Skip to content

Commit

Permalink
Use proper type instead of empty string, fix base and head confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Sep 30, 2024
1 parent 0fdc47a commit 1d16fe9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
20 changes: 14 additions & 6 deletions src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ use crate::remote::Remote;
pub struct RepoChangeset<C: Client> {
pub name: String,
pub remote: Remote<C>,
pub base_commit: String,
pub base_commit: Option<String>,
pub head_commit: String,
pub changes: Vec<Changeset>,
}

impl<C: Client> RepoChangeset<C> {
pub fn new(name: String, remote: crate::Remote<C>, base_commit: String, head_commit: String) -> RepoChangeset<C> {
pub fn new(
name: String,
remote: crate::Remote<C>,
base_commit: Option<String>,
head_commit: String,
) -> RepoChangeset<C> {
Self {
name,
remote,
Expand All @@ -45,12 +50,15 @@ impl<C: Client> RepoChangeset<C> {
impl<C: Client + Sync + Send + 'static> RepoChangeset<C> {
pub async fn analyze_commits(mut self) -> anyhow::Result<Self> {
// 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);
Expand Down
13 changes: 8 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down Expand Up @@ -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;
}
Expand All @@ -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(),
));
}
}
Expand All @@ -228,7 +228,10 @@ fn print_changes(repo_changeset: &[RepoChangeset<RealClient>]) -> 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())?;
Expand Down

0 comments on commit 1d16fe9

Please sign in to comment.