Skip to content

Commit ef22f9b

Browse files
authored
Merge pull request #2202 from Urgau/mcp-tracking-issue
Automatically create tracking issues when major change are accepted
2 parents 820288b + 16c51bc commit ef22f9b

File tree

2 files changed

+117
-8
lines changed

2 files changed

+117
-8
lines changed

src/config.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ pub(crate) struct MajorChangeConfig {
419419
pub(crate) zulip_stream: u64,
420420
/// Extra text in the opening major change.
421421
pub(crate) open_extra_text: Option<String>,
422+
/// Template for a tracking issue to be created when the major change is accepted
423+
#[serde(rename = "tracking-issue-template")]
424+
pub(crate) tracking_issue_template: Option<MajorChangeTrackingIssueTemplateConfig>,
422425
}
423426

424427
impl MajorChangeConfig {
@@ -433,6 +436,20 @@ impl MajorChangeConfig {
433436
}
434437
}
435438

439+
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
440+
#[serde(rename_all = "kebab-case")]
441+
#[serde(deny_unknown_fields)]
442+
pub(crate) struct MajorChangeTrackingIssueTemplateConfig {
443+
/// Template for the title
444+
pub(crate) title: String,
445+
/// Repository where to create the tracking issue (otherwise the current repository)
446+
pub(crate) repository: Option<String>,
447+
/// List of labels to add to the issue
448+
pub(crate) labels: Vec<String>,
449+
/// Template of the body
450+
pub(crate) body: String,
451+
}
452+
436453
#[derive(PartialEq, Eq, Debug, serde::Deserialize)]
437454
#[serde(deny_unknown_fields)]
438455
pub(crate) struct CloseConfig {}
@@ -1030,4 +1047,50 @@ mod tests {
10301047
})
10311048
));
10321049
}
1050+
1051+
#[test]
1052+
fn major_change() {
1053+
let config = r#"
1054+
[major-change]
1055+
enabling_label = "major-change"
1056+
meeting_label = "to-announce"
1057+
second_label = "final-comment-period"
1058+
concerns_label = "has-concerns"
1059+
accept_label = "major-change-accepted"
1060+
waiting_period = 1
1061+
auto_closing = true
1062+
zulip_stream = 224082
1063+
zulip_ping = "Urgau"
1064+
1065+
[major-change.tracking-issue-template]
1066+
repository = "triagebot"
1067+
title = "Tracking issue for MCP#${mcp_number}"
1068+
body = """
1069+
Multi text body with ${mcp_issue} and ${mcp_title}
1070+
"""
1071+
labels = ["C-tracking-issue", "T-compiler"]
1072+
"#;
1073+
let config = toml::from_str::<Config>(&config).unwrap();
1074+
assert_eq!(
1075+
config.major_change,
1076+
Some(MajorChangeConfig {
1077+
zulip_ping: "Urgau".to_string(),
1078+
enabling_label: "major-change".to_string(),
1079+
second_label: "final-comment-period".to_string(),
1080+
accept_label: "major-change-accepted".to_string(),
1081+
meeting_label: "to-announce".to_string(),
1082+
concerns_label: Some("has-concerns".to_string()),
1083+
waiting_period: 1,
1084+
auto_closing: true,
1085+
zulip_stream: 224082,
1086+
open_extra_text: None,
1087+
tracking_issue_template: Some(MajorChangeTrackingIssueTemplateConfig {
1088+
title: "Tracking issue for MCP#${mcp_number}".to_string(),
1089+
repository: Some("triagebot".to_string()),
1090+
body: "Multi text body with ${mcp_issue} and ${mcp_title}\n".to_string(),
1091+
labels: vec!["C-tracking-issue".to_string(), "T-compiler".to_string()],
1092+
})
1093+
})
1094+
);
1095+
}
10331096
}

src/handlers/major_change.rs

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl Job for MajorChangeAcceptenceJob {
519519

520520
let now = Utc::now();
521521

522-
match process_seconded(ctx, &major_change, now).await {
522+
match try_accept_mcp(ctx, &major_change, now).await {
523523
Ok(()) => {
524524
tracing::info!(
525525
"{}: major change ({:?}) as been accepted",
@@ -549,7 +549,7 @@ impl Job for MajorChangeAcceptenceJob {
549549
}
550550
}
551551

552-
async fn process_seconded(
552+
async fn try_accept_mcp(
553553
ctx: &super::Context,
554554
major_change: &MajorChangeSeconded,
555555
now: DateTime<Utc>,
@@ -581,17 +581,18 @@ async fn process_seconded(
581581
.await
582582
.context("unable to get the associated issue")?;
583583

584+
let (org, repo) = major_change
585+
.repo
586+
.split_once('/')
587+
.context("unable to split org/repo")?;
588+
584589
{
585590
// Static checks against the timeline to block the acceptance if the state changed between
586591
// the second and now (like concerns added, issue closed, ...).
587592
//
588593
// Note that checking the timeline is important as a concern could have been added and
589594
// resolved by the time we run, missing that this job should not run.
590595

591-
let (org, repo) = major_change
592-
.repo
593-
.split_once('/')
594-
.context("unable to split org/repo")?;
595596
let timeline = ctx
596597
.octocrab
597598
.issues(org, repo)
@@ -665,13 +666,58 @@ async fn process_seconded(
665666
}
666667

667668
if !issue.labels.iter().any(|l| l.name == config.accept_label) {
668-
// Only post the comment if the accept_label isn't set yet, we may be in a retry
669+
// Only create the tracking issue and post the comment if the accept_label isn't set yet, we may be in a retry.
670+
671+
let tracking_issue_text =
672+
if let Some(tracking_issue_template) = &config.tracking_issue_template {
673+
let issue_repo = crate::github::IssueRepository {
674+
organization: org.to_string(),
675+
repository: tracking_issue_template
676+
.repository
677+
.as_deref()
678+
.unwrap_or(repo)
679+
.to_string(),
680+
};
681+
682+
let fill_out = |input: &str| {
683+
input
684+
.replace("${mcp_number}", &issue.number.to_string())
685+
.replace("${mcp_title}", &issue.title)
686+
.replace("${mcp_author}", &issue.user.login)
687+
};
688+
689+
let title = fill_out(&tracking_issue_template.title);
690+
let body = fill_out(&tracking_issue_template.body);
691+
692+
let tracking_issue = ctx
693+
.github
694+
.new_issue(
695+
&issue_repo,
696+
&title,
697+
&body,
698+
tracking_issue_template.labels.clone(),
699+
)
700+
.await
701+
.context("unable to create MCP tracking issue")
702+
.with_context(|| format!("title: {title}"))
703+
.with_context(|| format!("body: {body}"))?;
704+
705+
format!(
706+
r"
707+
Progress of this major change will be tracked in the tracking issue at {}#{}.
708+
",
709+
&issue_repo, tracking_issue.number
710+
)
711+
} else {
712+
String::new()
713+
};
714+
669715
issue
670716
.post_comment(
671717
&ctx.github,
672718
&format!(
673719
r"The final comment period is now complete, this major change is now **accepted**.
674-
720+
{tracking_issue_text}
675721
As the automated representative, I would like to thank the author for their work and everyone else who contributed to this major change proposal.
676722
677723
*If you think this major change shouldn't have been accepted, feel free to remove the `{}` label and reopen this issue.*",

0 commit comments

Comments
 (0)