From d0b52edacec6a01b65b86b0e8bb5575470f1a775 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Thu, 20 May 2021 13:17:29 -0600 Subject: Add title to PR information display Also refactor MergeInfo -> PrInfo. Reviewed-by: Alyssa Ross Tested-by: Alyssa Ross --- src/github.rs | 19 +++++++++++-------- src/main.rs | 11 +++++++---- src/merge_commit.graphql | 16 ---------------- src/pr_info.graphql | 18 ++++++++++++++++++ templates/page.html | 15 +++++++++++++-- 5 files changed, 49 insertions(+), 30 deletions(-) delete mode 100644 src/merge_commit.graphql create mode 100644 src/pr_info.graphql diff --git a/src/github.rs b/src/github.rs index fd24d23..1128f95 100644 --- a/src/github.rs +++ b/src/github.rs @@ -1,5 +1,6 @@ // SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception // SPDX-FileCopyrightText: 2021 Alyssa Ross +// SPDX-FileCopyrightText: 2021 Sumner Evans use std::ffi::OsStr; use std::fmt::{self, Display, Formatter}; @@ -63,12 +64,12 @@ const FIRST_KNOWN_NULL_MERGE_COMMIT: &str = "2013-10-20T15:50:06Z"; #[derive(GraphQLQuery)] #[graphql( schema_path = "vendor/github_schema.graphql", - query_path = "src/merge_commit.graphql", + query_path = "src/pr_info.graphql", response_derives = "Debug" )] -struct MergeCommitQuery; +struct PrInfoQuery; -type PullRequest = merge_commit_query::MergeCommitQueryRepositoryPullRequest; +type PullRequest = pr_info_query::PrInfoQueryRepositoryPullRequest; impl PullRequest { fn merge_commit_oid(&self) -> Option<&str> { @@ -97,8 +98,9 @@ pub enum PullRequestStatus { } #[derive(Debug)] -pub struct MergeInfo { +pub struct PrInfo { pub branch: String, + pub title: String, pub status: PullRequestStatus, } @@ -118,8 +120,8 @@ impl<'a> GitHub<'a> { Ok(HeaderValue::from_bytes(value)?) } - pub async fn merge_info_for_nixpkgs_pr(&self, pr: i64) -> Result { - let query = MergeCommitQuery::build_query(merge_commit_query::Variables { + pub async fn pr_info_for_nixpkgs_pr(&self, pr: i64) -> Result { + let query = PrInfoQuery::build_query(pr_info_query::Variables { owner: "NixOS".to_string(), repo: "nixpkgs".to_string(), number: pr, @@ -148,7 +150,7 @@ impl<'a> GitHub<'a> { return Err(Error::Response(status)); } - let data: GitHubGraphQLResponse = dbg!(response) + let data: GitHubGraphQLResponse = dbg!(response) .body_json() .await .map_err(Error::Deserialization)?; @@ -168,8 +170,9 @@ impl<'a> GitHub<'a> { PullRequestStatus::Open }; - Ok(MergeInfo { + Ok(PrInfo { branch: pr.base_ref_name, + title: pr.title, status, }) } diff --git a/src/main.rs b/src/main.rs index 22023a8..0b70a15 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ // SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception // SPDX-FileCopyrightText: 2021 Alyssa Ross +// SPDX-FileCopyrightText: 2021 Sumner Evans mod branches; mod github; @@ -70,6 +71,7 @@ static GITHUB_TOKEN: Lazy = Lazy::new(|| { struct PageTemplate { error: Option, pr_number: Option, + pr_title: Option, closed: bool, tree: Option, source_url: String, @@ -97,7 +99,7 @@ async fn track_pr(pr_number: Option, status: &mut u16, page: &mut PageTe 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) => { *status = 404; page.error = Some(format!("No such nixpkgs PR #{}.", pr_number_i64)); @@ -114,18 +116,19 @@ async fn track_pr(pr_number: Option, status: &mut u16, page: &mut PageTe }; 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; return; } 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 { merge_commit_oid, .. - } = merge_info.status + } = pr_info.status { 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()); diff --git a/src/merge_commit.graphql b/src/merge_commit.graphql deleted file mode 100644 index 76d12ec..0000000 --- a/src/merge_commit.graphql +++ /dev/null @@ -1,16 +0,0 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception -# SPDX-FileCopyrightText: 2021 Alyssa Ross - -query MergeCommitQuery($owner: String!, $repo: String!, $number: Int!) { - repository(owner: $owner, name: $repo) { - pullRequest(number: $number) { - baseRefName - mergeCommit { - oid - } - merged - mergedAt - closed - } - } -} diff --git a/src/pr_info.graphql b/src/pr_info.graphql new file mode 100644 index 0000000..fb533a0 --- /dev/null +++ b/src/pr_info.graphql @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception +# SPDX-FileCopyrightText: 2021 Alyssa Ross +# SPDX-FileCopyrightText: 2021 Sumner Evans + +query PrInfoQuery($owner: String!, $repo: String!, $number: Int!) { + repository(owner: $owner, name: $repo) { + pullRequest(number: $number) { + title + baseRefName + mergeCommit { + oid + } + merged + mergedAt + closed + } + } +} diff --git a/templates/page.html b/templates/page.html index d433e41..404977b 100644 --- a/templates/page.html +++ b/templates/page.html @@ -1,12 +1,18 @@ + {% match pr_number %} {%- when Some with (pr_number) -%} + {% match pr_title %} + {%- when Some with (pr_title) -%} + Nixpkgs PR #{{ pr_number }} ("{{ pr_title }}") progress + {%- else -%} Nixpkgs PR #{{ pr_number }} progress + {%- endmatch -%} {%- else -%} Nixpkgs PR progress tracker {% endmatch %} @@ -179,8 +185,13 @@ {%- endif -%} PR #{{ pr_number }} - {%- if closed -%} - closed + {% match pr_title %} + {%- when Some with (pr_title) -%} + ("{{ pr_title }}") + {%- else -%} + {%- endmatch -%} + {% if closed -%} + (closed) {%- endif -%} -- cgit 1.4.1