~sumner/pr-tracker

c01d3aa539b5dc8650571c4f55b334ad668fce18 — Sumner Evans 6 months ago cd702f9
pr-info: add title to PR information display and title

Also refactor MergeInfo -> PrInfo.
4 files changed, 59 insertions(+), 23 deletions(-)

M src/github.rs
M src/main.rs
R src/{merge_commit.graphql => pr_info.graphql}
M templates/page.html
M src/github.rs => src/github.rs +10 -8
@@ 63,12 63,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 97,9 @@ pub enum PullRequestStatus {
}

#[derive(Debug)]
pub struct MergeInfo {
pub struct PrInfo {
    pub branch: String,
    pub title: String,
    pub status: PullRequestStatus,
}



@@ 118,8 119,8 @@ impl<'a> GitHub<'a> {
        Ok(HeaderValue::from_bytes(value)?)
    }

    pub async fn merge_info_for_nixpkgs_pr(&self, pr: i64) -> Result<MergeInfo, Error> {
        let query = MergeCommitQuery::build_query(merge_commit_query::Variables {
    pub async fn pr_info_for_nixpkgs_pr(&self, pr: i64) -> Result<PrInfo, Error> {
        let query = PrInfoQuery::build_query(pr_info_query::Variables {
            owner: "NixOS".to_string(),
            repo: "nixpkgs".to_string(),
            number: pr,


@@ 148,7 149,7 @@ impl<'a> GitHub<'a> {
            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()
            .await
            .map_err(Error::Deserialization)?;


@@ 168,8 169,9 @@ impl<'a> GitHub<'a> {
            PullRequestStatus::Open
        };

        Ok(MergeInfo {
        Ok(PrInfo {
            branch: pr.base_ref_name,
            title: pr.title,
            status,
        })
    }

M src/main.rs => src/main.rs +6 -4
@@ 70,6 70,7 @@ static GITHUB_TOKEN: Lazy<OsString> = Lazy::new(|| {
struct PageTemplate {
    error: Option<String>,
    pr_number: Option<String>,
    pr_title: Option<String>,
    closed: bool,
    tree: Option<Tree>,
    source_url: String,


@@ 97,7 98,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 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 115,19 @@ async fn track_pr(pr_number: Option<String>, 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());

R src/merge_commit.graphql => src/pr_info.graphql +2 -1
@@ 1,9 1,10 @@
# SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>

query MergeCommitQuery($owner: String!, $repo: String!, $number: Int!) {
query PrInfoQuery($owner: String!, $repo: String!, $number: Int!) {
  repository(owner: $owner, name: $repo) {
    pullRequest(number: $number) {
      title
      baseRefName
      mergeCommit {
        oid

M templates/page.html => templates/page.html +41 -10
@@ 6,7 6,12 @@
  <head>
    {% match pr_number %}
    {%- when Some with (pr_number) -%}
    <title>Nixpkgs PR #{{ pr_number }} progress</title>
      {% 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>
      {%- endmatch -%}
    {%- else -%}
    <title>Nixpkgs PR progress tracker</title>
    {% endmatch %}


@@ 68,6 73,15 @@
        line-height: 2;
      }

      li > div {
        display: flex;
        flex-direction: row;
      }

      li > div p {
        margin: 0;
      }

      span {
        color: transparent;
        position: relative;


@@ 173,15 187,32 @@
    <main>
      <ol>
        <li>
          {%- if closed -%}
          <span class="state-rejected">❌</span>
          {%- else -%}
          <span class="state-accepted">✅</span>
          {%- endif -%}
          PR <a href="https://github.com/NixOS/nixpkgs/pull/{{ pr_number }}">#{{ pr_number }}</a>
          {%- if closed -%}
          closed
          {%- endif -%}
          <div>
            {%- if closed -%}
            <span class="state-rejected">❌</span>
            {%- else -%}
            <span class="state-accepted">✅</span>
            {%- endif -%}
            <div>
              <p>
                PR <a href="https://github.com/NixOS/nixpkgs/pull/{{ pr_number }}">#{{ pr_number }}</a>
                {% if closed -%}
                (closed)
                {%- endif -%}
              </p>

              <table>
                {% match pr_title %}
                {%- when Some with (pr_title) -%}
                <tr>
                  <td><b>Title:</b></td>
                  <td>{{ pr_title }}</td>
                </tr>
                {%- else -%}
                {%- endmatch -%}
              </table>
            </div>
          </div>
        </li>

        {% match tree %}