@@ -19,6 +19,7 @@ use clap::{ArgAction, Parser, ValueEnum};
1919use colored:: Colorize ;
2020use github:: get_pr_comments;
2121use log:: debug;
22+ use regex:: RegexBuilder ;
2223use reqwest:: blocking:: Client ;
2324
2425mod git;
@@ -1200,16 +1201,7 @@ impl Config {
12001201 . filter ( |c| c. user . login == "rust-timer" )
12011202 . find ( |c| c. body . contains ( "Perf builds for each rolled up PR" ) )
12021203 . 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 ) ?;
12131205 let short_sha = builds
12141206 . iter ( )
12151207 . map ( |sha| sha. chars ( ) . take ( 8 ) . collect ( ) )
@@ -1272,6 +1264,29 @@ fn main() {
12721264 }
12731265}
12741266
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+
12751290#[ cfg( test) ]
12761291mod tests {
12771292 use super :: * ;
0 commit comments