Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract job documentation URL from logs #88

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/bin/server/worker.rs
Original file line number Diff line number Diff line change
@@ -295,6 +295,10 @@ impl Worker {
Some(job_name) => format!("The job **`{}`**", job_name),
None => "A job".to_owned(),
};
let trailer = match log_variables.doc_url {
Some(url) => format!("\nFor more information how to resolve CI failures of this job, visit this [link]({url})."),
None => "".to_string(),
};

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

info!("marked build {} as recently notified", build_id);
self.recently_notified.store(build_id);
16 changes: 15 additions & 1 deletion src/log_variables.rs
Original file line number Diff line number Diff line change
@@ -4,17 +4,22 @@ const SEPARATOR: u8 = b'=';

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

pub struct LogVariables<'a> {
pub job_name: Option<&'a str>,
pub pr_number: Option<&'a str>,
pub doc_url: Option<&'a str>,
}

impl<'a> LogVariables<'a> {
pub fn extract<I: crate::index::IndexData>(lines: &'a [I]) -> Self {
let mut result = LogVariables {
job_name: None,
pr_number: None,
doc_url: None,
};

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

// Early exit if everything was found
if result.job_name.is_some() && result.pr_number.is_some() {
if result.job_name.is_some() && result.pr_number.is_some() && result.doc_url.is_some() {
break;
}
}
@@ -72,10 +80,16 @@ mod tests {
Sanitized("baz"),
Sanitized("[CI_PR_NUMBER=123]"),
Sanitized("quux"),
Sanitized("[CI_JOB_DOC_URL=https://github.com/rust-lang/rust/job1]"),
Sanitized("foobar"),
];

let extracted = LogVariables::extract(LOG);
assert_eq!(Some("test-job"), extracted.job_name);
assert_eq!(Some("123"), extracted.pr_number);
assert_eq!(
Some("https://github.com/rust-lang/rust/job1"),
extracted.doc_url
);
}
}