diff --git a/tools/automator/src/announcement.rs b/tools/automator/src/announcement.rs index 9162265ea..3c11266ac 100644 --- a/tools/automator/src/announcement.rs +++ b/tools/automator/src/announcement.rs @@ -95,14 +95,12 @@ async fn generate_announcement( title, url, author, + .. } = pull_request; - let author = if authors.contains(&author.name) - || author_blacklist.contains(author.name.as_str()) - { + let author = if author_blacklist.contains(author.name.as_str()) { None } else { - authors.insert(author.name.clone()); Some(author) }; @@ -118,8 +116,12 @@ async fn generate_announcement( pull_request_links.push_str(&link); if let Some(Author { name, profile }) = author { - let author_link = format!("[@{name}]: {profile}\n"); - author_links.push_str(&author_link); + if !authors.contains(&name) { + let author_link = format!("[@{name}]: {profile}\n"); + author_links.push_str(&author_link); + + authors.insert(name.clone()); + } } } diff --git a/tools/automator/src/pull_requests.rs b/tools/automator/src/pull_requests.rs index 61a885cde..fa8b08a1a 100644 --- a/tools/automator/src/pull_requests.rs +++ b/tools/automator/src/pull_requests.rs @@ -2,6 +2,7 @@ use std::collections::BTreeMap; use anyhow::anyhow; use autolib::find_version_in_str; +use chrono::{DateTime, Utc}; use octocrab::{ models::pulls::PullRequest as OctoPullRequest, params::{pulls::Sort, Direction, State}, @@ -19,7 +20,7 @@ impl PullRequestsSinceLastRelease { let mut pull_requests = BTreeMap::new(); let mut page = 1u32; - let version_of_last_release = 'outer: loop { + let (version_of_last_release, time_of_last_release) = 'outer: loop { const MAX_RESULTS_PER_PAGE: u8 = 100; println!("Fetching page {}...", page); @@ -50,8 +51,8 @@ impl PullRequestsSinceLastRelease { pull_request.title.ok_or_else(|| { anyhow!("Release PR is missing title") })?; - let version = find_version_in_str(&title)?; + let version = find_version_in_str(&title)?; let version = version.ok_or_else(|| { anyhow!( "Pull request title contains no version:\ @@ -59,15 +60,20 @@ impl PullRequestsSinceLastRelease { ) })?; - break 'outer version; + let time = + pull_request.merged_at.ok_or_else(|| { + anyhow!("Release PR is missing merge time") + })?; + + break 'outer (version, time); } } } - if pull_request.merged_at.is_none() { + let Some(merged_at) = pull_request.merged_at else { // If it wasn't merged, we're not interested. continue; - } + }; let number = pull_request.number; let title = pull_request @@ -85,6 +91,7 @@ impl PullRequestsSinceLastRelease { title, url, author, + merged_at, }; pull_requests.insert(pull_request.number, pull_request); @@ -97,6 +104,10 @@ impl PullRequestsSinceLastRelease { } }; + pull_requests.retain(|_, pull_request| { + pull_request.merged_at > time_of_last_release + }); + Ok(Self { pull_requests, version_of_last_release, @@ -109,6 +120,7 @@ pub struct PullRequest { pub title: String, pub url: Url, pub author: Author, + pub merged_at: DateTime, } pub struct Author {