Skip to content

Commit 205d213

Browse files
committed
Move main logic for enqueuing to its own function
1 parent ee3ca11 commit 205d213

File tree

2 files changed

+76
-61
lines changed

2 files changed

+76
-61
lines changed

site/src/github.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod client;
22

3-
use crate::api::github::Issue;
3+
use crate::api::github::{Commit, Issue};
44
use crate::comparison::{
55
deserves_attention_icount, write_summary_table, write_summary_table_footer, ArtifactComparison,
66
ArtifactComparisonSummary, Direction, Metric,
@@ -33,6 +33,57 @@ pub async fn get_authorized_users() -> Result<Vec<usize>, String> {
3333
.map(|perms| perms.github_ids)
3434
}
3535

36+
/// Enqueues try builds on the try-perf branch for every rollup merge in `rollup_merges`.
37+
/// Returns a mapping between the rollup merge commit and the try build sha.
38+
pub async fn enqueue_unrolled_try_builds<'a>(
39+
client: client::Client,
40+
rollup_merges: impl Iterator<Item = &'a Commit>,
41+
previous_master: &str,
42+
) -> Result<Vec<(&'a Commit, String)>, String> {
43+
let mut mapping = Vec::new();
44+
for rollup_merge in rollup_merges {
45+
// Fetch the rollup merge commit which should have two parents.
46+
// The first parent is in the chain of rollup merge commits all the way back to `previous_master`.
47+
// The second parent is the head of the PR that was rolled up. We want the second parent.
48+
let commit = client.get_commit(&rollup_merge.sha).await.map_err(|e| {
49+
format!(
50+
"Error getting rollup merge commit '{}': {e:?}",
51+
rollup_merge.sha
52+
)
53+
})?;
54+
assert!(
55+
commit.parents.len() == 2,
56+
"What we thought was a merge commit was not a merge commit. sha: {}",
57+
rollup_merge.sha
58+
);
59+
let rolled_up_head = &commit.parents[1].sha;
60+
61+
// Reset perf-tmp to the previous master
62+
client
63+
.update_branch("perf-tmp", previous_master)
64+
.await
65+
.map_err(|e| format!("Error updating perf-tmp with previous master: {e:?}"))?;
66+
67+
// Merge in the rolled up PR's head commit into the previous master
68+
let sha = client
69+
.merge_branch("perf-tmp", rolled_up_head, "merge")
70+
.await
71+
.map_err(|e| format!("Error merging commit into perf-tmp: {e:?}"))?;
72+
73+
// Force the `try-perf` branch to point to what the perf-tmp branch points to
74+
client
75+
.update_branch("try-perf", &sha)
76+
.await
77+
.map_err(|e| format!("Error updating the try-perf branch: {e:?}"))?;
78+
79+
mapping.push((rollup_merge, sha));
80+
// Wait to ensure there's enough time for GitHub to checkout these changes before they are overwritten
81+
tokio::time::sleep(std::time::Duration::from_secs(15)).await
82+
}
83+
84+
Ok(mapping)
85+
}
86+
3687
// Returns the PR number
3788
pub async fn pr_and_try_for_rollup(
3889
ctxt: Arc<SiteCtxt>,

site/src/request_handlers/github.rs

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::api::{github, ServerResult};
22
use crate::github::{
3-
branch_for_rollup, client, enqueue_sha, get_authorized_users, parse_homu_comment,
4-
pr_and_try_for_rollup,
3+
branch_for_rollup, client, enqueue_sha, enqueue_unrolled_try_builds, get_authorized_users,
4+
parse_homu_comment, pr_and_try_for_rollup,
55
};
66
use crate::load::SiteCtxt;
77

@@ -43,8 +43,8 @@ async fn handle_push(ctxt: Arc<SiteCtxt>, push: github::Push) -> ServerResult<gi
4343
if push.r#ref != "refs/heads/master" {
4444
return Ok(github::Response);
4545
}
46-
let pr = rollup_pr(&ci_client, &push).await?;
47-
let pr = match pr {
46+
let rollup_pr = rollup_pr(&main_repo_client, &push).await?;
47+
let rollup_pr = match rollup_pr {
4848
Some(pr) => pr,
4949
None => return Ok(github::Response),
5050
};
@@ -57,68 +57,32 @@ async fn handle_push(ctxt: Arc<SiteCtxt>, push: github::Push) -> ServerResult<gi
5757
.skip(1) // skip the head commit
5858
.take_while(|c| c.message.starts_with("Rollup merge of "));
5959

60-
let mut prs = Vec::new();
61-
for rollup_merge in rollup_merges {
62-
let pr_num = ROLLUPED_PR_NUMBER
63-
.captures(&rollup_merge.message)
64-
.and_then(|c| c.get(0))
65-
.map(|m| m.as_str())
66-
.ok_or_else(|| {
67-
format!(
68-
"Could not get PR number from message: '{}'",
69-
rollup_merge.message
70-
)
71-
})?;
72-
// Fetch the rollup merge commit which should have two parents.
73-
// The first parent is in the chain of rollup merge commits all the way back to `previous_master`.
74-
// The second parent is the head of the PR that was rolled up. We want the second parent.
75-
let commit = ci_client.get_commit(&rollup_merge.sha).await.map_err(|e| {
76-
format!(
77-
"Error getting rollup merge commit '{}': {e:?}",
78-
rollup_merge.sha
79-
)
80-
})?;
81-
assert!(
82-
commit.parents.len() == 2,
83-
"What we thought was a merge commit was not a merge commit. sha: {}",
84-
rollup_merge.sha
85-
);
86-
let rolled_up_head = &commit.parents[1].sha;
87-
88-
// Reset perf-tmp to the previous master
89-
ci_client
90-
.update_branch("perf-tmp", previous_master)
91-
.await
92-
.map_err(|e| format!("Error updating perf-tmp with previous master: {e:?}"))?;
93-
94-
// Merge in the rolled up PR's head commit into the previous master
95-
let sha = ci_client
96-
.merge_branch("perf-tmp", rolled_up_head, "merge")
97-
.await
98-
.map_err(|e| format!("Error merging commit into perf-tmp: {e:?}"))?;
99-
100-
// Force the `try-perf` branch to point to what the perf-tmp branch points to
101-
ci_client
102-
.update_branch("try-perf", &sha)
103-
.await
104-
.map_err(|e| format!("Error updating the try-perf branch: {e:?}"))?;
60+
let mapping = enqueue_unrolled_try_builds(ci_client, rollup_merges, previous_master).await?;
10561

106-
prs.push((pr_num, sha));
107-
// Wait to ensure there's enough time for GitHub to checkout these changes before they are overwritten
108-
tokio::time::sleep(std::time::Duration::from_secs(15)).await
109-
}
110-
111-
// Post comment to the rollup PR with the mapping between individual PRs and the new try commits
112-
let mapping = prs
62+
let mapping = mapping
11363
.into_iter()
114-
.fold(String::new(), |mut string, (pr, commit)| {
64+
.map(|(rollup_merge, sha)| {
65+
ROLLUPED_PR_NUMBER
66+
.captures(&rollup_merge.message)
67+
.and_then(|c| c.get(0))
68+
.map(|m| (m.as_str(), sha))
69+
.ok_or_else(|| {
70+
format!(
71+
"Could not get PR number from message: '{}'",
72+
rollup_merge.message
73+
)
74+
})
75+
})
76+
.fold(ServerResult::Ok(String::new()), |string, n| {
11577
use std::fmt::Write;
78+
let (pr, commit) = n?;
79+
let mut string = string?;
11680
write!(&mut string, "#{pr}: {commit}\n").unwrap();
117-
string
118-
});
81+
Ok(string)
82+
})?;
11983
let msg =
12084
format!("Try perf builds for each individual rolled up PR have been enqueued:\n{mapping}");
121-
main_repo_client.post_comment(pr, msg).await;
85+
main_repo_client.post_comment(rollup_pr, msg).await;
12286
Ok(github::Response)
12387
}
12488

0 commit comments

Comments
 (0)