Merge pull request #1325 from hannobraun/release

Fix bugs in release automation
This commit is contained in:
Hanno Braun 2022-11-08 11:26:30 +01:00 committed by GitHub
commit 88a0266c6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 11 deletions

View File

@ -95,14 +95,12 @@ async fn generate_announcement(
title, title,
url, url,
author, author,
..
} = pull_request; } = pull_request;
let author = if authors.contains(&author.name) let author = if author_blacklist.contains(author.name.as_str()) {
|| author_blacklist.contains(author.name.as_str())
{
None None
} else { } else {
authors.insert(author.name.clone());
Some(author) Some(author)
}; };
@ -118,8 +116,12 @@ async fn generate_announcement(
pull_request_links.push_str(&link); pull_request_links.push_str(&link);
if let Some(Author { name, profile }) = author { if let Some(Author { name, profile }) = author {
let author_link = format!("[@{name}]: {profile}\n"); if !authors.contains(&name) {
author_links.push_str(&author_link); let author_link = format!("[@{name}]: {profile}\n");
author_links.push_str(&author_link);
authors.insert(name.clone());
}
} }
} }

View File

@ -2,6 +2,7 @@ use std::collections::BTreeMap;
use anyhow::anyhow; use anyhow::anyhow;
use autolib::find_version_in_str; use autolib::find_version_in_str;
use chrono::{DateTime, Utc};
use octocrab::{ use octocrab::{
models::pulls::PullRequest as OctoPullRequest, models::pulls::PullRequest as OctoPullRequest,
params::{pulls::Sort, Direction, State}, params::{pulls::Sort, Direction, State},
@ -19,7 +20,7 @@ impl PullRequestsSinceLastRelease {
let mut pull_requests = BTreeMap::new(); let mut pull_requests = BTreeMap::new();
let mut page = 1u32; 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; const MAX_RESULTS_PER_PAGE: u8 = 100;
println!("Fetching page {}...", page); println!("Fetching page {}...", page);
@ -50,8 +51,8 @@ impl PullRequestsSinceLastRelease {
pull_request.title.ok_or_else(|| { pull_request.title.ok_or_else(|| {
anyhow!("Release PR is missing title") 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(|| { let version = version.ok_or_else(|| {
anyhow!( anyhow!(
"Pull request title contains no version:\ "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. // If it wasn't merged, we're not interested.
continue; continue;
} };
let number = pull_request.number; let number = pull_request.number;
let title = pull_request let title = pull_request
@ -85,6 +91,7 @@ impl PullRequestsSinceLastRelease {
title, title,
url, url,
author, author,
merged_at,
}; };
pull_requests.insert(pull_request.number, pull_request); 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 { Ok(Self {
pull_requests, pull_requests,
version_of_last_release, version_of_last_release,
@ -109,6 +120,7 @@ pub struct PullRequest {
pub title: String, pub title: String,
pub url: Url, pub url: Url,
pub author: Author, pub author: Author,
pub merged_at: DateTime<Utc>,
} }
pub struct Author { pub struct Author {