diff --git a/src/changes.rs b/src/changes.rs index b6f9e9b..5742bb4 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -13,10 +13,9 @@ // limitations under the License. use anyhow::{anyhow, Context}; -use octocrab::models::commits::Commit; use tokio::task::JoinSet; -use crate::github::Review; +use crate::github::{Commit, Review}; use crate::remote::Remote; #[derive(Clone, Debug)] @@ -30,10 +29,10 @@ pub struct RepoChangeset { impl RepoChangeset { pub async fn analyze_commits(mut self) -> Result { - let compare = self.remote.compare(&self.base_commit, &self.head_commit).await?; + let compare_commits = self.remote.compare(&self.base_commit, &self.head_commit).await?; let mut join_set = JoinSet::new(); - for commit in compare.commits { + for commit in compare_commits { join_set.spawn(self.clone().analyze_commit(commit)); } @@ -145,7 +144,6 @@ pub struct CommitMetadata { impl CommitMetadata { pub fn new(commit: &Commit) -> Self { let headline = commit - .commit .message .split('\n') .next() @@ -193,11 +191,11 @@ mod tests { user: "user2".to_owned(), }, Review { - approved: false, - commit_id: "00000000000000000000000000000003".to_owned(), - submitted_at: 3, - user: "user3".to_owned(), - }, + approved: false, + commit_id: "00000000000000000000000000000003".to_owned(), + submitted_at: 3, + user: "user3".to_owned(), + }, ], ) } @@ -205,14 +203,14 @@ mod tests { #[test] fn collect_approved_reviews() { let (mut changeset, pr_reviews) = gen_change_review(); - changeset.collect_approved_reviews(&pr_reviews, &"00000000000000000000000000000002".to_string()); + changeset.collect_approved_reviews(&pr_reviews, &"00000000000000000000000000000002".to_owned()); assert_eq!(changeset.approvals, vec!["user2"]); } #[test] fn collect_approved_reviews_extra_commit() { let (mut changeset, pr_reviews) = gen_change_review(); - changeset.collect_approved_reviews(&pr_reviews, &"00000000000000000000000000000003".to_string()); + changeset.collect_approved_reviews(&pr_reviews, &"00000000000000000000000000000003".to_owned()); assert_eq!(changeset.approvals, Vec::::new()); } } diff --git a/src/github.rs b/src/github.rs index cd138a6..6d38c3a 100644 --- a/src/github.rs +++ b/src/github.rs @@ -12,6 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#[derive(Clone, Debug)] +pub struct Commit { + pub html_url: String, + pub message: String, + pub sha: String, +} + #[derive(Clone, Debug)] pub struct Review { pub approved: bool, diff --git a/src/remote.rs b/src/remote.rs index c59bbba..2f188d1 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -16,7 +16,6 @@ use std::sync::Arc; use anyhow::{anyhow, bail, Context}; use octocrab::commits::PullRequestTarget; -use octocrab::models::commits::CommitComparison; use octocrab::models::pulls::{PullRequest, ReviewState}; use octocrab::models::repos::RepoCommit; use octocrab::Octocrab; @@ -24,6 +23,7 @@ use tokio::sync::SemaphorePermit; use url::Url; use crate::api_clients::Client; +use crate::github::Commit; use crate::github::Review; #[derive(Clone, Debug)] @@ -80,10 +80,10 @@ impl Remote { Ok(associated_prs_page.take_items()) } - pub async fn compare(&self, base_commit: &str, head_commit: &str) -> Result { + pub async fn compare(&self, base_commit: &str, head_commit: &str) -> Result, anyhow::Error> { let (_permit, octocrab) = self.get_client().await?; - octocrab + let compare = octocrab .commits(&self.owner, &self.repository) .compare(base_commit, head_commit) .send() @@ -93,7 +93,18 @@ impl Remote { self.original.trim_end_matches(".git"), &base_commit, &head_commit - )) + ))?; + + let mut commits: Vec = vec![]; + for commit in compare.commits { + commits.push(Commit { + html_url: commit.html_url, + message: commit.commit.message, + sha: commit.sha, + }); + } + + Ok(commits) } pub async fn pr_head_hash(&self, pr_number: u64) -> Result {