-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathreview_submitted.rs
More file actions
75 lines (68 loc) · 2.34 KB
/
Copy pathreview_submitted.rs
File metadata and controls
75 lines (68 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use anyhow::Context as _;
use crate::config::ShortcutConfig;
use crate::github::{Issue, IssueCommentAction, IssueCommentEvent, Label, PullRequestReviewState};
use crate::{config::ReviewSubmittedConfig, github::Event, handlers::Context};
pub(crate) async fn handle(
ctx: &Context,
event: &Event,
config: &ReviewSubmittedConfig,
shortcut_config: Option<&ShortcutConfig>,
) -> anyhow::Result<()> {
if let Event::IssueComment(
event @ IssueCommentEvent {
action: IssueCommentAction::Created,
issue: Issue {
pull_request: Some(_),
..
},
..
},
) = event
{
if event.comment.pr_review_state != Some(PullRequestReviewState::ChangesRequested) {
return Ok(());
}
// Let's switch the review labels if the user who issued the changes requested:
// - is one of the assignees
// - or has write/admin permission on the repository
if event.issue.assignees.contains(&event.comment.user) || {
let perm = event
.issue
.repository()
.collaborator_permission(&ctx.github, &event.comment.user.login)
.await
.context("failed to get the user repository permission")?;
perm.permission.has_write_permissions()
} {
// Remove review labels
event
.issue
.remove_labels(
&ctx.github,
config
.review_labels
.iter()
.map(|label| Label {
name: label.clone(),
})
.collect(),
)
.await?;
// Add waiting on author
event
.issue
.add_labels(
&ctx.github,
vec![Label {
name: config.reviewed_label.clone(),
}],
)
.await?;
// Add reminder about `@bot review`
super::review_reminder::remind_author_of_bot_ready(ctx, &event.issue, shortcut_config)
.await
.context("failed to remind author of @bot review")?;
}
}
Ok(())
}