~sumner/pr-tracker

60c48d1d94ee335e8eae94a2f8e0863ebbe52b19 — Sumner Evans 4 months ago 51cf6ee main
preview: use og: tags
5 files changed, 63 insertions(+), 3 deletions(-)

M src/main.rs
A src/ogmeta.rs
M src/tree.rs
A templates/ogmeta.html
M templates/page.html
M src/main.rs => src/main.rs +5 -0
@@ 4,6 4,7 @@
mod branches;
mod github;
mod nixpkgs;
mod ogmeta;
mod systemd;
mod tree;



@@ 29,6 30,7 @@ use github::{GitHub, PullRequestStatus};
use nixpkgs::Nixpkgs;
use systemd::{is_socket_inet, is_socket_unix, listen_fds};
use tree::Tree;
use ogmeta::Ogmeta;

#[derive(StructOpt, Debug)]
struct Config {


@@ 74,6 76,7 @@ struct PageTemplate {
    pr_author: Option<String>,
    closed: bool,
    tree: Option<Tree>,
    ogmeta: Option<Ogmeta>,
    source_url: String,
}



@@ 126,6 129,7 @@ async fn track_pr(pr_number: Option<String>, status: &mut u16, page: &mut PageTe

    let nixpkgs = Nixpkgs::new(&CONFIG.path, &CONFIG.remote);
    let tree = Tree::make(pr_info.branch.to_string(), &pr_info.status, &nixpkgs).await;
    let ogmeta = Ogmeta::from_tree(&tree);

    if let github::PullRequestStatus::Merged {
        merge_commit_oid, ..


@@ 137,6 141,7 @@ async fn track_pr(pr_number: Option<String>, status: &mut u16, page: &mut PageTe
    }

    page.tree = Some(tree);
    page.ogmeta = Some(ogmeta);
}

async fn handle_request<S>(request: Request<S>) -> http_types::Result<Response> {

A src/ogmeta.rs => src/ogmeta.rs +24 -0
@@ 0,0 1,24 @@
// SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
// SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>

use askama::Template;

use crate::Tree;

#[derive(Debug, Template)]
#[template(path = "ogmeta.html")]
pub struct Ogmeta {
    branch_name: String,
    accepted: Option<bool>,
    children: Vec<Ogmeta>,
}

impl Ogmeta {
    pub fn from_tree(tree: &Tree) -> Ogmeta {
        Ogmeta {
            branch_name: tree.branch_name.clone(),
            accepted: tree.accepted.clone(),
            children: tree.children.iter().map(|c| Ogmeta::from_tree(&c)).collect(),
        }
    }
}

M src/tree.rs => src/tree.rs +3 -3
@@ 13,9 13,9 @@ use crate::nixpkgs::Nixpkgs;
#[derive(Debug, Template)]
#[template(path = "tree.html")]
pub struct Tree {
    branch_name: String,
    accepted: Option<bool>,
    children: Vec<Tree>,
    pub branch_name: String,
    pub accepted: Option<bool>,
    pub children: Vec<Tree>,
}

impl Tree {

A templates/ogmeta.html => templates/ogmeta.html +15 -0
@@ 0,0 1,15 @@
{# SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception #}
{#- SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> -#}

| {% match accepted %}
{%- when Some with (true) -%}
{%- when Some with (false) -%}
{%- when None -%}
{% endmatch %} {{ branch_name }} {% if !children.is_empty() %}
  {%- for child in children -%}
  {{ child|safe }}
  {%- endfor -%}
{% endif %}

M templates/page.html => templates/page.html +16 -0
@@ 9,13 9,29 @@
      {% match pr_title %}
      {%- when Some with (pr_title) -%}
        <title>Nixpkgs PR #{{ pr_number }} ({{ pr_title }}) progress</title>
        <meta property="og:title" content="Nixpkgs PR #{{ pr_number }} ({{ pr_title }}) progress" />
      {%- else -%}
        <title>Nixpkgs PR #{{ pr_number }} progress</title>
        <meta property="og:title" content="Nixpkgs PR #{{ pr_number }} progress" />
      {%- endmatch -%}
    {%- else -%}
    <title>Nixpkgs PR progress tracker</title>
    <meta property="og:title" content="Nixpkgs PR progress tracker" />
    {% endmatch %}

    <meta name="description" content="Track the progress of PRs to Nixpkgs.">

    <meta property="og:description" content="
    {%- if closed %}❌{%- else %}✅{%- endif %} {% match pr_number -%}
    {%- when Some with (pr_number) -%}
      PR #{{ pr_number }} {% match ogmeta -%}
      {%- when Some with (ogmeta) -%}
         {{ ogmeta|safe }}
      {%- else -%}
      {%- endmatch -%}
    {%- else -%}
    {%- endmatch -%}" />

    <meta charset="utf-8">

    <style>