about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArnout Engelen <arnout@bzzt.net>2022-02-02 18:18:08 +0100
committerAlyssa Ross <hi@alyssa.is>2022-02-16 13:29:16 +0000
commit7f87e6d8eb219f0bcf9266ea2fb5c4062a57c0c2 (patch)
tree915672eeba0b0ac2ea4e04f85ad3f962db41a835
parentf9d47ab4f75da1818b9c727bbec2c073323d8c90 (diff)
downloadpr-tracker-7f87e6d8eb219f0bcf9266ea2fb5c4062a57c0c2.tar
pr-tracker-7f87e6d8eb219f0bcf9266ea2fb5c4062a57c0c2.tar.gz
pr-tracker-7f87e6d8eb219f0bcf9266ea2fb5c4062a57c0c2.tar.bz2
pr-tracker-7f87e6d8eb219f0bcf9266ea2fb5c4062a57c0c2.tar.lz
pr-tracker-7f87e6d8eb219f0bcf9266ea2fb5c4062a57c0c2.tar.xz
pr-tracker-7f87e6d8eb219f0bcf9266ea2fb5c4062a57c0c2.tar.zst
pr-tracker-7f87e6d8eb219f0bcf9266ea2fb5c4062a57c0c2.zip
Add links to hydra
-rw-r--r--src/branches.rs85
-rw-r--r--src/tree.rs6
-rw-r--r--templates/tree.html12
3 files changed, 98 insertions, 5 deletions
diff --git a/src/branches.rs b/src/branches.rs
index aa2c5b1..e3ee262 100644
--- a/src/branches.rs
+++ b/src/branches.rs
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
 // SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+// SPDX-FileCopyrightText: 2022 Arnout Engelen <arnout@bzzt.net>
 
 use std::borrow::Cow;
 use std::collections::BTreeMap;
@@ -57,14 +58,64 @@ pub fn next_branches(branch: &str) -> Vec<Cow<str>> {
         .collect()
 }
 
+const BRANCH_HYDRA_LINK_TABLE: [(&str, &str); 4] = [
+    (r"\Anixpkgs-unstable\z", "nixpkgs/trunk/unstable"),
+    (r"\Anixos-unstable-small\z", "nixos/unstable-small/tested"),
+    (r"\Anixos-unstable\z", "nixos/trunk-combined/tested"),
+    (r"\Anixos-(\d.*)\z", "nixos/release-$1/tested"),
+];
+
+static BRANCH_HYDRA_LINK_PATTERNS: Lazy<Vec<Regex>> = Lazy::new(|| {
+    BRANCH_HYDRA_LINKS
+        .keys()
+        .copied()
+        .map(Regex::new)
+        .map(Result::unwrap)
+        .collect()
+});
+
+static BRANCH_HYDRA_LINKS: Lazy<BTreeMap<&str, &str>> = Lazy::new(|| {
+    BRANCH_HYDRA_LINK_TABLE
+        .iter()
+        .fold(BTreeMap::new(), |mut map, (pattern, next)| {
+            // TODO throw an error when this does not return None?
+            map.insert(pattern, next);
+            map
+        })
+});
+
+static BRANCH_HYDRA_LINKS_BY_INDEX: Lazy<Vec<&str>> =
+    Lazy::new(|| BRANCH_HYDRA_LINKS.values().cloned().collect());
+
+static BRANCH_HYDRA_LINK_REGEXES: Lazy<RegexSet> =
+    Lazy::new(|| RegexSet::new(BRANCH_HYDRA_LINKS.keys()).unwrap());
+
+pub fn branch_hydra_link(branch: &str) -> Option<String> {
+    BRANCH_HYDRA_LINK_REGEXES
+        .matches(branch)
+        .iter()
+        .next()
+        .map(|index| {
+            let regex = BRANCH_HYDRA_LINK_PATTERNS.get(index).unwrap();
+            BRANCH_HYDRA_LINKS_BY_INDEX
+                .get(index)
+                .map(move |link| regex.replace(branch, *link))
+                .map(move |l| format!("https://hydra.nixos.org/job/{}#tabs-constituents", l))
+        })
+        .flatten()
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
 
     #[test]
     fn staging_18_03() {
-        let res = next_branches("staging-18.03");
-        assert_eq!(res, vec!["release-18.03"]);
+        let branch = "staging-18.03";
+        let next = next_branches(branch);
+        assert_eq!(next, vec!["release-18.03"]);
+        let link = branch_hydra_link(branch);
+        assert_eq!(link, None);
     }
 
     #[test]
@@ -102,4 +153,34 @@ mod tests {
         let res = next_branches("release-20.09");
         assert_eq!(res, vec!["nixpkgs-20.09-darwin", "nixos-20.09-small"]);
     }
+
+    #[test]
+    fn nixpkgs_unstable() {
+        let branch = "nixpkgs-unstable";
+        let next = next_branches(branch);
+        assert!(next.is_empty());
+        let link = branch_hydra_link(branch);
+        let expected = "https://hydra.nixos.org/job/nixpkgs/trunk/unstable#tabs-constituents";
+        assert_eq!(link.unwrap(), expected);
+    }
+
+    #[test]
+    fn nixos_unstable_small() {
+        let branch = "nixos-unstable-small";
+        let next = next_branches(branch);
+        assert_eq!(next, vec!["nixos-unstable"]);
+        let link = branch_hydra_link(branch);
+        let expected = "https://hydra.nixos.org/job/nixos/unstable-small/tested#tabs-constituents";
+        assert_eq!(link.unwrap(), expected);
+    }
+
+    #[test]
+    fn nixos_unstable() {
+        let branch = "nixos-unstable";
+        let next = next_branches(branch);
+        assert_eq!(next.len(), 0);
+        let link = branch_hydra_link(branch);
+        let expected = "https://hydra.nixos.org/job/nixos/trunk-combined/tested#tabs-constituents";
+        assert_eq!(link.unwrap(), expected);
+    }
 }
