Skip to content

Improve PR rollup table formatting #1623

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 4 commits into from
Jun 26, 2023
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
47 changes: 40 additions & 7 deletions site/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,63 @@ pub async fn unroll_rollup(
previous_master: &str,
rollup_pr_number: u32,
) -> Result<(), String> {
let commit_link = |sha: &str| format!("https://github.com/rust-lang-ci/rust/commit/{sha}");

let format_commit = |s: &str, truncate: bool| {
let display = truncate.then(|| s.split_at(10).0).unwrap_or(s);
format!("[{display}](https://github.com/rust-lang-ci/rust/commit/{s})")
format!("[{display}]({})", commit_link(s))
};
let mapping = enqueue_unrolled_try_builds(ci_client, rollup_merges, previous_master)
.await?

// Sort rolled up commits by their PR number in ascending order, so that they have the
// same ordering as in the rollup PR description.
let mut unrolled_builds: Vec<UnrolledCommit> =
enqueue_unrolled_try_builds(ci_client, rollup_merges, previous_master).await?;
// The number should really be an integer, but if not, we will just sort the "non-integer" PRs
// first.
unrolled_builds.sort_by_cached_key(|commit| commit.original_pr_number.parse::<u64>().ok());

let mapping = unrolled_builds
.into_iter()
.fold(String::new(), |mut string, c| {
use std::fmt::Write;
let commit = c
.sha
.as_deref()
.map(|s| format_commit(s, false))
.map(|s| {
// Format the SHA as a code block to make it easy to copy-paste verbatim
let link = commit_link(s);
format!("`{s}` ([link]({link}))")
})
.unwrap_or_else(|| {
let head = format_commit(&c.rolled_up_head, true);
format!("❌ conflicts merging '{head}' into previous master ❌")
});
writeln!(&mut string, "|#{pr}|{commit}|", pr = c.original_pr_number).unwrap();
let message = c
.rollup_merge
.message
.split('\n')
// Skip over "Rollup merge of ..." and an empty line
.nth(2)
.map(|m| {
if m.len() <= 60 {
m.to_string()
} else {
format!("{}…", m.split_at(59).0)
}
})
.unwrap_or_else(|| format!("#{}", c.original_pr_number));
writeln!(
&mut string,
"|#{pr}|{message}|{commit}|",
pr = c.original_pr_number
)
.unwrap();
string
});
let previous_master = format_commit(previous_master, true);
let msg =
format!("📌 Perf builds for each rolled up PR:\n\n\
|PR# | Perf Build Sha|\n|----|:-----:|\n\
|PR# | Message | Perf Build Sha|\n|----|:-----:|\n\
{mapping}\n\n*previous master*: {previous_master}\n\nIn the case of a perf regression, \
run the following command for each PR you suspect might be the cause: `@rust-timer build $SHA`\n\
{COMMENT_MARK_ROLLUP}");
Expand Down Expand Up @@ -108,7 +141,7 @@ async fn enqueue_unrolled_try_builds<'a>(
.merge_branch(
"perf-tmp",
&rolled_up_head,
&format!("Unrolled build for #{original_pr_number}"),
&format!("Unrolled build for #{original_pr_number}\n{}", rollup_merge.message),
)
.await
.map_err(|e| {
Expand Down