diff --git a/src/changes.rs b/src/changes.rs index 0cfba16..6e68980 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -1,21 +1,39 @@ +use octocrab::models::pulls::Review; +use octocrab::models::pulls::ReviewState::Approved; + #[derive(Clone, Debug)] pub struct RepoChangeset { - pub name: String, - pub remote: String, + pub name: String, + pub remote: String, pub base_commit: String, pub head_commit: String, - pub changes: Vec, + pub changes: Vec, } #[derive(Clone, Debug)] pub struct Changeset { - pub commits: Vec, - pub pr_link: Option, + pub commits: Vec, + pub pr_link: Option, pub approvals: Vec, } +impl Changeset { + pub fn collect_approved_reviews(&mut self, pr_reviews: &[Review]) { + for pr_review in pr_reviews { + // TODO: do we need to check if this is the last review of the user? + if pr_review.state == Some(Approved) { + let Some(ref user) = pr_review.user else { + continue; + }; + + self.approvals.push(user.login.clone()); + } + } + } +} + #[derive(Clone, Debug)] pub struct CommitMetadata { pub headline: String, - pub link: String, + pub link: String, } diff --git a/src/helm_config.rs b/src/helm_config.rs index 0d8f286..c3d0b5b 100644 --- a/src/helm_config.rs +++ b/src/helm_config.rs @@ -11,14 +11,14 @@ pub struct ImageRefs { #[derive(Debug, Serialize, Deserialize)] pub struct ImageRef { - pub account: String, + pub account: String, pub repository: String, - pub tag: String, - pub sources: Vec, + pub tag: String, + pub sources: Vec, } #[derive(Debug, Serialize, Deserialize)] pub struct SourceRepoRef { - pub repo: String, + pub repo: String, pub commit: String, } diff --git a/src/main.rs b/src/main.rs index d78b29e..f2adea4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,8 +14,6 @@ use git2::Repository; use helm_config::ImageRefs; use lazy_static::lazy_static; use octocrab::commits::PullRequestTarget; -use octocrab::models::pulls; -use octocrab::models::pulls::ReviewState; use octocrab::Octocrab; use url::Url; @@ -263,7 +261,7 @@ async fn find_reviews(octocrab: &Arc, repo: &mut RepoChangeset) -> Res if let Some(changeset) = repo.changes.iter_mut().find(|cs| cs.pr_link == associated_pr_link) { changeset.commits.push(change_commit.clone()); - collect_approved_reviews(&pr_reviews, changeset)?; + changeset.collect_approved_reviews(&pr_reviews); continue; } @@ -273,7 +271,7 @@ async fn find_reviews(octocrab: &Arc, repo: &mut RepoChangeset) -> Res approvals: Vec::new(), }; - collect_approved_reviews(&pr_reviews, &mut changeset)?; + changeset.collect_approved_reviews(&pr_reviews); repo.changes.push(changeset); } } @@ -316,24 +314,6 @@ fn print_changes(changes: &[RepoChangeset]) { } } -fn collect_approved_reviews(pr_reviews: &[pulls::Review], review: &mut Changeset) -> Result<(), anyhow::Error> { - for pr_review in pr_reviews { - // TODO: do we need to check if this is the last review of the user? - if pr_review.state.ok_or(anyhow!("review has no state"))? == ReviewState::Approved { - review.approvals.push( - pr_review - .user - .as_ref() - .ok_or(anyhow!("review without an user!?"))? - .login - .clone(), - ); - } - } - - Ok(()) -} - // for commits take the first 6 chars // https://github.com/sapcc/tenso/commit/39241382cc5de6ab54eb34f6ac09dfb740cbee701 // -> [tenso 392413](https://github.com/sapcc/tenso/commit/39241382cc5de6ab54eb34f6ac09dfb740cbee701)