From 7f87e6d8eb219f0bcf9266ea2fb5c4062a57c0c2 Mon Sep 17 00:00:00 2001 From: Arnout Engelen Date: Wed, 2 Feb 2022 18:18:08 +0100 Subject: Add links to hydra --- src/branches.rs | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++-- src/tree.rs | 6 ++++ templates/tree.html | 12 ++++++-- 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 +// SPDX-FileCopyrightText: 2022 Arnout Engelen use std::borrow::Cow; use std::collections::BTreeMap; @@ -57,14 +58,64 @@ pub fn next_branches(branch: &str) -> Vec> { .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> = Lazy::new(|| { + BRANCH_HYDRA_LINKS + .keys() + .copied() + .map(Regex::new) + .map(Result::unwrap) + .collect() +}); + +static BRANCH_HYDRA_LINKS: Lazy> = 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> = + Lazy::new(|| BRANCH_HYDRA_LINKS.values().cloned().collect()); + +static BRANCH_HYDRA_LINK_REGEXES: Lazy = + Lazy::new(|| RegexSet::new(BRANCH_HYDRA_LINKS.keys()).unwrap()); + +pub fn branch_hydra_link(branch: &str) -> Option { + 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 +// SPDX-FileCopyrightText: 2022 Arnout Engelen 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, + hydra_link: Option, children: Vec, } @@ -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 -#} +{#- SPDX-FileCopyrightText: 2022 Arnout Engelen -#}
  • {% match accepted %} {%- when Some with (true) -%} {%- when Some with (false) -%} - + {%- when None -%} - + {% endmatch %} - {{ branch_name }} + {% match hydra_link %} + {%- when Some with (link) -%} + {{ branch_name }} + {%- when None -%} + {{ branch_name }} + {% endmatch %} {% if !children.is_empty() %}
      -- cgit 1.4.1