Skip to content

Commit

Permalink
Merge pull request #1325 from hannobraun/release
Browse files Browse the repository at this point in the history
Fix bugs in release automation
  • Loading branch information
hannobraun authored Nov 8, 2022
2 parents 2c8cc2a + 7a04c11 commit 88a0266
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
14 changes: 8 additions & 6 deletions tools/automator/src/announcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};

Expand All @@ -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());
}
}
}

Expand Down
22 changes: 17 additions & 5 deletions tools/automator/src/pull_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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);
Expand Down Expand Up @@ -50,24 +51,29 @@ 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:\
{title}"
)
})?;

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
Expand All @@ -85,6 +91,7 @@ impl PullRequestsSinceLastRelease {
title,
url,
author,
merged_at,
};

pull_requests.insert(pull_request.number, pull_request);
Expand All @@ -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,
Expand All @@ -109,6 +120,7 @@ pub struct PullRequest {
pub title: String,
pub url: Url,
pub author: Author,
pub merged_at: DateTime<Utc>,
}

pub struct Author {
Expand Down

0 comments on commit 88a0266

Please sign in to comment.