Skip to content

Commit 74cc697

Browse files
Merge pull request #1397 from rylev/captures-test
Write test for extracting build sha
2 parents a5976eb + 9e87199 commit 74cc697

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

site/src/request_handlers/github.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async fn handle_rust_timer(
137137
return Ok(github::Response);
138138
}
139139

140-
for captures in build_captures(&comment).map(|(_, captures)| captures) {
140+
for captures in build_captures(&comment.body).map(|(_, captures)| captures) {
141141
let include = captures.get(2).map(|v| v.as_str());
142142
let exclude = captures.get(3).map(|v| v.as_str());
143143
let runs = captures.get(4).and_then(|v| v.as_str().parse::<i32>().ok());
@@ -152,17 +152,17 @@ async fn handle_rust_timer(
152152
&main_client,
153153
&ci_client,
154154
issue.number,
155-
build_captures(&comment).map(|(commit, _)| commit),
155+
build_captures(&comment.body).map(|(commit, _)| commit),
156156
)
157157
.await?;
158158

159159
Ok(github::Response)
160160
}
161161

162162
/// Run the `@rust-timer build` regex over the comment message extracting the commit and the other captures
163-
fn build_captures(comment: &github::Comment) -> impl Iterator<Item = (&str, regex::Captures)> {
163+
fn build_captures(comment_body: &str) -> impl Iterator<Item = (&str, regex::Captures)> {
164164
BODY_TIMER_BUILD
165-
.captures_iter(&comment.body)
165+
.captures_iter(&comment_body)
166166
.filter_map(|captures| {
167167
captures.get(1).map(|m| {
168168
let commit = m
@@ -188,3 +188,27 @@ pub async fn get_authorized_users() -> Result<Vec<usize>, String> {
188188
.map_err(|err| format!("failed to fetch authorized users: {}", err))
189189
.map(|perms| perms.github_ids)
190190
}
191+
192+
#[cfg(test)]
193+
mod tests {
194+
use super::*;
195+
#[test]
196+
fn captures_all_shas() {
197+
let comment_body = r#"
198+
Going to do perf runs for a few of these:
199+
200+
@rust-timer build 5832462aa1d9373b24ace96ad2c50b7a18af9952 (https://github.com/rust-lang/rust/pull/100307)
201+
@rust-timer build 23936af287657fa4148aeab40cc2a780810fae52 (https://github.com/rust-lang/rust/pull/100392)
202+
"#;
203+
let shas = build_captures(comment_body)
204+
.map(|(c, _)| c)
205+
.collect::<Vec<_>>();
206+
assert_eq!(
207+
shas,
208+
&[
209+
"5832462aa1d9373b24ace96ad2c50b7a18af9952",
210+
"23936af287657fa4148aeab40cc2a780810fae52"
211+
]
212+
);
213+
}
214+
}

0 commit comments

Comments
 (0)