@@ -4,17 +4,22 @@ const SEPARATOR: u8 = b'=';
4
4
5
5
const JOB_NAME_VARIABLE : & str = "CI_JOB_NAME" ;
6
6
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" ;
7
10
8
11
pub struct LogVariables < ' a > {
9
12
pub job_name : Option < & ' a str > ,
10
13
pub pr_number : Option < & ' a str > ,
14
+ pub doc_url : Option < & ' a str > ,
11
15
}
12
16
13
17
impl < ' a > LogVariables < ' a > {
14
18
pub fn extract < I : crate :: index:: IndexData > ( lines : & ' a [ I ] ) -> Self {
15
19
let mut result = LogVariables {
16
20
job_name : None ,
17
21
pr_number : None ,
22
+ doc_url : None ,
18
23
} ;
19
24
20
25
for line in lines {
@@ -26,9 +31,12 @@ impl<'a> LogVariables<'a> {
26
31
if result. pr_number . is_none ( ) {
27
32
result. pr_number = extract_variable ( sanitized, PR_NUMBER_VARIABLE ) ;
28
33
}
34
+ if result. doc_url . is_none ( ) {
35
+ result. doc_url = extract_variable ( sanitized, JOB_DOC_URL ) ;
36
+ }
29
37
30
38
// 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 ( ) {
32
40
break ;
33
41
}
34
42
}
@@ -72,10 +80,16 @@ mod tests {
72
80
Sanitized ( "baz" ) ,
73
81
Sanitized ( "[CI_PR_NUMBER=123]" ) ,
74
82
Sanitized ( "quux" ) ,
83
+ Sanitized ( "[CI_JOB_DOC_URL=https://github.com/rust-lang/rust/job1]" ) ,
84
+ Sanitized ( "foobar" ) ,
75
85
] ;
76
86
77
87
let extracted = LogVariables :: extract ( LOG ) ;
78
88
assert_eq ! ( Some ( "test-job" ) , extracted. job_name) ;
79
89
assert_eq ! ( Some ( "123" ) , extracted. pr_number) ;
90
+ assert_eq ! (
91
+ Some ( "https://github.com/rust-lang/rust/job1" ) ,
92
+ extracted. doc_url
93
+ ) ;
80
94
}
81
95
}
0 commit comments