11use 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} ;
33use crate :: load:: SiteCtxt ;
44
55use std:: sync:: Arc ;
66
77use regex:: Regex ;
88
99lazy_static:: lazy_static! {
10- static ref BODY_TRY_COMMIT : Regex =
10+ static ref BODY_TIMER_BUILD : Regex =
1111 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 =
1313 Regex :: new( r#"(?:\W|^)@rust-timer\s+queue(?:\W|$)(?:include=(\S+))?\s*(?:exclude=(\S+))?\s*(?:runs=(\d+))?"# ) . unwrap( ) ;
1414}
1515
@@ -81,7 +81,14 @@ async fn handle_issue(
8181 ) ;
8282 if comment. body . contains ( " homu: " ) {
8383 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 ?;
8592 return Ok ( github:: Response ) ;
8693 }
8794 }
@@ -112,7 +119,7 @@ async fn handle_rust_timer(
112119 return Ok ( github:: Response ) ;
113120 }
114121
115- if let Some ( captures) = BODY_QUEUE . captures ( & comment. body ) {
122+ if let Some ( captures) = BODY_TIMER_QUEUE . captures ( & comment. body ) {
116123 let include = captures. get ( 1 ) . map ( |v| v. as_str ( ) ) ;
117124 let exclude = captures. get ( 2 ) . map ( |v| v. as_str ( ) ) ;
118125 let runs = captures. get ( 3 ) . and_then ( |v| v. as_str ( ) . parse :: < i32 > ( ) . ok ( ) ) ;
@@ -130,30 +137,43 @@ async fn handle_rust_timer(
130137 . await ;
131138 return Ok ( github:: Response ) ;
132139 }
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 ;
152148 }
153149 }
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+
154160 Ok ( github:: Response )
155161}
156162
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+
157177pub async fn get_authorized_users ( ) -> Result < Vec < usize > , String > {
158178 let url = format ! ( "{}/permissions/perf.json" , :: rust_team_data:: v1:: BASE_URL ) ;
159179 let client = reqwest:: Client :: new ( ) ;
0 commit comments