-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathnominate.rs
More file actions
81 lines (72 loc) · 2.51 KB
/
Copy pathnominate.rs
File metadata and controls
81 lines (72 loc) · 2.51 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
76
77
78
79
80
81
//! Purpose: Allow team members to nominate issues or PRs.
use crate::{
config::NominateConfig,
errors::user_error,
github::{self, Event},
handlers::Context,
interactions::ErrorComment,
};
use parser::command::nominate::{NominateCommand, Style};
pub(super) async fn handle_command(
ctx: &Context,
config: &NominateConfig,
event: &Event,
cmd: NominateCommand,
) -> anyhow::Result<()> {
let is_team_member = matches!(ctx.team.is_team_member(&event.user().login).await, Ok(true));
if !is_team_member {
return user_error!(
"Nominating and approving issues and pull requests is restricted to members of the Rust teams."
);
}
let issue_labels = event.issue().unwrap().labels();
let mut labels_to_add = vec![];
if cmd.style == Style::BetaApprove {
if !issue_labels.iter().any(|l| l.name == "beta-nominated") {
let cmnt = ErrorComment::new(
event.issue().unwrap(),
format!(
"This pull request is not beta-nominated, so it cannot be approved yet.\
Perhaps try to beta-nominate it by using `@{} beta-nominate <team>`?",
ctx.username,
),
);
cmnt.post(&ctx.github).await?;
return Ok(());
}
// Add the beta-accepted label, but don't attempt to remove beta-nominated or the team
// label.
labels_to_add.push(github::Label {
name: "beta-accepted".into(),
});
} else {
if !config.teams.contains_key(&cmd.team) {
let cmnt = ErrorComment::new(
event.issue().unwrap(),
format!(
"This team (`{}`) cannot be nominated for via this command;\
it may need to be added to `triagebot.toml` on the default branch.",
cmd.team,
),
);
cmnt.post(&ctx.github).await?;
return Ok(());
}
let label = config.teams[&cmd.team].clone();
labels_to_add.push(github::Label { name: label });
let style_label = match cmd.style {
Style::Decision => "I-nominated",
Style::Beta => "beta-nominated",
Style::BetaApprove => unreachable!(),
};
labels_to_add.push(github::Label {
name: style_label.into(),
});
}
event
.issue()
.unwrap()
.add_labels(&ctx.github, labels_to_add)
.await?;
Ok(())
}