Skip to content

Commit

Permalink
Only consider last review by user
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Aug 16, 2024
1 parent fdb9600 commit f307ad2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 25 additions & 8 deletions src/changes.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::sync::Arc;

use crate::util::Remote;
use anyhow::{anyhow, Context};
use octocrab::commits::PullRequestTarget;
use octocrab::models::commits::Commit;
use octocrab::models::pulls::Review;
use octocrab::models::pulls::ReviewState::Approved;
use octocrab::Octocrab;

use crate::util::Remote;

#[derive(Clone, Debug)]
pub struct RepoChangeset {
pub name: String,
Expand Down Expand Up @@ -73,7 +74,8 @@ impl RepoChangeset {
pr_reviews_page.next.is_none(),
"found more than one page for associated_prs"
);
let pr_reviews = pr_reviews_page.take_items();
let mut pr_reviews = pr_reviews_page.take_items();
pr_reviews.sort_by_key(|r| r.submitted_at);

let associated_pr_link = Some(
associated_pr
Expand Down Expand Up @@ -111,14 +113,29 @@ pub struct Changeset {
}

impl Changeset {
// pr_reviews must be sorted by key submitted_at!
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;
};
let mut last_review_by: Vec<&String> = vec![];

// reverse the order of reviews to start with the oldest
for pr_review in pr_reviews.iter().rev() {
let Some(ref user) = pr_review.user else {
continue;
};

// only consider the last review of any user
if last_review_by.contains(&&user.login) {
continue;
}
last_review_by.push(&user.login);

// in case it isn't approve, ignore it
if pr_review.state != Some(Approved) {
continue;
}

// don't duplicate user names
if !self.approvals.contains(&user.login) {
self.approvals.push(user.login.clone());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn print_changes(changes: &[RepoChangeset]) {
},
None => String::new(),
},
commit_change.approvals.join("None"),
commit_change.approvals.join(", "),
);
}
}
Expand Down

0 comments on commit f307ad2

Please sign in to comment.