-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathshortcut.rs
More file actions
74 lines (66 loc) · 2.29 KB
/
Copy pathshortcut.rs
File metadata and controls
74 lines (66 loc) · 2.29 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
//! Purpose: Allow the use of single words shortcut to do specific actions on GitHub via comments.
//!
//! Parsing is done in the `parser::command::shortcut` module.
use crate::{
config::ShortcutConfig,
errors::user_error,
github::{Event, Label},
handlers::Context,
};
use anyhow::Context as _;
use parser::command::shortcut::ShortcutCommand;
pub(super) async fn handle_command(
ctx: &Context,
config: &ShortcutConfig,
event: &Event,
input: ShortcutCommand,
) -> anyhow::Result<()> {
let issue = event.issue().unwrap();
// NOTE: if shortcuts available to issues are created, they need to be allowed here
if !issue.is_pr() {
return user_error!(format!(
"The \"{input:?}\" shortcut only works on pull requests."
));
}
let issue_labels = issue.labels();
let waiting_on_review = "S-waiting-on-review";
let waiting_on_author = "S-waiting-on-author";
let blocked = "S-blocked";
let status_labels = [waiting_on_review, waiting_on_author, blocked, "S-inactive"];
let add = match input {
ShortcutCommand::Ready => waiting_on_review,
ShortcutCommand::Author => waiting_on_author,
ShortcutCommand::Blocked => blocked,
};
if !issue_labels.iter().any(|l| l.name == add) {
issue
.remove_labels(
&ctx.github,
status_labels
.iter()
.filter(|l| **l != add)
.map(|l| Label { name: (*l).into() })
.collect(),
)
.await?;
issue
.add_labels(
&ctx.github,
vec![Label {
name: add.to_owned(),
}],
)
.await?;
}
// We add a small reminder for the author to use `@bot ready` when ready
//
// Except if the author is a member (or the owner) of the repository, as
// the author should already know about the `ready` command and already
// have the required permissions to update the labels manually anyway.
if matches!(input, ShortcutCommand::Author) {
super::review_reminder::remind_author_of_bot_ready(ctx, issue, Some(config))
.await
.context("failed to send @bot review reminder")?;
}
Ok(())
}