|
| 1 | +//! This handler implements collecting release notes from issues and PRs that are tagged with |
| 2 | +//! `relnotes`. Any such tagging will open a new issue in rust-lang/rust responsible for tracking |
| 3 | +//! the inclusion in releases notes. |
| 4 | +//! |
| 5 | +//! The new issue will be closed when T-release has added the text proposed (tracked in the issue |
| 6 | +//! description) into the final release notes PR. |
| 7 | +//! |
| 8 | +//! The issue description will be edited manually by teams through the GitHub UI -- in the future, |
| 9 | +//! we might add triagebot support for maintaining that text via commands or similar. |
| 10 | +//! |
| 11 | +//! These issues will also be automatically milestoned when their corresponding PR or issue is. In |
| 12 | +//! the absence of a milestone, T-release is responsible for ascertaining which release is |
| 13 | +//! associated with the issue. |
| 14 | +
|
| 15 | +use serde::{Deserialize, Serialize}; |
| 16 | + |
| 17 | +use crate::{ |
| 18 | + db::issue_data::IssueData, |
| 19 | + github::{Event, IssuesAction}, |
| 20 | + handlers::Context, |
| 21 | +}; |
| 22 | + |
| 23 | +const RELNOTES_KEY: &str = "relnotes"; |
| 24 | + |
| 25 | +#[derive(Debug, Default, Deserialize, Serialize)] |
| 26 | +struct RelnotesState { |
| 27 | + relnotes_issue: Option<u64>, |
| 28 | +} |
| 29 | + |
| 30 | +pub async fn handle(ctx: &Context, event: &Event) -> anyhow::Result<()> { |
| 31 | + let Event::Issue(e) = event else { |
| 32 | + return Ok(()); |
| 33 | + }; |
| 34 | + |
| 35 | + let repo = e.issue.repository(); |
| 36 | + if !(repo.organization == "rust-lang" && repo.repository == "rust") { |
| 37 | + return Ok(()); |
| 38 | + } |
| 39 | + |
| 40 | + if e.issue |
| 41 | + .title |
| 42 | + .starts_with("Tracking issue for release notes") |
| 43 | + { |
| 44 | + // Ignore these issues -- they're otherwise potentially self-recursive. |
| 45 | + return Ok(()); |
| 46 | + } |
| 47 | + |
| 48 | + let mut client = ctx.db.get().await; |
| 49 | + let mut state: IssueData<'_, RelnotesState> = |
| 50 | + IssueData::load(&mut client, &e.issue, RELNOTES_KEY).await?; |
| 51 | + |
| 52 | + if let Some(paired) = state.data.relnotes_issue { |
| 53 | + // Already has a paired release notes issue. |
| 54 | + |
| 55 | + if let IssuesAction::Milestoned = &e.action { |
| 56 | + if let Some(milestone) = &e.issue.milestone { |
| 57 | + ctx.github |
| 58 | + .set_milestone(&e.issue.repository().to_string(), &milestone, paired) |
| 59 | + .await?; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + return Ok(()); |
| 64 | + } |
| 65 | + |
| 66 | + if let IssuesAction::Labeled { label } = &e.action { |
| 67 | + if label.name == "relnotes" || label.name == "relnotes-perf" { |
| 68 | + let title = format!( |
| 69 | + "Tracking issue for release notes of #{}: {}", |
| 70 | + e.issue.number, e.issue.title |
| 71 | + ); |
| 72 | + let body = format!( |
| 73 | + " |
| 74 | +This issue tracks the release notes text for #{}. |
| 75 | +
|
| 76 | +- [ ] Issue is nominated for the responsible team (and T-release nomination is removed). |
| 77 | +- [ ] Proposed text is drafted by team responsible for underlying change. |
| 78 | +- [ ] Issue is nominated for release team review of clarity for wider audience. |
| 79 | +- [ ] Release team includes text in release notes/blog posts. |
| 80 | +
|
| 81 | +Release notes text: |
| 82 | +
|
| 83 | +The section title will be de-duplicated by the release team with other release notes issues. |
| 84 | +Prefer to use the standard titles from [previous releases](https://doc.rust-lang.org/nightly/releases.html). |
| 85 | +More than one section can be included if needed. |
| 86 | +
|
| 87 | +```markdown |
| 88 | +# Compatibility Notes |
| 89 | +- [{}]({}) |
| 90 | +``` |
| 91 | +
|
| 92 | +Release blog section (if any, leave blank if no section is expected): |
| 93 | +
|
| 94 | +```markdown |
| 95 | +``` |
| 96 | +", |
| 97 | + e.issue.number, e.issue.title, e.issue.html_url, |
| 98 | + ); |
| 99 | + let resp = ctx |
| 100 | + .github |
| 101 | + .new_issue( |
| 102 | + &e.issue.repository(), |
| 103 | + &title, |
| 104 | + &body, |
| 105 | + vec!["relnotes".to_owned(), "I-release-nominated".to_owned()], |
| 106 | + ) |
| 107 | + .await?; |
| 108 | + state.data.relnotes_issue = Some(resp.number); |
| 109 | + state.save().await?; |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + Ok(()) |
| 114 | +} |
0 commit comments