Skip to content

Commit e80fbca

Browse files
committed
update unrolled perf builds detection
there are currently 2 formats we need to support, explicitly looking for shas should be make parsing more resilient and backwards compatible.
1 parent e729914 commit e80fbca

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/main.rs

+25-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use clap::{ArgAction, Parser, ValueEnum};
1919
use colored::Colorize;
2020
use github::get_pr_comments;
2121
use log::debug;
22+
use regex::RegexBuilder;
2223
use reqwest::blocking::Client;
2324

2425
mod 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)]
12761291
mod tests {
12771292
use super::*;

0 commit comments

Comments
 (0)