Skip to content

Write test for extracting build sha #1397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions site/src/request_handlers/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async fn handle_rust_timer(
return Ok(github::Response);
}

for captures in build_captures(&comment).map(|(_, captures)| captures) {
for captures in build_captures(&comment.body).map(|(_, captures)| captures) {
let include = captures.get(2).map(|v| v.as_str());
let exclude = captures.get(3).map(|v| v.as_str());
let runs = captures.get(4).and_then(|v| v.as_str().parse::<i32>().ok());
Expand All @@ -152,17 +152,17 @@ async fn handle_rust_timer(
&main_client,
&ci_client,
issue.number,
build_captures(&comment).map(|(commit, _)| commit),
build_captures(&comment.body).map(|(commit, _)| commit),
)
.await?;

Ok(github::Response)
}

/// Run the `@rust-timer build` regex over the comment message extracting the commit and the other captures
fn build_captures(comment: &github::Comment) -> impl Iterator<Item = (&str, regex::Captures)> {
fn build_captures(comment_body: &str) -> impl Iterator<Item = (&str, regex::Captures)> {
BODY_TIMER_BUILD
.captures_iter(&comment.body)
.captures_iter(&comment_body)
.filter_map(|captures| {
captures.get(1).map(|m| {
let commit = m
Expand All @@ -188,3 +188,27 @@ pub async fn get_authorized_users() -> Result<Vec<usize>, String> {
.map_err(|err| format!("failed to fetch authorized users: {}", err))
.map(|perms| perms.github_ids)
}

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn captures_all_shas() {
let comment_body = r#"
Going to do perf runs for a few of these:

@rust-timer build 5832462aa1d9373b24ace96ad2c50b7a18af9952 (https://github.com/rust-lang/rust/pull/100307)
@rust-timer build 23936af287657fa4148aeab40cc2a780810fae52 (https://github.com/rust-lang/rust/pull/100392)
"#;
let shas = build_captures(comment_body)
.map(|(c, _)| c)
.collect::<Vec<_>>();
assert_eq!(
shas,
&[
"5832462aa1d9373b24ace96ad2c50b7a18af9952",
"23936af287657fa4148aeab40cc2a780810fae52"
]
);
}
}