Skip to content

Commit 5285ce7

Browse files
LeSeulArtichautMark-Simulacrum
authored andcommitted
Fix the @rustbot prioritize command
1 parent 5ba2160 commit 5285ce7

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

src/handlers/prioritize.rs

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use parser::command::{Command, Input};
1010
pub(super) struct PrioritizeHandler;
1111

1212
pub(crate) enum Prioritize {
13+
Label,
1314
Start,
1415
End,
1516
}
@@ -60,7 +61,7 @@ impl Handler for PrioritizeHandler {
6061

6162
let mut input = Input::new(&body, &ctx.username);
6263
match input.parse_command() {
63-
Command::Prioritize(Ok(PrioritizeCommand)) => Ok(Some(Prioritize::Start)),
64+
Command::Prioritize(Ok(PrioritizeCommand)) => Ok(Some(Prioritize::Label)),
6465
_ => Ok(None),
6566
}
6667
}
@@ -86,19 +87,25 @@ async fn handle_input(
8687

8788
let mut labels = issue.labels().to_owned();
8889
let content = match cmd {
89-
Prioritize::Start => {
90-
// Don't add the label if it's already there, e.g., if this is a
91-
// labeled event
90+
Prioritize::Label => {
91+
// Don't add the label if it's already there
9292
if !labels.iter().any(|l| l.name == config.label) {
9393
labels.push(github::Label {
9494
name: config.label.clone(),
9595
});
96+
} else {
97+
// TODO maybe send a GitHub message if the label is already there,
98+
// i.e. the issue has already been requested for prioritization?
99+
return Ok(());
96100
}
97-
format!(
101+
None
102+
}
103+
Prioritize::Start => {
104+
Some(format!(
98105
"@*WG-prioritization* issue [#{}]({}) has been requested for prioritization.",
99106
issue.number,
100107
event.html_url().unwrap()
101-
)
108+
))
102109
}
103110
Prioritize::End => {
104111
// Shouldn't be necessary in practice as we only end on label
@@ -107,36 +114,39 @@ async fn handle_input(
107114
if let Some(idx) = labels.iter().position(|l| l.name == config.label) {
108115
labels.remove(idx);
109116
}
110-
format!(
117+
Some(format!(
111118
"Issue [#{}]({})'s prioritization request has been removed.",
112119
issue.number,
113120
event.html_url().unwrap()
114-
)
121+
))
115122
}
116123
};
117124

118125
let github_req = issue.set_labels(&ctx.github, labels);
119126

120-
let mut zulip_topic = format!(
121-
"{} {} {}",
122-
config.label,
123-
issue.zulip_topic_reference(),
124-
issue.title
125-
);
126-
zulip_topic.truncate(60); // Zulip limitation
127-
128-
let zulip_stream = config.zulip_stream.to_string();
129-
let zulip_req = crate::zulip::MessageApiRequest {
130-
type_: "stream",
131-
to: &zulip_stream,
132-
topic: Some(&zulip_topic),
133-
content: &content,
134-
};
135-
136-
let zulip_req = zulip_req.send(&ctx.github.raw());
137-
138-
let (gh_res, zulip_res) = futures::join!(github_req, zulip_req);
139-
gh_res?;
140-
zulip_res?;
141-
Ok(())
127+
if let Some(content) = content {
128+
let mut zulip_topic = format!(
129+
"{} {} {}",
130+
config.label,
131+
issue.zulip_topic_reference(),
132+
issue.title
133+
);
134+
zulip_topic.truncate(60); // Zulip limitation
135+
136+
let zulip_stream = config.zulip_stream.to_string();
137+
let zulip_req = crate::zulip::MessageApiRequest {
138+
type_: "stream",
139+
to: &zulip_stream,
140+
topic: Some(&zulip_topic),
141+
content: &content,
142+
};
143+
let zulip_req = zulip_req.send(&ctx.github.raw());
144+
let (gh_res, zulip_res) = futures::join!(github_req, zulip_req);
145+
gh_res?;
146+
zulip_res?;
147+
Ok(())
148+
} else {
149+
github_req.await?;
150+
Ok(())
151+
}
142152
}

0 commit comments

Comments
 (0)