From de02259f73033466d3243b1187fffad2ce124477 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Aug 2022 10:56:08 +0200 Subject: [PATCH 1/3] Place pull request links under pull requests This makes copy-pasting the pull requests into the changelog easier. --- tools/automator/src/announcement.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/automator/src/announcement.rs b/tools/automator/src/announcement.rs index d0805ad7c..79c15357f 100644 --- a/tools/automator/src/announcement.rs +++ b/tools/automator/src/announcement.rs @@ -139,6 +139,8 @@ Improvements that are relevant to developers working on Fornjot itself. **TASK: Sort into the categories above; update/merge as appropriate.** {pull_request_list} +{pull_request_links} +{author_links} ### Issue of the Week @@ -147,11 +149,7 @@ Improvements that are relevant to developers working on Fornjot itself. ### Outlook -**TASK: Write.** - - -{pull_request_links} -{author_links}\ +**TASK: Write.**\n\ " )?; From 95548fb63758255c735441345c0268819adc80c9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Aug 2022 11:05:20 +0200 Subject: [PATCH 2/3] Automatically thank contributors --- tools/automator/src/announcement.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/automator/src/announcement.rs b/tools/automator/src/announcement.rs index 79c15357f..ad9f84e89 100644 --- a/tools/automator/src/announcement.rs +++ b/tools/automator/src/announcement.rs @@ -78,7 +78,12 @@ async fn generate_announcement( Some(author) }; - let item = format!("- {title} ([#{number}])\n"); + let thanks = match author.as_ref() { + Some(author) => format!("; thank you, [@{}]!", author.name), + None => String::new(), + }; + + let item = format!("- {title} ([#{number}]{thanks})\n"); pull_request_list.push_str(&item); let link = format!("[#{number}]: {url}\n"); From e6f716f1e60e3c48796a11f56abd94e24819cdd1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 30 Aug 2022 11:21:47 +0200 Subject: [PATCH 3/3] Automatically determine PRs since last release --- tools/automator/src/announcement.rs | 7 +--- tools/automator/src/args.rs | 9 ----- tools/automator/src/pull_requests.rs | 57 +++++++++++++--------------- tools/automator/src/run.rs | 2 +- 4 files changed, 29 insertions(+), 46 deletions(-) diff --git a/tools/automator/src/announcement.rs b/tools/automator/src/announcement.rs index ad9f84e89..024a5388d 100644 --- a/tools/automator/src/announcement.rs +++ b/tools/automator/src/announcement.rs @@ -1,7 +1,7 @@ use std::{collections::HashSet, fmt::Write, path::PathBuf}; use anyhow::Context; -use chrono::{Date, Datelike, Utc}; +use chrono::{Datelike, Utc}; use map_macro::set; use tokio::{ fs::{self, File}, @@ -11,7 +11,6 @@ use tokio::{ use crate::pull_requests::{Author, PullRequest}; pub async fn create_release_announcement( - last_release_date: Date, version: String, ) -> anyhow::Result<()> { let now = Utc::now(); @@ -20,9 +19,7 @@ pub async fn create_release_announcement( let week = now.iso_week().week(); let pull_requests = - PullRequest::fetch_since_last_release(last_release_date) - .await? - .into_values(); + PullRequest::fetch_since_last_release().await?.into_values(); let mut file = create_file(year, week).await?; generate_announcement(week, version, pull_requests, &mut file).await?; diff --git a/tools/automator/src/args.rs b/tools/automator/src/args.rs index 571b90003..360345b24 100644 --- a/tools/automator/src/args.rs +++ b/tools/automator/src/args.rs @@ -1,5 +1,3 @@ -use chrono::{Date, NaiveDate, Utc}; - #[derive(clap::Parser)] pub enum Args { CreateReleaseAnnouncement(CreateReleaseAnnouncement), @@ -13,12 +11,5 @@ impl Args { #[derive(clap::Parser)] pub struct CreateReleaseAnnouncement { - pub last_release_date: NaiveDate, pub version: String, } - -impl CreateReleaseAnnouncement { - pub fn last_release_date(&self) -> Date { - Date::from_utc(self.last_release_date, Utc) - } -} diff --git a/tools/automator/src/pull_requests.rs b/tools/automator/src/pull_requests.rs index 5d8c3a08d..4a1cdc43f 100644 --- a/tools/automator/src/pull_requests.rs +++ b/tools/automator/src/pull_requests.rs @@ -1,7 +1,6 @@ use std::collections::BTreeMap; use anyhow::anyhow; -use chrono::{Date, Utc}; use octocrab::{ models::pulls::PullRequest as OctoPullRequest, params::{pulls::Sort, Direction, State}, @@ -17,7 +16,6 @@ pub struct PullRequest { impl PullRequest { pub async fn fetch_since_last_release( - last_release_date: Date, ) -> anyhow::Result> { let mut pull_requests = BTreeMap::new(); let mut page = 1u32; @@ -41,40 +39,37 @@ impl PullRequest { .await?; for pull_request in pull_request_page.items { - if let Some(updated_at) = pull_request.updated_at { - if updated_at.date() < last_release_date { - // This pull request has been updated before the last - // release. Since we sort pull requests by - // updated-descending, that means all following pull - // requests have been updated before the last release, - // and thus couldn't have been merged after. - break 'outer; + if let Some(labels) = pull_request.labels.as_ref() { + for label in labels { + if label.name == "release" { + // We have found the most recently updated release + // PR. Unless it has been updated since being merged + // (which we prevent, by locking release PRs as part + // of the release procedure), we can stop here. + break 'outer; + } } } - if let Some(merged_at) = pull_request.merged_at { - if merged_at.date() >= last_release_date { - let number = pull_request.number; - let title = - pull_request.title.clone().ok_or_else(|| { - anyhow!("Pull request is missing title") - })?; - let url = - pull_request.html_url.clone().ok_or_else(|| { - anyhow!("Pull request is missing URL") - })?; - let author = Author::from_pull_request(&pull_request)?; + let number = pull_request.number; + let title = pull_request + .title + .clone() + .ok_or_else(|| anyhow!("Pull request is missing title"))?; + let url = pull_request + .html_url + .clone() + .ok_or_else(|| anyhow!("Pull request is missing URL"))?; + let author = Author::from_pull_request(&pull_request)?; - let pull_request = Self { - number, - title, - url, - author, - }; + let pull_request = Self { + number, + title, + url, + author, + }; - pull_requests.insert(pull_request.number, pull_request); - } - } + pull_requests.insert(pull_request.number, pull_request); } if pull_request_page.next.is_some() { diff --git a/tools/automator/src/run.rs b/tools/automator/src/run.rs index 7cd975938..8feefea20 100644 --- a/tools/automator/src/run.rs +++ b/tools/automator/src/run.rs @@ -5,7 +5,7 @@ use crate::{announcement::create_release_announcement, args::Args}; pub async fn run() -> anyhow::Result<()> { match Args::parse() { Args::CreateReleaseAnnouncement(args) => { - create_release_announcement(args.last_release_date(), args.version) + create_release_announcement(args.version) .await .context("Failed to create release announcement")?; }