From 12aa503dd7a1f7279707aee58f1a0f257b71f876 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 23 Aug 2022 11:34:18 +0200 Subject: [PATCH] Add author to `PullRequest` --- tools/automator/src/announcement.rs | 4 ++- tools/automator/src/pull_requests.rs | 49 +++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/tools/automator/src/announcement.rs b/tools/automator/src/announcement.rs index 49247f380..ce1a74ce4 100644 --- a/tools/automator/src/announcement.rs +++ b/tools/automator/src/announcement.rs @@ -54,7 +54,9 @@ async fn generate_announcement( let mut pull_request_links = String::new(); for pull_request in pull_requests { - let PullRequest { number, title, url } = pull_request; + let PullRequest { + number, title, url, .. + } = pull_request; let item = format!("- {title} ([#{number}])\n"); pull_request_list.push_str(&item); diff --git a/tools/automator/src/pull_requests.rs b/tools/automator/src/pull_requests.rs index 385547a88..5d8c3a08d 100644 --- a/tools/automator/src/pull_requests.rs +++ b/tools/automator/src/pull_requests.rs @@ -2,13 +2,17 @@ use std::collections::BTreeMap; use anyhow::anyhow; use chrono::{Date, Utc}; -use octocrab::params::{pulls::Sort, Direction, State}; +use octocrab::{ + models::pulls::PullRequest as OctoPullRequest, + params::{pulls::Sort, Direction, State}, +}; use url::Url; pub struct PullRequest { pub number: u64, pub title: String, pub url: Url, + pub author: Author, } impl PullRequest { @@ -51,14 +55,22 @@ impl PullRequest { 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.ok_or_else(|| { - anyhow!("Pull request is missing title") - })?; - let url = pull_request.html_url.ok_or_else(|| { - anyhow!("Pull request is missing URL") - })?; + 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 }; + let pull_request = Self { + number, + title, + url, + author, + }; pull_requests.insert(pull_request.number, pull_request); } @@ -75,3 +87,24 @@ impl PullRequest { Ok(pull_requests) } } + +pub struct Author { + pub name: String, + pub profile: Url, +} + +impl Author { + pub fn from_pull_request( + pull_request: &OctoPullRequest, + ) -> anyhow::Result { + let user = pull_request + .user + .clone() + .ok_or_else(|| anyhow!("Pull request is missing author"))?; + + let name = user.login; + let profile = user.html_url; + + Ok(Self { name, profile }) + } +}