Skip to content

Commit 803cde7

Browse files
authored
Merge pull request #2072 from Urgau/improv_mcp-auto-close-concerns
Improve a major change handling of concerns and auto-close
2 parents 2ebc36b + deaf558 commit 803cde7

File tree

1 file changed

+58
-21
lines changed

1 file changed

+58
-21
lines changed

src/handlers/major_change.rs

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ pub(super) async fn handle_input(
208208
if event.issue.labels().contains(&Label {
209209
name: config.second_label.to_string(),
210210
}) {
211-
// Re-schedule acceptence job to automaticaly close the MCP
212-
schedule_acceptence_job(ctx, config, &event.issue).await?;
211+
// Re-schedule acceptance job to automaticaly close the MCP
212+
schedule_acceptance_job(ctx, config, &event.issue).await?;
213213

214214
format!("All concerns on the [associated GitHub issue]({}) have been resolved, this proposal is no longer blocked, and will be approved in 10 days if no (new) objections are raised.", event.issue.html_url)
215215
} else {
@@ -267,12 +267,31 @@ pub(super) async fn handle_command(
267267
return Ok(());
268268
}
269269

270-
let zulip_msg = format!(
271-
"@*{}*: Proposal [#{}]({}) has been seconded, and will be approved in 10 days if no objections are raised.",
272-
config.zulip_ping,
273-
issue.number,
274-
event.html_url().unwrap()
275-
);
270+
let has_concerns = if let Some(concerns_label) = &config.concerns_label {
271+
issue.labels().iter().any(|l| &l.name == concerns_label)
272+
} else {
273+
false
274+
};
275+
276+
let waiting_period = config.waiting_period.unwrap_or(10);
277+
278+
let zulip_msg = if !has_concerns {
279+
format!(
280+
"@*{}*: Proposal [#{}]({}) has been seconded, and will be approved in {} days if no objections are raised.",
281+
config.zulip_ping,
282+
issue.number,
283+
event.html_url().unwrap(),
284+
waiting_period,
285+
)
286+
} else {
287+
format!(
288+
"@*{}*: Proposal [#{}]({}) has been seconded, but there are unresolved concerns preventing approval, use `@{} resolve concern-name` in the GitHub thread to resolve them.",
289+
config.zulip_ping,
290+
issue.number,
291+
event.html_url().unwrap(),
292+
&ctx.username,
293+
)
294+
};
276295

277296
handle(
278297
ctx,
@@ -285,13 +304,15 @@ pub(super) async fn handle_command(
285304
.await
286305
.context("unable to process second command")?;
287306

288-
// Schedule acceptence job to automaticaly close the MCP
289-
schedule_acceptence_job(ctx, config, issue).await?;
307+
if !has_concerns {
308+
// Schedule acceptance job to automaticaly close the MCP
309+
schedule_acceptance_job(ctx, config, issue).await?;
310+
}
290311

291312
Ok(())
292313
}
293314

294-
async fn schedule_acceptence_job(
315+
async fn schedule_acceptance_job(
295316
ctx: &Context,
296317
config: &MajorChangeConfig,
297318
issue: &Issue,
@@ -428,7 +449,9 @@ enum SecondedLogicError {
428449
draft: bool,
429450
open: bool,
430451
},
431-
ConcernsLabelSet,
452+
NotAMajorChange,
453+
SecondLabelAbsent,
454+
ConcernsLabelPresent,
432455
NoMajorChangeConfig,
433456
}
434457

@@ -443,7 +466,9 @@ impl Display for SecondedLogicError {
443466
SecondedLogicError::IssueNotReady { draft, open } => {
444467
write!(f, "issue is not ready (draft: {draft}; open: {open})")
445468
}
446-
SecondedLogicError::ConcernsLabelSet => write!(f, "concerns label set"),
469+
SecondedLogicError::NotAMajorChange => write!(f, "not a major change"),
470+
SecondedLogicError::SecondLabelAbsent => write!(f, "second label is absent"),
471+
SecondedLogicError::ConcernsLabelPresent => write!(f, "concerns label set"),
447472
SecondedLogicError::NoMajorChangeConfig => write!(f, "no `[major_change]` config"),
448473
}
449474
}
@@ -477,7 +502,7 @@ impl Job for MajorChangeAcceptenceJob {
477502
match process_seconded(&ctx, &major_change, now).await {
478503
Ok(()) => {
479504
tracing::info!(
480-
"{}: major change ({:?}) as been accepted, remove from the queue",
505+
"{}: major change ({:?}) as been accepted",
481506
self.name(),
482507
&major_change,
483508
);
@@ -536,12 +561,17 @@ async fn process_seconded(
536561
.await
537562
.context("unable to get the associated issue")?;
538563

539-
if issue
540-
.labels
541-
.iter()
542-
.any(|l| Some(&l.name) == config.concerns_label.as_ref())
543-
{
544-
anyhow::bail!(SecondedLogicError::ConcernsLabelSet);
564+
if !issue.labels.iter().any(|l| l.name == config.enabling_label) {
565+
anyhow::bail!(SecondedLogicError::NotAMajorChange);
566+
}
567+
568+
if !issue.labels.iter().any(|l| l.name == config.second_label) {
569+
anyhow::bail!(SecondedLogicError::SecondLabelAbsent);
570+
}
571+
572+
let concerns_label = config.concerns_label.as_ref();
573+
if issue.labels.iter().any(|l| Some(&l.name) == concerns_label) {
574+
anyhow::bail!(SecondedLogicError::ConcernsLabelPresent);
545575
}
546576

547577
if !issue.is_open() || issue.draft {
@@ -556,7 +586,14 @@ async fn process_seconded(
556586
issue
557587
.post_comment(
558588
&ctx.github,
559-
"The final comment period is now complete, this major change is now accepted.\n\nAs the automated representative, I would like to thank the author for their work and everyone else who contributed to this major change proposal."
589+
&*format!(
590+
"The final comment period is now complete, this major change is now **accepted**.\
591+
\
592+
As the automated representative, I would like to thank the author for their work and everyone else who contributed to this major change proposal.\
593+
\
594+
*If you think this major change shouldn't have been accepted, feel free to remove the `{}` label and reopen this issue.*",
595+
&config.accept_label,
596+
),
560597
)
561598
.await
562599
.context("unable to post the acceptance comment")?;

0 commit comments

Comments
 (0)