diff --git a/src/tree.rs b/src/tree.rs
index 39cfcf0..fb56c99 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -1,11 +1,13 @@
 // SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
 // SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+// SPDX-FileCopyrightText: 2022 Arnout Engelen <arnout@bzzt.net>
 
 use std::collections::BTreeSet;
 use std::ffi::{OsStr, OsString};
 
 use askama::Template;
 
+use crate::branches::branch_hydra_link;
 use crate::branches::next_branches;
 use crate::github;
 use crate::nixpkgs::Nixpkgs;
@@ -15,6 +17,7 @@ use crate::nixpkgs::Nixpkgs;
 pub struct Tree {
     branch_name: String,
     accepted: Option<bool>,
+    hydra_link: Option<String>,
     children: Vec<Tree>,
 }
 
@@ -27,9 +30,12 @@ impl Tree {
             .map(|b| Self::generate(b.to_string(), found_branches))
             .collect();
 
+        let link = branch_hydra_link(&branch).map(|l| l.to_string());
+
         Tree {
             accepted: None,
             branch_name: branch,
+            hydra_link: link,
             children: nexts,
         }
     }
diff --git a/templates/tree.html b/templates/tree.html
index caa9c3e..7760907 100644
--- a/templates/tree.html
+++ b/templates/tree.html
@@ -1,17 +1,23 @@
 {# SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception #}
 {#- SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> -#}
+{#- SPDX-FileCopyrightText: 2022 Arnout Engelen <arnout@bzzt.net> -#}
 
 <li>
   {% match accepted %}
   {%- when Some with (true) -%}
   <span class="state-accepted">✅</span>
   {%- when Some with (false) -%}
-  <span class="state-pending">⚪</span>
+    <span class="state-pending">⚪</span>
   {%- when None -%}
-  <span class="state-unknown">❓</span>
+    <span class="state-unknown">❓</span>
   {% endmatch %}
 
-  {{ branch_name }}
+  {% match hydra_link %}
+  {%- when Some with (link) -%}
+    <a href="{{ link }}">{{ branch_name }}</a>
+  {%- when None -%}
+    {{ branch_name }}
+  {% endmatch %}
 
   {% if !children.is_empty() %}
   <ul>