@@ -19,6 +19,7 @@ use clap::{ArgAction, Parser, ValueEnum};
19
19
use colored:: Colorize ;
20
20
use github:: get_pr_comments;
21
21
use log:: debug;
22
+ use regex:: RegexBuilder ;
22
23
use reqwest:: blocking:: Client ;
23
24
24
25
mod git;
@@ -1200,16 +1201,7 @@ impl Config {
1200
1201
. filter ( |c| c. user . login == "rust-timer" )
1201
1202
. find ( |c| c. body . contains ( "Perf builds for each rolled up PR" ) )
1202
1203
. context ( "couldn't find perf build comment" ) ?;
1203
- let builds = perf_comment
1204
- . body
1205
- . lines ( )
1206
- // lines of table with PR builds
1207
- . filter ( |l| l. starts_with ( "|#" ) )
1208
- // get the commit link
1209
- . filter_map ( |l| l. split ( '|' ) . nth ( 2 ) )
1210
- // get the commit sha
1211
- . map ( |l| l. split_once ( '[' ) . unwrap ( ) . 1 . rsplit_once ( ']' ) . unwrap ( ) . 0 )
1212
- . collect :: < Vec < _ > > ( ) ;
1204
+ let builds = extract_perf_shas ( & perf_comment. body ) ?;
1213
1205
let short_sha = builds
1214
1206
. iter ( )
1215
1207
. map ( |sha| sha. chars ( ) . take ( 8 ) . collect ( ) )
@@ -1272,6 +1264,29 @@ fn main() {
1272
1264
}
1273
1265
}
1274
1266
1267
+ /// Extracts the commits posted by the rust-timer bot on rollups, for unrolled perf builds.
1268
+ ///
1269
+ /// We're looking for a commit sha, in a comment whose format has changed (and could change in the
1270
+ /// future), for example:
1271
+ /// - v1: https://github.com/rust-lang/rust/pull/113014#issuecomment-1605868471
1272
+ /// - v2, the current: https://github.com/rust-lang/rust/pull/113105#issuecomment-1610393473
1273
+ ///
1274
+ /// The sha comes in later columns, so we'll look for a 40-char hex string and give priority to the
1275
+ /// last we find (to avoid possible conflicts with commits in the PR title column).
1276
+ fn extract_perf_shas ( body : & str ) -> anyhow:: Result < Vec < & str > > {
1277
+ let sha_regex = RegexBuilder :: new ( r"([0-9a-f]{40})" )
1278
+ . case_insensitive ( true )
1279
+ . build ( ) ?;
1280
+ let builds = body
1281
+ . lines ( )
1282
+ // lines of table with PR builds
1283
+ . filter ( |l| l. starts_with ( "|#" ) )
1284
+ // get the last sha we find, to prioritize the 3rd or 2nd columns.
1285
+ . filter_map ( |l| sha_regex. find_iter ( l) . last ( ) . and_then ( |m| Some ( m. as_str ( ) ) ) )
1286
+ . collect ( ) ;
1287
+ Ok ( builds)
1288
+ }
1289
+
1275
1290
#[ cfg( test) ]
1276
1291
mod tests {
1277
1292
use super :: * ;
0 commit comments