Skip to content

Commit ca35b2f

Browse files
authored
Merge pull request #2211 from Urgau/review-changes-requested-write
Switch review labels for users with write perm when requesting changes
2 parents 3fe53db + b9f6b5c commit ca35b2f

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/github.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,11 @@ pub enum Selection<'a, T: ?Sized> {
554554
Except(&'a T),
555555
}
556556

557+
#[derive(Debug, serde::Deserialize)]
558+
pub struct CollaboratorPermission {
559+
pub permission: String,
560+
}
561+
557562
#[derive(Debug, Clone, PartialEq, Eq)]
558563
pub struct IssueRepository {
559564
pub organization: String,
@@ -594,6 +599,16 @@ impl IssueRepository {
594599
}
595600
}
596601
}
602+
603+
pub(crate) async fn collaborator_permission(
604+
&self,
605+
client: &GithubClient,
606+
username: &str,
607+
) -> anyhow::Result<CollaboratorPermission> {
608+
let url = format!("{}/collaborators/{username}/permission", self.url(client));
609+
let permission = client.json(client.get(&url)).await?;
610+
Ok(permission)
611+
}
597612
}
598613

599614
impl Issue {

src/handlers/review_submitted.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use anyhow::Context as _;
2+
13
use crate::github::{Issue, IssueCommentAction, IssueCommentEvent, Label, PullRequestReviewState};
24
use crate::{config::ReviewSubmittedConfig, github::Event, handlers::Context};
35

@@ -21,7 +23,19 @@ pub(crate) async fn handle(
2123
return Ok(());
2224
}
2325

24-
if event.issue.assignees.contains(&event.comment.user) {
26+
// Let's switch the review labels if the user who issued the changes requested:
27+
// - is one of the assignees
28+
// - or has write/admin permission on the repository
29+
if event.issue.assignees.contains(&event.comment.user) || {
30+
let perm = event
31+
.issue
32+
.repository()
33+
.collaborator_permission(&ctx.github, &event.comment.user.login)
34+
.await
35+
.context("failed to get the user repository permission")?;
36+
37+
perm.permission == "write" || perm.permission == "admin"
38+
} {
2539
// Remove review labels
2640
event
2741
.issue

0 commit comments

Comments
 (0)