Skip to content

Commit

Permalink
Add author to PullRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Aug 23, 2022
1 parent 98d4ce3 commit 12aa503
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
4 changes: 3 additions & 1 deletion tools/automator/src/announcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
49 changes: 41 additions & 8 deletions tools/automator/src/pull_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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<Self> {
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 })
}
}

0 comments on commit 12aa503

Please sign in to comment.