Add links to hydra

This commit is contained in:
Arnout Engelen 2022-02-02 18:18:08 +01:00 committed by Alyssa Ross
parent f9d47ab4f7
commit 7f87e6d8eb
No known key found for this signature in database
GPG key ID: F9DBED4859B271C0
3 changed files with 98 additions and 5 deletions

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception // SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
// SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> // SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
// SPDX-FileCopyrightText: 2022 Arnout Engelen <arnout@bzzt.net>
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::BTreeMap; use std::collections::BTreeMap;
@ -57,14 +58,64 @@ pub fn next_branches(branch: &str) -> Vec<Cow<str>> {
.collect() .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)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
#[test] #[test]
fn staging_18_03() { fn staging_18_03() {
let res = next_branches("staging-18.03"); let branch = "staging-18.03";
assert_eq!(res, vec!["release-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] #[test]
@ -102,4 +153,34 @@ mod tests {
let res = next_branches("release-20.09"); let res = next_branches("release-20.09");
assert_eq!(res, vec!["nixpkgs-20.09-darwin", "nixos-20.09-small"]); 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);
}
} }

View file

@ -1,11 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception // SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception
// SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> // SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
// SPDX-FileCopyrightText: 2022 Arnout Engelen <arnout@bzzt.net>
use std::collections::BTreeSet; use std::collections::BTreeSet;
use std::ffi::{OsStr, OsString}; use std::ffi::{OsStr, OsString};
use askama::Template; use askama::Template;
use crate::branches::branch_hydra_link;
use crate::branches::next_branches; use crate::branches::next_branches;
use crate::github; use crate::github;
use crate::nixpkgs::Nixpkgs; use crate::nixpkgs::Nixpkgs;
@ -15,6 +17,7 @@ use crate::nixpkgs::Nixpkgs;
pub struct Tree { pub struct Tree {
branch_name: String, branch_name: String,
accepted: Option<bool>, accepted: Option<bool>,
hydra_link: Option<String>,
children: Vec<Tree>, children: Vec<Tree>,
} }
@ -27,9 +30,12 @@ impl Tree {
.map(|b| Self::generate(b.to_string(), found_branches)) .map(|b| Self::generate(b.to_string(), found_branches))
.collect(); .collect();
let link = branch_hydra_link(&branch).map(|l| l.to_string());
Tree { Tree {
accepted: None, accepted: None,
branch_name: branch, branch_name: branch,
hydra_link: link,
children: nexts, children: nexts,
} }
} }

View file

@ -1,17 +1,23 @@
{# SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception #} {# SPDX-License-Identifier: AGPL-3.0-or-later WITH GPL-3.0-linking-exception #}
{#- SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> -#} {#- SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is> -#}
{#- SPDX-FileCopyrightText: 2022 Arnout Engelen <arnout@bzzt.net> -#}
<li> <li>
{% match accepted %} {% match accepted %}
{%- when Some with (true) -%} {%- when Some with (true) -%}
<span class="state-accepted"></span> <span class="state-accepted"></span>
{%- when Some with (false) -%} {%- when Some with (false) -%}
<span class="state-pending"></span> <span class="state-pending"></span>
{%- when None -%} {%- when None -%}
<span class="state-unknown"></span> <span class="state-unknown"></span>
{% endmatch %} {% 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() %} {% if !children.is_empty() %}
<ul> <ul>