Skip to content

Commit 2036d7c

Browse files
Parse new unrolled PR commit format
1 parent 94df17b commit 2036d7c

1 file changed

Lines changed: 61 additions & 25 deletions

File tree

site/src/request_handlers/github.rs

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,15 @@ async fn handle_rust_timer(
237237
};
238238

239239
// Find PR number from commit message
240-
let pr_number = match find_pr_number_for_unrolled_build(&commit.commit.message) {
241-
Ok(r) => r,
242-
Err(err) => {
243-
writeln!(&mut result, "### {sha}").unwrap();
244-
writeln!(&mut result, "{err}").unwrap();
245-
continue;
246-
}
247-
};
240+
let unrolled_build_message =
241+
match parse_unrolled_build_message(&commit.commit.message) {
242+
Ok(r) => r,
243+
Err(err) => {
244+
writeln!(&mut result, "### {sha}").unwrap();
245+
writeln!(&mut result, "{err}").unwrap();
246+
continue;
247+
}
248+
};
248249

249250
// Write header
250251
let pr_title = &commit
@@ -253,13 +254,18 @@ async fn handle_rust_timer(
253254
.lines()
254255
.nth(3)
255256
.unwrap_or("<FAILED TO GET PR TITLE>");
256-
writeln!(&mut result, "### #{pr_number} {sha} {pr_title}",).unwrap();
257+
writeln!(
258+
&mut result,
259+
"### #{} {sha} {pr_title}",
260+
unrolled_build_message.member_pr_number
261+
)
262+
.unwrap();
257263

258264
// Enqueue the sha build and write result
259265
let (Ok(msg) | Err(msg)) = enqueue_sha_build(
260266
&ctxt,
261267
main_client,
262-
pr_number,
268+
unrolled_build_message.member_pr_number,
263269
&BuildCommand {
264270
sha,
265271
params: Default::default(),
@@ -278,22 +284,48 @@ async fn handle_rust_timer(
278284
Ok(github::Response)
279285
}
280286

281-
fn find_pr_number_for_unrolled_build(commit_message: &str) -> Result<u32, String> {
282-
// Find PR number for this unrolled build sha
283-
const COMMIT_NAME_START: &str = "Unrolled build for #";
287+
#[derive(Debug)]
288+
struct UnrolledBuildMessage {
289+
member_pr_number: u32,
290+
#[expect(unused, reason = "Will be used in follow-up PR")]
291+
rollup_pr_number: u32,
292+
}
293+
294+
fn parse_unrolled_build_message(commit_message: &str) -> Result<UnrolledBuildMessage, String> {
284295
let first_line = commit_message.lines().next().unwrap_or("");
285-
let Some(pr_number) = first_line.strip_prefix(COMMIT_NAME_START) else {
296+
297+
// The first line of the commit message will look like
298+
// `Unrolled build for #123 in rollup #123`
299+
let words = first_line.split(" ").collect::<Vec<_>>();
300+
let ["Unrolled", "build", "for", member_pr_number, "in", "rollup", rollup_pr_number] =
301+
words[..]
302+
else {
286303
return Err(format!(
287-
"Unexpected commit name `{first_line}`, did not find expected prefix. Is the commit an unrolled build?"
304+
"Unexpected commit name `{first_line}`, could not parse commit title. Is the commit an unrolled build?"
288305
));
289306
};
290-
let Ok(pr_number) = pr_number.parse::<u32>() else {
307+
308+
let Some(member_pr_number) = member_pr_number
309+
.strip_prefix("#")
310+
.and_then(|num| num.parse::<u32>().ok())
311+
else {
291312
return Err(format!(
292-
"Unexpected commit name, pr number `{pr_number}` was not parsable as u32. Is the commit an unrolled build?"
313+
"Unexpected commit name `{first_line}`, could not parse member pr number. Is the commit an unrolled build?"
314+
));
315+
};
316+
let Some(rollup_pr_number) = rollup_pr_number
317+
.strip_prefix("#")
318+
.and_then(|num| num.parse::<u32>().ok())
319+
else {
320+
return Err(format!(
321+
"Unexpected commit name `{first_line}`, could not parse rollup pr number. Is the commit an unrolled build?"
293322
));
294323
};
295324

296-
Ok(pr_number)
325+
Ok(UnrolledBuildMessage {
326+
member_pr_number,
327+
rollup_pr_number,
328+
})
297329
}
298330

299331
async fn enqueue_sha_build(
@@ -713,19 +745,23 @@ Otherwise LGTM."#),
713745

714746
#[test]
715747
fn pr_number_from_unrolled_build() {
716-
const EXAMPLE: &str = "Unrolled build for #157428
748+
const EXAMPLE: &str = "Unrolled build for #157428 in rollup #1234
717749
Rollup merge of #157428 - nia-e:allocator-refactor, r=clarfonthey
718750
719751
allocator: refactor for stabilisation
720752
721753
Adds my current proposal per the doc in #156882 and follow-up Zulip conversations (notably for [dyn-compat](https://rust-lang.zulipchat.com/#narrow/channel/197181-t-libs.2Fwg-allocators/topic/Allocator.20dyn-safety/near/599555822)) unstably.
722754
723755
r? libs";
724-
insta::assert_compact_debug_snapshot!(find_pr_number_for_unrolled_build(EXAMPLE),
725-
@"Ok(157428)");
726-
insta::assert_compact_debug_snapshot!(find_pr_number_for_unrolled_build("Not a correct title"),
727-
@r#"Err("Unexpected commit name `Not a correct title`, did not find expected prefix. Is the commit an unrolled build?")"#);
728-
insta::assert_compact_debug_snapshot!(find_pr_number_for_unrolled_build("Unrolled build for #123almost"),
729-
@r#"Err("Unexpected commit name, pr number `123almost` was not parsable as u32. Is the commit an unrolled build?")"#);
756+
insta::assert_compact_debug_snapshot!(parse_unrolled_build_message(EXAMPLE),
757+
@"Ok(UnrolledBuildMessage { member_pr_number: 157428, rollup_pr_number: 1234 })");
758+
insta::assert_compact_debug_snapshot!(parse_unrolled_build_message("Not a correct title"),
759+
@r#"Err("Unexpected commit name `Not a correct title`, could not parse commit title. Is the commit an unrolled build?")"#);
760+
insta::assert_compact_debug_snapshot!(parse_unrolled_build_message("Unrolled build for #123almost in rollup #1234"),
761+
@r#"Err("Unexpected commit name `Unrolled build for #123almost in rollup #1234`, could not parse member pr number. Is the commit an unrolled build?")"#);
762+
insta::assert_compact_debug_snapshot!(parse_unrolled_build_message("Unrolled build for #123 in rollup #1234almost"),
763+
@r#"Err("Unexpected commit name `Unrolled build for #123 in rollup #1234almost`, could not parse rollup pr number. Is the commit an unrolled build?")"#);
764+
insta::assert_compact_debug_snapshot!(parse_unrolled_build_message("Unrolled build for #123"),
765+
@r#"Err("Unexpected commit name `Unrolled build for #123`, could not parse commit title. Is the commit an unrolled build?")"#);
730766
}
731767
}

0 commit comments

Comments
 (0)