Skip to content

Commit c59b16a

Browse files
Enable configuring major-change/major-change-accepted labels (#1620)
This will let the libs-api team use slightly different labels here.
1 parent 31100ff commit c59b16a

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

src/config.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,39 @@ pub(crate) struct NotifyZulipLabelConfig {
150150

151151
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
152152
pub(crate) struct MajorChangeConfig {
153+
/// A username (typically a group, e.g. T-lang) to ping on Zulip for newly
154+
/// opened proposals.
153155
pub(crate) zulip_ping: String,
156+
/// This label allows an issue to participate in the major change process
157+
/// (i.e., creates a Zulip thread, tracks seconding, etc.)
158+
// This has a default primarily for backwards compatibility.
159+
#[serde(default = "MajorChangeConfig::enabling_label_default")]
160+
pub(crate) enabling_label: String,
161+
/// This is the label applied when issuing a `@rustbot second` command, it
162+
/// indicates that the proposal has moved into the 10 day waiting period.
154163
pub(crate) second_label: String,
164+
/// This is the label applied after the waiting period has successfully
165+
/// elapsed (currently not automatically applied; this must be done
166+
/// manually).
167+
// This has a default primarily for backwards compatibility.
168+
#[serde(default = "MajorChangeConfig::accept_label_default")]
169+
pub(crate) accept_label: String,
170+
/// This is the label to be added to newly opened proposals, so they can be
171+
/// discussed in a meeting.
155172
pub(crate) meeting_label: String,
156173
pub(crate) zulip_stream: u64,
157174
pub(crate) open_extra_text: Option<String>,
158175
}
159176

177+
impl MajorChangeConfig {
178+
fn enabling_label_default() -> String {
179+
String::from("major-change")
180+
}
181+
fn accept_label_default() -> String {
182+
String::from("major-change-accepted")
183+
}
184+
}
185+
160186
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
161187
pub(crate) struct GlacierConfig {}
162188

src/handlers/major_change.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ pub enum Invocation {
1818
pub(super) async fn parse_input(
1919
_ctx: &Context,
2020
event: &IssuesEvent,
21-
_config: Option<&MajorChangeConfig>,
21+
config: Option<&MajorChangeConfig>,
2222
) -> Result<Option<Invocation>, String> {
23+
let config = if let Some(config) = config {
24+
config
25+
} else {
26+
return Ok(None);
27+
};
28+
let enabling_label = config.enabling_label.as_str();
29+
2330
if event.action == IssuesAction::Edited {
2431
if let Some(changes) = &event.changes {
2532
if let Some(previous_title) = &changes.title {
@@ -32,13 +39,12 @@ pub(super) async fn parse_input(
3239
.issue
3340
.labels()
3441
.iter()
35-
.any(|l| l.name == "major-change")
42+
.any(|l| l.name == enabling_label)
3643
{
3744
return Ok(Some(Invocation::Rename { prev_issue }));
3845
} else {
39-
// Ignore renamed issues without major-change label
40-
// to avoid warning about the major-change feature not being
41-
// enabled.
46+
// Ignore renamed issues without primary label (e.g., major-change)
47+
// to avoid warning about the feature not being enabled.
4248
return Ok(None);
4349
}
4450
}
@@ -53,7 +59,7 @@ pub(super) async fn parse_input(
5359
&& event
5460
.label
5561
.as_ref()
56-
.map_or(false, |l| l.name == "major-change-accepted")
62+
.map_or(false, |l| l.name == config.accept_label)
5763
{
5864
return Ok(Some(Invocation::AcceptedProposal));
5965
}
@@ -69,12 +75,12 @@ pub(super) async fn parse_input(
6975
.issue
7076
.labels()
7177
.iter()
72-
.any(|l| l.name == "major-change"))
78+
.any(|l| l.name == enabling_label))
7379
|| (event.action == IssuesAction::Labeled
7480
&& event
7581
.label
7682
.as_ref()
77-
.map_or(false, |l| l.name == "major-change"))
83+
.map_or(false, |l| l.name == enabling_label))
7884
{
7985
return Ok(Some(Invocation::NewProposal));
8086
}
@@ -93,11 +99,14 @@ pub(super) async fn handle_input(
9399
.issue
94100
.labels()
95101
.iter()
96-
.any(|l| l.name == "major-change")
102+
.any(|l| l.name == config.enabling_label)
97103
{
98104
let cmnt = ErrorComment::new(
99105
&event.issue,
100-
"This is not a major change (it lacks the `major-change` label).",
106+
format!(
107+
"This issue is not ready for proposals; it lacks the `{}` label.",
108+
config.enabling_label
109+
),
101110
);
102111
cmnt.post(&ctx.github).await?;
103112
return Ok(());
@@ -152,7 +161,8 @@ pub(super) async fn handle_input(
152161
let new_topic_url = crate::zulip::Recipient::Stream {
153162
id: config.zulip_stream,
154163
topic: &new_topic,
155-
}.url();
164+
}
165+
.url();
156166
let breadcrumb_comment = format!(
157167
"The associated GitHub issue has been renamed. Please see the [renamed Zulip topic]({}).",
158168
new_topic_url
@@ -191,10 +201,17 @@ pub(super) async fn handle_command(
191201
) -> anyhow::Result<()> {
192202
let issue = event.issue().unwrap();
193203

194-
if !issue.labels().iter().any(|l| l.name == "major-change") {
204+
if !issue
205+
.labels()
206+
.iter()
207+
.any(|l| l.name == config.enabling_label)
208+
{
195209
let cmnt = ErrorComment::new(
196210
&issue,
197-
"This is not a major change (it lacks the `major-change` label).",
211+
&format!(
212+
"This issue cannot be seconded; it lacks the `{}` label.",
213+
config.enabling_label
214+
),
198215
);
199216
cmnt.post(&ctx.github).await?;
200217
return Ok(());

0 commit comments

Comments
 (0)