Skip to content

Commit d0c5ded

Browse files
committed
Make build command able to enqueue many shas
1 parent 5a6a48d commit d0c5ded

File tree

2 files changed

+80
-54
lines changed

2 files changed

+80
-54
lines changed

site/src/github.rs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -162,43 +162,49 @@ pub async fn rollup_pr_number(
162162
.then(|| issue.number))
163163
}
164164

165-
pub async fn enqueue_sha(
165+
pub async fn enqueue_shas(
166166
ctxt: &SiteCtxt,
167167
main_client: &client::Client,
168168
ci_client: &client::Client,
169169
pr_number: u32,
170-
commit: String,
170+
commits: impl Iterator<Item = &str>,
171171
) -> Result<(), String> {
172-
let commit_response = ci_client
173-
.get_commit(&commit)
174-
.await
175-
.map_err(|e| e.to_string())?;
176-
if commit_response.parents.len() != 2 {
177-
log::error!(
178-
"Bors try commit {} unexpectedly has {} parents.",
179-
commit_response.sha,
180-
commit_response.parents.len()
181-
);
182-
return Ok(());
183-
}
184-
let try_commit = TryCommit {
185-
sha: commit_response.sha.clone(),
186-
parent_sha: commit_response.parents[0].sha.clone(),
187-
};
188-
let queued = {
189-
let conn = ctxt.conn().await;
190-
conn.pr_attach_commit(pr_number, &try_commit.sha, &try_commit.parent_sha)
172+
let mut msg = String::new();
173+
for commit in commits {
174+
let mut commit_response = ci_client
175+
.get_commit(&commit)
191176
.await
192-
};
193-
if queued {
194-
let msg = format!(
195-
"Queued {} with parent {}, future [comparison URL]({}).",
196-
try_commit.sha,
197-
try_commit.parent_sha,
198-
try_commit.comparison_url(),
199-
);
200-
main_client.post_comment(pr_number, msg).await;
177+
.map_err(|e| e.to_string())?;
178+
if commit_response.parents.len() != 2 {
179+
log::error!(
180+
"Bors try commit {} unexpectedly has {} parents.",
181+
commit_response.sha,
182+
commit_response.parents.len()
183+
);
184+
return Ok(());
185+
}
186+
let try_commit = TryCommit {
187+
sha: commit_response.sha,
188+
parent_sha: commit_response.parents.remove(0).sha,
189+
};
190+
let queued = {
191+
let conn = ctxt.conn().await;
192+
conn.pr_attach_commit(pr_number, &try_commit.sha, &try_commit.parent_sha)
193+
.await
194+
};
195+
if queued {
196+
if !msg.is_empty() {
197+
msg.push('\n');
198+
}
199+
msg.push_str(&format!(
200+
"Queued {} with parent {}, future [comparison URL]({}).",
201+
try_commit.sha,
202+
try_commit.parent_sha,
203+
try_commit.comparison_url(),
204+
));
205+
}
201206
}
207+
main_client.post_comment(pr_number, msg).await;
202208
Ok(())
203209
}
204210

site/src/request_handlers/github.rs

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::api::{github, ServerResult};
2-
use crate::github::{client, enqueue_sha, parse_homu_comment, rollup_pr_number, unroll_rollup};
2+
use crate::github::{client, enqueue_shas, parse_homu_comment, rollup_pr_number, unroll_rollup};
33
use crate::load::SiteCtxt;
44

55
use std::sync::Arc;
66

77
use regex::Regex;
88

99
lazy_static::lazy_static! {
10-
static ref BODY_TRY_COMMIT: Regex =
10+
static ref BODY_TIMER_BUILD: Regex =
1111
Regex::new(r#"(?:\W|^)@rust-timer\s+build\s+(\w+)(?:\W|$)(?:include=(\S+))?\s*(?:exclude=(\S+))?\s*(?:runs=(\d+))?"#).unwrap();
12-
static ref BODY_QUEUE: Regex =
12+
static ref BODY_TIMER_QUEUE: Regex =
1313
Regex::new(r#"(?:\W|^)@rust-timer\s+queue(?:\W|$)(?:include=(\S+))?\s*(?:exclude=(\S+))?\s*(?:runs=(\d+))?"#).unwrap();
1414
}
1515

@@ -81,7 +81,14 @@ async fn handle_issue(
8181
);
8282
if comment.body.contains(" homu: ") {
8383
if let Some(sha) = parse_homu_comment(&comment.body).await {
84-
enqueue_sha(&ctxt, &main_client, &ci_client, issue.number, sha).await?;
84+
enqueue_shas(
85+
&ctxt,
86+
&main_client,
87+
&ci_client,
88+
issue.number,
89+
std::iter::once(sha.as_str()),
90+
)
91+
.await?;
8592
return Ok(github::Response);
8693
}
8794
}
@@ -112,7 +119,7 @@ async fn handle_rust_timer(
112119
return Ok(github::Response);
113120
}
114121

115-
if let Some(captures) = BODY_QUEUE.captures(&comment.body) {
122+
if let Some(captures) = BODY_TIMER_QUEUE.captures(&comment.body) {
116123
let include = captures.get(1).map(|v| v.as_str());
117124
let exclude = captures.get(2).map(|v| v.as_str());
118125
let runs = captures.get(3).and_then(|v| v.as_str().parse::<i32>().ok());
@@ -130,30 +137,43 @@ async fn handle_rust_timer(
130137
.await;
131138
return Ok(github::Response);
132139
}
133-
if let Some(captures) = BODY_TRY_COMMIT.captures(&comment.body) {
134-
if let Some(commit) = captures.get(1).map(|c| c.as_str().to_owned()) {
135-
let include = captures.get(2).map(|v| v.as_str());
136-
let exclude = captures.get(3).map(|v| v.as_str());
137-
let runs = captures.get(4).and_then(|v| v.as_str().parse::<i32>().ok());
138-
let commit = commit.trim_start_matches("https://github.com/rust-lang/rust/commit/");
139-
{
140-
let conn = ctxt.conn().await;
141-
conn.queue_pr(issue.number, include, exclude, runs).await;
142-
}
143-
enqueue_sha(
144-
&ctxt,
145-
&main_client,
146-
&ci_client,
147-
issue.number,
148-
commit.to_owned(),
149-
)
150-
.await?;
151-
return Ok(github::Response);
140+
141+
for captures in build_captures(&comment).map(|(_, captures)| captures) {
142+
let include = captures.get(2).map(|v| v.as_str());
143+
let exclude = captures.get(3).map(|v| v.as_str());
144+
let runs = captures.get(4).and_then(|v| v.as_str().parse::<i32>().ok());
145+
{
146+
let conn = ctxt.conn().await;
147+
conn.queue_pr(issue.number, include, exclude, runs).await;
152148
}
153149
}
150+
151+
enqueue_shas(
152+
&ctxt,
153+
&main_client,
154+
&ci_client,
155+
issue.number,
156+
build_captures(&comment).map(|(commit, _)| commit),
157+
)
158+
.await?;
159+
154160
Ok(github::Response)
155161
}
156162

163+
/// Run the `@rust-timer build` regex over the comment message extracting the commit and the other captures
164+
fn build_captures(comment: &github::Comment) -> impl Iterator<Item = (&str, regex::Captures)> {
165+
BODY_TIMER_BUILD
166+
.captures_iter(&comment.body)
167+
.filter_map(|captures| {
168+
captures.get(1).map(|m| {
169+
let commit = m
170+
.as_str()
171+
.trim_start_matches("https://github.com/rust-lang/rust/commit/");
172+
(commit, captures)
173+
})
174+
})
175+
}
176+
157177
pub async fn get_authorized_users() -> Result<Vec<usize>, String> {
158178
let url = format!("{}/permissions/perf.json", ::rust_team_data::v1::BASE_URL);
159179
let client = reqwest::Client::new();

0 commit comments

Comments
 (0)