Skip to content

Commit 4b370d4

Browse files
committed
Extract job documentation URL from logs
1 parent df1a026 commit 4b370d4

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/bin/server/worker.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ impl Worker {
295295
Some(job_name) => format!("The job **`{}`**", job_name),
296296
None => "A job".to_owned(),
297297
};
298+
let trailer = match log_variables.doc_url {
299+
Some(url) => format!("\nTo learn out more about this job, visit this [link]({url})."),
300+
None => "".to_string(),
301+
};
298302

299303
let log_url = job.log_url().unwrap_or_else(|| "unknown".into());
300304
self.github.post_comment(repo, pr, &format!(r#"
@@ -307,7 +311,7 @@ impl Worker {
307311
```
308312
309313
</details>
310-
"#, opening = opening, html_url = job.html_url(), log_url = log_url, log = extracted))?;
314+
{trailer}"#, opening = opening, html_url = job.html_url(), log_url = log_url, log = extracted, trailer = trailer))?;
311315

312316
info!("marked build {} as recently notified", build_id);
313317
self.recently_notified.store(build_id);

src/log_variables.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ const SEPARATOR: u8 = b'=';
44

55
const JOB_NAME_VARIABLE: &str = "CI_JOB_NAME";
66
const PR_NUMBER_VARIABLE: &str = "CI_PR_NUMBER";
7+
/// URL pointing to a documentation page about the job.
8+
/// Added in https://github.com/rust-lang/rust/pull/136911.
9+
const JOB_DOC_URL: &str = "CI_JOB_DOC_URL";
710

811
pub struct LogVariables<'a> {
912
pub job_name: Option<&'a str>,
1013
pub pr_number: Option<&'a str>,
14+
pub doc_url: Option<&'a str>,
1115
}
1216

1317
impl<'a> LogVariables<'a> {
1418
pub fn extract<I: crate::index::IndexData>(lines: &'a [I]) -> Self {
1519
let mut result = LogVariables {
1620
job_name: None,
1721
pr_number: None,
22+
doc_url: None,
1823
};
1924

2025
for line in lines {
@@ -26,9 +31,12 @@ impl<'a> LogVariables<'a> {
2631
if result.pr_number.is_none() {
2732
result.pr_number = extract_variable(sanitized, PR_NUMBER_VARIABLE);
2833
}
34+
if result.doc_url.is_none() {
35+
result.doc_url = extract_variable(sanitized, JOB_DOC_URL);
36+
}
2937

3038
// Early exit if everything was found
31-
if result.job_name.is_some() && result.pr_number.is_some() {
39+
if result.job_name.is_some() && result.pr_number.is_some() && result.doc_url.is_some() {
3240
break;
3341
}
3442
}
@@ -72,10 +80,16 @@ mod tests {
7280
Sanitized("baz"),
7381
Sanitized("[CI_PR_NUMBER=123]"),
7482
Sanitized("quux"),
83+
Sanitized("[CI_JOB_DOC_URL=https://github.com/rust-lang/rust/job1]"),
84+
Sanitized("foobar"),
7585
];
7686

7787
let extracted = LogVariables::extract(LOG);
7888
assert_eq!(Some("test-job"), extracted.job_name);
7989
assert_eq!(Some("123"), extracted.pr_number);
90+
assert_eq!(
91+
Some("https://github.com/rust-lang/rust/job1"),
92+
extracted.doc_url
93+
);
8094
}
8195
}

0 commit comments

Comments
 (0)