Add title to PR information display

Also refactor MergeInfo -> PrInfo.

Reviewed-by: Alyssa Ross <hi@alyssa.is>
Tested-by: Alyssa Ross <hi@alyssa.is>
This commit is contained in:
Sumner Evans 2021-05-20 13:17:29 -06:00 committed by Alyssa Ross
parent 4398773a58
commit d0b52edace
No known key found for this signature in database
GPG key ID: F9DBED4859B271C0
4 changed files with 34 additions and 15 deletions

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception // SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
// SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> // SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
// SPDX-FileCopyrightText: 2021 Sumner Evans <me@sumnerevans.com>
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
@ -63,12 +64,12 @@ const FIRST_KNOWN_NULL_MERGE_COMMIT: &str = "2013-10-20T15:50:06Z";
#[derive(GraphQLQuery)] #[derive(GraphQLQuery)]
#[graphql( #[graphql(
schema_path = "vendor/github_schema.graphql", schema_path = "vendor/github_schema.graphql",
query_path = "src/merge_commit.graphql", query_path = "src/pr_info.graphql",
response_derives = "Debug" response_derives = "Debug"
)] )]
struct MergeCommitQuery; struct PrInfoQuery;
type PullRequest = merge_commit_query::MergeCommitQueryRepositoryPullRequest; type PullRequest = pr_info_query::PrInfoQueryRepositoryPullRequest;
impl PullRequest { impl PullRequest {
fn merge_commit_oid(&self) -> Option<&str> { fn merge_commit_oid(&self) -> Option<&str> {
@ -97,8 +98,9 @@ pub enum PullRequestStatus {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct MergeInfo { pub struct PrInfo {
pub branch: String, pub branch: String,
pub title: String,
pub status: PullRequestStatus, pub status: PullRequestStatus,
} }
@ -118,8 +120,8 @@ impl<'a> GitHub<'a> {
Ok(HeaderValue::from_bytes(value)?) Ok(HeaderValue::from_bytes(value)?)
} }
pub async fn merge_info_for_nixpkgs_pr(&self, pr: i64) -> Result<MergeInfo, Error> { pub async fn pr_info_for_nixpkgs_pr(&self, pr: i64) -> Result<PrInfo, Error> {
let query = MergeCommitQuery::build_query(merge_commit_query::Variables { let query = PrInfoQuery::build_query(pr_info_query::Variables {
owner: "NixOS".to_string(), owner: "NixOS".to_string(),
repo: "nixpkgs".to_string(), repo: "nixpkgs".to_string(),
number: pr, number: pr,
@ -148,7 +150,7 @@ impl<'a> GitHub<'a> {
return Err(Error::Response(status)); return Err(Error::Response(status));
} }
let data: GitHubGraphQLResponse<merge_commit_query::ResponseData> = dbg!(response) let data: GitHubGraphQLResponse<pr_info_query::ResponseData> = dbg!(response)
.body_json() .body_json()
.await .await
.map_err(Error::Deserialization)?; .map_err(Error::Deserialization)?;
@ -168,8 +170,9 @@ impl<'a> GitHub<'a> {
PullRequestStatus::Open PullRequestStatus::Open
}; };
Ok(MergeInfo { Ok(PrInfo {
branch: pr.base_ref_name, branch: pr.base_ref_name,
title: pr.title,
status, status,
}) })
} }

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception // SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
// SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> // SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
// SPDX-FileCopyrightText: 2021 Sumner Evans <me@sumnerevans.com>
mod branches; mod branches;
mod github; mod github;
@ -70,6 +71,7 @@ static GITHUB_TOKEN: Lazy<OsString> = Lazy::new(|| {
struct PageTemplate { struct PageTemplate {
error: Option<String>, error: Option<String>,
pr_number: Option<String>, pr_number: Option<String>,
pr_title: Option<String>,
closed: bool, closed: bool,
tree: Option<Tree>, tree: Option<Tree>,
source_url: String, source_url: String,
@ -97,7 +99,7 @@ async fn track_pr(pr_number: Option<String>, status: &mut u16, page: &mut PageTe
let github = GitHub::new(&GITHUB_TOKEN, &CONFIG.user_agent); let github = GitHub::new(&GITHUB_TOKEN, &CONFIG.user_agent);
let merge_info = match github.merge_info_for_nixpkgs_pr(pr_number_i64).await { let pr_info = match github.pr_info_for_nixpkgs_pr(pr_number_i64).await {
Err(github::Error::NotFound) => { Err(github::Error::NotFound) => {
*status = 404; *status = 404;
page.error = Some(format!("No such nixpkgs PR #{}.", pr_number_i64)); page.error = Some(format!("No such nixpkgs PR #{}.", pr_number_i64));
@ -114,18 +116,19 @@ async fn track_pr(pr_number: Option<String>, status: &mut u16, page: &mut PageTe
}; };
page.pr_number = Some(pr_number); page.pr_number = Some(pr_number);
page.pr_title = Some(pr_info.title);
if matches!(merge_info.status, PullRequestStatus::Closed) { if matches!(pr_info.status, PullRequestStatus::Closed) {
page.closed = true; page.closed = true;
return; return;
} }
let nixpkgs = Nixpkgs::new(&CONFIG.path, &CONFIG.remote); let nixpkgs = Nixpkgs::new(&CONFIG.path, &CONFIG.remote);
let tree = Tree::make(merge_info.branch.to_string(), &merge_info.status, &nixpkgs).await; let tree = Tree::make(pr_info.branch.to_string(), &pr_info.status, &nixpkgs).await;
if let github::PullRequestStatus::Merged { if let github::PullRequestStatus::Merged {
merge_commit_oid, .. merge_commit_oid, ..
} = merge_info.status } = pr_info.status
{ {
if merge_commit_oid.is_none() { if merge_commit_oid.is_none() {
page.error = Some("For older PRs, GitHub doesn't tell us the merge commit, so we're unable to track this PR past being merged.".to_string()); page.error = Some("For older PRs, GitHub doesn't tell us the merge commit, so we're unable to track this PR past being merged.".to_string());

View file

@ -1,9 +1,11 @@
# SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception # SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> # SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
# SPDX-FileCopyrightText: 2021 Sumner Evans <me@sumnerevans.com>
query MergeCommitQuery($owner: String!, $repo: String!, $number: Int!) { query PrInfoQuery($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) { repository(owner: $owner, name: $repo) {
pullRequest(number: $number) { pullRequest(number: $number) {
title
baseRefName baseRefName
mergeCommit { mergeCommit {
oid oid

View file

@ -1,12 +1,18 @@
<!-- SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception --> <!-- SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception -->
<!-- SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> --> <!-- SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> -->
<!-- SPDX-FileCopyrightText: 2021 Sumner Evans <me@sumnerevans.com> -->
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
{% match pr_number %} {% match pr_number %}
{%- when Some with (pr_number) -%} {%- when Some with (pr_number) -%}
{% match pr_title %}
{%- when Some with (pr_title) -%}
<title>Nixpkgs PR #{{ pr_number }} ("{{ pr_title }}") progress</title>
{%- else -%}
<title>Nixpkgs PR #{{ pr_number }} progress</title> <title>Nixpkgs PR #{{ pr_number }} progress</title>
{%- endmatch -%}
{%- else -%} {%- else -%}
<title>Nixpkgs PR progress tracker</title> <title>Nixpkgs PR progress tracker</title>
{% endmatch %} {% endmatch %}
@ -179,8 +185,13 @@
<span class="state-accepted"></span> <span class="state-accepted"></span>
{%- endif -%} {%- endif -%}
PR <a href="https://github.com/NixOS/nixpkgs/pull/{{ pr_number }}">#{{ pr_number }}</a> PR <a href="https://github.com/NixOS/nixpkgs/pull/{{ pr_number }}">#{{ pr_number }}</a>
{%- if closed -%} {% match pr_title %}
closed {%- when Some with (pr_title) -%}
("{{ pr_title }}")
{%- else -%}
{%- endmatch -%}
{% if closed -%}
(closed)
{%- endif -%} {%- endif -%}
</li> </li>