Skip to content

Commit 31dcab7

Browse files
committed
github: render some job tag values as backlinks to GitHub
1 parent 05b6c5c commit 31dcab7

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

github/server/src/variety/basic.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,8 @@ pub(crate) async fn details(
14861486
/*
14871487
* Try to fetch the log output of the job itself.
14881488
*/
1489-
let bm = app.buildomat(&app.db.load_repository(cs.repo)?);
1489+
let repo = app.db.load_repository(cs.repo)?;
1490+
let bm = app.buildomat(&repo);
14901491
let job = bm.job_get().job(jid).send().await?;
14911492
let outputs = bm.job_outputs_get().job(jid).send().await?.into_inner();
14921493

@@ -1495,13 +1496,49 @@ pub(crate) async fn details(
14951496
if !job.tags.is_empty() {
14961497
out += "<h3>Tags:</h3>\n";
14971498
out += "<ul>\n";
1499+
14981500
let mut keys = job.tags.keys().collect::<Vec<_>>();
14991501
keys.sort_unstable();
1502+
15001503
for &n in keys.iter() {
1504+
let v = job.tags.get(n).unwrap();
1505+
let url = match n.as_str() {
1506+
"gong.head.sha" | "gong.plan.sha" => Some(format!(
1507+
"https://github.com/{}/{}/commit/{}",
1508+
html_escape::encode_quoted_attribute(&repo.owner),
1509+
html_escape::encode_quoted_attribute(&repo.name),
1510+
html_escape::encode_quoted_attribute(v),
1511+
)),
1512+
"gong.repo.name" => Some(format!(
1513+
"https://github.com/{}/{}",
1514+
html_escape::encode_quoted_attribute(&repo.owner),
1515+
html_escape::encode_quoted_attribute(&repo.name),
1516+
)),
1517+
"gong.repo.owner" => Some(format!(
1518+
"https://github.com/{}",
1519+
html_escape::encode_quoted_attribute(&repo.owner),
1520+
)),
1521+
"gong.run.github_id" => Some(format!(
1522+
"https://github.com/{}/{}/runs/{}",
1523+
html_escape::encode_quoted_attribute(&repo.owner),
1524+
html_escape::encode_quoted_attribute(&repo.name),
1525+
html_escape::encode_quoted_attribute(v),
1526+
)),
1527+
_ => None,
1528+
};
1529+
1530+
let value = if let Some(url) = url {
1531+
format!(
1532+
"<a href=\"{url}\">{}</a>",
1533+
html_escape::encode_safe(v),
1534+
)
1535+
} else {
1536+
html_escape::encode_safe(v).to_string()
1537+
};
1538+
15011539
out += &format!(
1502-
"<li><b>{}:</b> {}\n",
1540+
"<li><b>{}:</b> {value}\n",
15031541
html_escape::encode_safe(n),
1504-
html_escape::encode_safe(job.tags.get(n).unwrap()),
15051542
);
15061543
}
15071544
out += "</ul>\n";

0 commit comments

Comments
 (0)