Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand release automation #1016

Merged
merged 3 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions tools/automator/src/announcement.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -11,7 +11,6 @@ use tokio::{
use crate::pull_requests::{Author, PullRequest};

pub async fn create_release_announcement(
last_release_date: Date<Utc>,
version: String,
) -> anyhow::Result<()> {
let now = Utc::now();
Expand All @@ -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?;
Expand Down Expand Up @@ -78,7 +75,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");
Expand Down Expand Up @@ -139,6 +141,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

Expand All @@ -147,11 +151,7 @@ Improvements that are relevant to developers working on Fornjot itself.

### Outlook

**TASK: Write.**


{pull_request_links}
{author_links}\
**TASK: Write.**\n\
"
)?;

Expand Down
9 changes: 0 additions & 9 deletions tools/automator/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use chrono::{Date, NaiveDate, Utc};

#[derive(clap::Parser)]
pub enum Args {
CreateReleaseAnnouncement(CreateReleaseAnnouncement),
Expand All @@ -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<Utc> {
Date::from_utc(self.last_release_date, Utc)
}
}
57 changes: 26 additions & 31 deletions tools/automator/src/pull_requests.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -17,7 +16,6 @@ pub struct PullRequest {

impl PullRequest {
pub async fn fetch_since_last_release(
last_release_date: Date<Utc>,
) -> anyhow::Result<BTreeMap<u64, Self>> {
let mut pull_requests = BTreeMap::new();
let mut page = 1u32;
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tools/automator/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")?;
}
Expand Down