1
1
use crate :: api:: { github, ServerResult } ;
2
- use crate :: github:: { client, enqueue_sha , parse_homu_comment, rollup_pr_number, unroll_rollup} ;
2
+ use crate :: github:: { client, enqueue_shas , parse_homu_comment, rollup_pr_number, unroll_rollup} ;
3
3
use crate :: load:: SiteCtxt ;
4
4
5
5
use std:: sync:: Arc ;
6
6
7
7
use regex:: Regex ;
8
8
9
9
lazy_static:: lazy_static! {
10
- static ref BODY_TRY_COMMIT : Regex =
10
+ static ref BODY_TIMER_BUILD : Regex =
11
11
Regex :: new( r#"(?:\W|^)@rust-timer\s+build\s+(\w+)(?:\W|$)(?:include=(\S+))?\s*(?:exclude=(\S+))?\s*(?:runs=(\d+))?"# ) . unwrap( ) ;
12
- static ref BODY_QUEUE : Regex =
12
+ static ref BODY_TIMER_QUEUE : Regex =
13
13
Regex :: new( r#"(?:\W|^)@rust-timer\s+queue(?:\W|$)(?:include=(\S+))?\s*(?:exclude=(\S+))?\s*(?:runs=(\d+))?"# ) . unwrap( ) ;
14
14
}
15
15
@@ -81,7 +81,14 @@ async fn handle_issue(
81
81
) ;
82
82
if comment. body . contains ( " homu: " ) {
83
83
if let Some ( sha) = parse_homu_comment ( & comment. body ) . await {
84
- enqueue_sha ( & ctxt, & main_client, & ci_client, issue. number , sha) . await ?;
84
+ enqueue_shas (
85
+ & ctxt,
86
+ & main_client,
87
+ & ci_client,
88
+ issue. number ,
89
+ std:: iter:: once ( sha. as_str ( ) ) ,
90
+ )
91
+ . await ?;
85
92
return Ok ( github:: Response ) ;
86
93
}
87
94
}
@@ -112,7 +119,7 @@ async fn handle_rust_timer(
112
119
return Ok ( github:: Response ) ;
113
120
}
114
121
115
- if let Some ( captures) = BODY_QUEUE . captures ( & comment. body ) {
122
+ if let Some ( captures) = BODY_TIMER_QUEUE . captures ( & comment. body ) {
116
123
let include = captures. get ( 1 ) . map ( |v| v. as_str ( ) ) ;
117
124
let exclude = captures. get ( 2 ) . map ( |v| v. as_str ( ) ) ;
118
125
let runs = captures. get ( 3 ) . and_then ( |v| v. as_str ( ) . parse :: < i32 > ( ) . ok ( ) ) ;
@@ -130,30 +137,43 @@ async fn handle_rust_timer(
130
137
. await ;
131
138
return Ok ( github:: Response ) ;
132
139
}
133
- if let Some ( captures) = BODY_TRY_COMMIT . captures ( & comment. body ) {
134
- if let Some ( commit) = captures. get ( 1 ) . map ( |c| c. as_str ( ) . to_owned ( ) ) {
135
- let include = captures. get ( 2 ) . map ( |v| v. as_str ( ) ) ;
136
- let exclude = captures. get ( 3 ) . map ( |v| v. as_str ( ) ) ;
137
- let runs = captures. get ( 4 ) . and_then ( |v| v. as_str ( ) . parse :: < i32 > ( ) . ok ( ) ) ;
138
- let commit = commit. trim_start_matches ( "https://github.com/rust-lang/rust/commit/" ) ;
139
- {
140
- let conn = ctxt. conn ( ) . await ;
141
- conn. queue_pr ( issue. number , include, exclude, runs) . await ;
142
- }
143
- enqueue_sha (
144
- & ctxt,
145
- & main_client,
146
- & ci_client,
147
- issue. number ,
148
- commit. to_owned ( ) ,
149
- )
150
- . await ?;
151
- return Ok ( github:: Response ) ;
140
+
141
+ for captures in build_captures ( & comment) . map ( |( _, captures) | captures) {
142
+ let include = captures. get ( 2 ) . map ( |v| v. as_str ( ) ) ;
143
+ let exclude = captures. get ( 3 ) . map ( |v| v. as_str ( ) ) ;
144
+ let runs = captures. get ( 4 ) . and_then ( |v| v. as_str ( ) . parse :: < i32 > ( ) . ok ( ) ) ;
145
+ {
146
+ let conn = ctxt. conn ( ) . await ;
147
+ conn. queue_pr ( issue. number , include, exclude, runs) . await ;
152
148
}
153
149
}
150
+
151
+ enqueue_shas (
152
+ & ctxt,
153
+ & main_client,
154
+ & ci_client,
155
+ issue. number ,
156
+ build_captures ( & comment) . map ( |( commit, _) | commit) ,
157
+ )
158
+ . await ?;
159
+
154
160
Ok ( github:: Response )
155
161
}
156
162
163
+ /// Run the `@rust-timer build` regex over the comment message extracting the commit and the other captures
164
+ fn build_captures ( comment : & github:: Comment ) -> impl Iterator < Item = ( & str , regex:: Captures ) > {
165
+ BODY_TIMER_BUILD
166
+ . captures_iter ( & comment. body )
167
+ . filter_map ( |captures| {
168
+ captures. get ( 1 ) . map ( |m| {
169
+ let commit = m
170
+ . as_str ( )
171
+ . trim_start_matches ( "https://github.com/rust-lang/rust/commit/" ) ;
172
+ ( commit, captures)
173
+ } )
174
+ } )
175
+ }
176
+
157
177
pub async fn get_authorized_users ( ) -> Result < Vec < usize > , String > {
158
178
let url = format ! ( "{}/permissions/perf.json" , :: rust_team_data:: v1:: BASE_URL ) ;
159
179
let client = reqwest:: Client :: new ( ) ;
0 commit comments