aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / crates / site-builder / src / components / live.rs
| 1 | //! The live part of the status section: facts read from the public GitHub record at build |
| 2 | //! time (`facts.json`, written by `site-builder facts`). Nothing here is typed by hand. |
| 3 | |
| 4 | use maud::{html, Markup}; |
| 5 | |
| 6 | use crate::facts::{short_date, Facts}; |
| 7 | |
| 8 | use super::boxlink::{foot, Target}; |
| 9 | |
| 10 | fn short_sha(sha: &str) -> &str { |
| 11 | if sha.len() >= 12 { &sha[..12] } else { sha } |
| 12 | } |
| 13 | |
| 14 | /// The receipt on the forge: the published receipt when it is on the forge, else the |
| 15 | /// commit it judged when that repository has a Radicle copy, else None (shown as plain |
| 16 | /// text, with the data file as the box link). |
| 17 | fn receipt_link(r: &crate::facts::Receipt) -> Option<String> { |
| 18 | if r.target_url.starts_with(crate::forge::FORGE) { |
| 19 | return Some(r.target_url.clone()); |
| 20 | } |
| 21 | let repo = crate::forge::repo_url(r.repo.rsplit('/').next().unwrap_or(&r.repo))?; |
| 22 | Some(if r.sha.is_empty() { repo } else { format!("{repo}/commit/{}", r.sha) }) |
| 23 | } |
| 24 | |
| 25 | /// The box link for a row: its forge page, else the data file behind this block. |
| 26 | fn foot_or_source(url: Option<&str>) -> Markup { |
| 27 | match url.filter(|u| !u.is_empty()) { |
| 28 | Some(u) => foot(u, Target::Evidence), |
| 29 | None => foot(&super::boxlink::source_href("facts.json"), Target::Source), |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /// A real verification receipt for the latest commit on the sovereign core's main branch, |
| 34 | /// as published by the Spark judge's check run. Set like a till print, because it is one. |
| 35 | pub fn render_receipt(facts: &Facts) -> Markup { |
| 36 | let r = &facts.receipt; |
| 37 | let (class, verdict) = match r.state.as_str() { |
| 38 | "success" => ("pass", "PASS"), |
| 39 | "failure" | "error" => ("fail", "FAIL"), |
| 40 | "pending" => ("pending", "PENDING"), |
| 41 | _ => ("pending", "NO RECEIPT YET"), |
| 42 | }; |
| 43 | let repo_short = r.repo.rsplit('/').next().unwrap_or(&r.repo); |
| 44 | html! { |
| 45 | aside class="receipt" id="receipt" aria-label="Latest verification receipt" { |
| 46 | h3 { "AIEN VERIFICATION" } |
| 47 | div class="rule" {} |
| 48 | div class="row" { span { "repository" } span { (repo_short) } } |
| 49 | div class="row" { span { "branch" } span { "main" } } |
| 50 | div class="row" { span { "commit" } span { (short_sha(&r.sha)) } } |
| 51 | @if !r.committed_at.is_empty() { |
| 52 | div class="row" { span { "committed" } span { (short_date(&r.committed_at)) } } |
| 53 | } |
| 54 | div class="row" { span { "judge" } span { "the Spark itself" } } |
| 55 | div class="rule" {} |
| 56 | @if !r.commit_title.is_empty() { |
| 57 | p { (r.commit_title) } |
| 58 | div class="rule" {} |
| 59 | } |
| 60 | div class=(format!("verdict {class}")) { (verdict) } |
| 61 | @if !r.description.is_empty() { |
| 62 | p class="receipt-note" { (r.description) } |
| 63 | } |
| 64 | div class="foot" { |
| 65 | @if !r.target_url.is_empty() { |
| 66 | @if !r.updated_at.is_empty() { "Published " (short_date(&r.updated_at)) ". " } |
| 67 | @if r.target_url.starts_with(crate::forge::FORGE) { |
| 68 | a href=(r.target_url) rel="noopener" { "Open the receipt" } (crate::forge::receipt_code(&r.target_url)) " " |
| 69 | } @else { |
| 70 | "Receipt: " code { (r.target_url) } " " |
| 71 | } |
| 72 | } @else { |
| 73 | "No verification has been published for this commit. " |
| 74 | } |
| 75 | @if receipt_link(r).is_none() { |
| 76 | "Commit " code { (r.repo.rsplit('/').next().unwrap_or(&r.repo)) " " (r.sha) } " has no copy on the forge. " |
| 77 | } |
| 78 | (foot_or_source(receipt_link(r).as_deref())) |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /// The core components with their last merged change and open changes, plus the newest |
| 85 | /// decision records. Rendered inside the status section. |
| 86 | pub fn render_live(facts: &Facts) -> Markup { |
| 87 | html! { |
| 88 | div class="live" id="live" { |
| 89 | div class="live-head" { |
| 90 | div class="badge badge-blue" { "READ FROM THE PUBLIC RECORD" } |
| 91 | h3 { "The components, as of the last build" } |
| 92 | p { |
| 93 | "Six repositories make up the core. The last two columns were read from GitHub, not typed by hand. Facts gathered at " |
| 94 | span class="mono" { (facts.generated_at) } |
| 95 | "; the page is republished only with reviewed releases." |
| 96 | } |
| 97 | } |
| 98 | div class="live-grid" { |
| 99 | table class="status-table" { |
| 100 | thead { |
| 101 | tr { |
| 102 | th { "Component" } |
| 103 | th { "What it is" } |
| 104 | th { "Last merged change" } |
| 105 | th class="num" { "Open" } |
| 106 | } |
| 107 | } |
| 108 | tbody { |
| 109 | @for c in &facts.components { |
| 110 | tr class="live-row" { |
| 111 | td class="name" { |
| 112 | @if c.url.is_empty() { |
| 113 | (c.name) |
| 114 | } @else { |
| 115 | a href=(c.url) rel="noopener" { (c.name) } |
| 116 | } |
| 117 | small { (c.repo.rsplit('/').next().unwrap_or(&c.repo)) } |
| 118 | (foot_or_source(Some(&c.url))) |
| 119 | } |
| 120 | td { |
| 121 | (c.role) |
| 122 | @if c.name == "Omega" { |
| 123 | " " a class="omega-link" href="/omega/" { "What Omega is" } |
| 124 | } |
| 125 | } |
| 126 | td { |
| 127 | @if let Some(m) = &c.last_merge { |
| 128 | @if m.url.is_empty() { |
| 129 | span class="merge" { (m.title) } |
| 130 | } @else { |
| 131 | a class="merge" href=(m.url) rel="noopener" { (m.title) } |
| 132 | (crate::forge::receipt_code(&m.url)) |
| 133 | } |
| 134 | span class="when" { (short_date(&m.merged_at)) } |
| 135 | } @else { |
| 136 | span class="merge" { "No merged changes on record" } |
| 137 | } |
| 138 | } |
| 139 | td class="num" { (c.open_prs) } |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | (render_receipt(facts)) |
| 145 | } |
| 146 | @if !facts.decisions.is_empty() { |
| 147 | div class="decisions" { |
| 148 | h4 { "Newest decision records" } |
| 149 | ul { |
| 150 | @for d in &facts.decisions { |
| 151 | li { |
| 152 | @if d.url.is_empty() { |
| 153 | span class="mono" { "ADR " (d.id) } |
| 154 | " " (d.title) |
| 155 | } @else { |
| 156 | a href=(d.url) rel="noopener" { |
| 157 | span class="mono" { "ADR " (d.id) } |
| 158 | " " (d.title) |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | p class="small" { |
| 165 | a href="https://interplane.io/drakestapleton/aien-architecture-mv/tree/main/docs/adr" rel="noopener" { "All decision records" } |
| 166 | " ยท " |
| 167 | a href="/facts.json" { "facts.json" } |
| 168 | ", the data behind this block." |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | #[cfg(test)] |
| 177 | mod tests { |
| 178 | use super::*; |
| 179 | |
| 180 | #[test] |
| 181 | fn receipt_and_component_rows_link_to_the_forge() { |
| 182 | let facts: Facts = serde_json::from_str(include_str!("../../../../facts.json")).expect("facts.json parses"); |
| 183 | let page = render_live(&facts).into_string(); |
| 184 | let rows = facts.components.len(); |
| 185 | assert!(rows >= 1); |
| 186 | assert_eq!(crate::components::boxlink::check_boxes(&page), Ok(rows + 1), "every component row and the receipt link to the forge"); |
| 187 | assert!(!page.contains("github.com")); |
| 188 | let mut r = facts.receipt.clone(); |
| 189 | r.target_url = "https://spark.example/receipt".into(); |
| 190 | r.sha = "abc123".into(); |
| 191 | r.repo = "aien-dev/aienux".into(); |
| 192 | assert_eq!(receipt_link(&r).as_deref(), Some("https://interplane.io/drakestapleton/aienux/commit/abc123")); |
| 193 | r.sha.clear(); |
| 194 | assert_eq!(receipt_link(&r).as_deref(), Some("https://interplane.io/drakestapleton/aienux")); |
| 195 | // A repository with no Radicle copy has no receipt link; the data file stands in. |
| 196 | r.repo = "aien-dev/aien-sovereign-core".into(); |
| 197 | assert_eq!(receipt_link(&r), None); |
| 198 | r.target_url = "https://github.com/aien-dev/aien-sovereign-core/runs/1".into(); |
| 199 | assert_eq!(receipt_link(&r), None, "a GitHub receipt is never linked"); |
| 200 | } |
| 201 | } |