Skip to content

Commit 50cdf2f

Browse files
authored
Merge pull request #2399 from Kobzol/comment-error-enqueue
Post an error if a given SHA was already benchmarked
2 parents 0ee9f0c + 55dcfdf commit 50cdf2f

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

site/src/github.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,14 @@ pub async fn rollup_pr_number(
233233
.then_some(issue.number))
234234
}
235235

236-
pub async fn enqueue_shas(
236+
/// Enqueues the given SHAs and returns the SHAs that were actually enqueued.
237+
pub async fn enqueue_shas<'a>(
237238
ctxt: &SiteCtxt,
238239
gh_client: &client::Client,
239240
pr_number: u32,
240-
commits: impl Iterator<Item = &str>,
241-
) -> Result<(), String> {
241+
commits: impl Iterator<Item = &'a str>,
242+
) -> Result<Vec<&'a str>, String> {
243+
let mut enqueued = vec![];
242244
let mut msg = String::new();
243245
for commit in commits {
244246
let mut commit_response = gh_client
@@ -251,7 +253,7 @@ pub async fn enqueue_shas(
251253
commit_response.sha,
252254
commit_response.parents.len()
253255
);
254-
return Ok(());
256+
continue;
255257
}
256258
let try_commit = TryCommit {
257259
sha: commit_response.sha,
@@ -268,6 +270,7 @@ pub async fn enqueue_shas(
268270
.await
269271
.map_err(|error| format!("Cannot attach SHAs to try benchmark request on PR {pr_number} and SHA {}: {error:?}", try_commit.sha))?;
270272
if queued {
273+
enqueued.push(commit);
271274
if !msg.is_empty() {
272275
msg.push('\n');
273276
}
@@ -286,7 +289,7 @@ pub async fn enqueue_shas(
286289
let queue_msg = format!(
287290
r#"There {verb} currently {preceding_artifacts} preceding artifact{suffix} in the [queue](https://perf.rust-lang.org/status.html).
288291
It will probably take at least ~{:.1} hours until the benchmark run finishes."#,
289-
(expected_duration.as_secs_f64() / 3600.0)
292+
expected_duration.as_secs_f64() / 3600.0
290293
);
291294

292295
msg.push_str(&format!(
@@ -303,7 +306,7 @@ It will probably take at least ~{:.1} hours until the benchmark run finishes."#,
303306
gh_client.post_comment(pr_number, msg).await;
304307
}
305308

306-
Ok(())
309+
Ok(enqueued)
307310
}
308311

309312
/// Counts how many artifacts are in the queue before the specified commit, and what is the expected

site/src/request_handlers/github.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,26 @@ async fn handle_rust_timer(
284284
}
285285
}
286286

287-
enqueue_shas(
287+
let enqueued = enqueue_shas(
288288
&ctxt,
289289
main_client,
290290
issue.number,
291291
valid_build_cmds.iter().map(|c| c.sha),
292292
)
293293
.await?;
294+
if enqueued.len() < valid_build_cmds.len() {
295+
use std::fmt::Write;
296+
297+
let mut msg =
298+
"The following SHAs were not enqueued, as they were probably already benchmarked:\n"
299+
.to_string();
300+
for cmd in valid_build_cmds {
301+
if !enqueued.contains(&cmd.sha) {
302+
writeln!(msg, "- {}", cmd.sha).unwrap();
303+
}
304+
}
305+
main_client.post_comment(issue.number, msg).await;
306+
}
294307

295308
Ok(github::Response)
296309
}

0 commit comments

Comments
 (0)