Skip to content

Include commit SHA in build failed comment #400

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 1 commit into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions src/bors/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::time::Duration;

use crate::bors::FailedWorkflowRun;
use crate::bors::command::CommandPrefix;
use crate::database::BuildModel;
use crate::github::GithubRepoName;
use crate::utils::text::pluralize;
use crate::{
Expand Down Expand Up @@ -49,7 +48,7 @@ impl Comment {
pub fn try_build_succeeded_comment(
workflows: &[WorkflowModel],
commit_sha: CommitSha,
build: &BuildModel,
parent_sha: CommitSha,
) -> Comment {
use std::fmt::Write;

Expand All @@ -65,8 +64,7 @@ pub fn try_build_succeeded_comment(
}
writeln!(
text,
"Build commit: {commit_sha} (`{commit_sha}`, parent: `{}`)",
build.parent
"Build commit: {commit_sha} (`{commit_sha}`, parent: `{parent_sha}`)",
)
.unwrap();

Expand Down Expand Up @@ -103,16 +101,17 @@ pub fn try_build_cancelled_comment(workflow_urls: impl Iterator<Item = String>)

pub fn build_failed_comment(
repo: &GithubRepoName,
commit_sha: CommitSha,
failed_workflows: Vec<FailedWorkflowRun>,
) -> Comment {
use std::fmt::Write;

let mut msg = ":broken_heart: Test failed".to_string();
let mut msg = format!(":broken_heart: Test for {commit_sha} failed");
let mut workflow_links = failed_workflows
.iter()
.map(|w| format!("[{}]({})", w.workflow_run.name, w.workflow_run.url));
if !failed_workflows.is_empty() {
write!(msg, " ({})", workflow_links.join(", ")).unwrap();
write!(msg, ": {}", workflow_links.join(", ")).unwrap();

let mut failed_jobs: Vec<Job> = failed_workflows
.into_iter()
Expand Down
4 changes: 2 additions & 2 deletions src/bors/handlers/trybuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ mod tests {
tester.workflow_full_failure(tester.try_branch()).await?;
insta::assert_snapshot!(
tester.get_comment().await?,
@":broken_heart: Test failed ([Workflow1](https://github.com/rust-lang/borstest/actions/runs/1))"
@":broken_heart: Test for merge-0-pr-1 failed: [Workflow1](https://github.com/rust-lang/borstest/actions/runs/1)"
);
Ok(())
})
Expand Down Expand Up @@ -438,7 +438,7 @@ mod tests {
insta::assert_snapshot!(
tester.get_comment().await?,
@r"
:broken_heart: Test failed ([Workflow1](https://github.com/rust-lang/borstest/actions/runs/1)). Failed jobs:
:broken_heart: Test for merge-0-pr-1 failed: [Workflow1](https://github.com/rust-lang/borstest/actions/runs/1). Failed jobs:

- `Job 42` ([web logs](https://github.com/job-logs/42), [extended logs](https://triage.rust-lang.org/gha-logs/rust-lang/borstest/42))
- `Job 50` ([web logs](https://github.com/job-logs/50), [extended logs](https://triage.rust-lang.org/gha-logs/rust-lang/borstest/50))
Expand Down
14 changes: 9 additions & 5 deletions src/bors/handlers/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::bors::merge_queue::AUTO_BRANCH_NAME;
use crate::bors::merge_queue::MergeQueueSender;
use crate::bors::{FailedWorkflowRun, RepositoryState, WorkflowRun};
use crate::database::{BuildModel, BuildStatus, PullRequestModel, WorkflowModel, WorkflowStatus};
use crate::github::LabelTrigger;
use crate::github::api::client::GithubRepositoryClient;
use crate::github::{CommitSha, LabelTrigger};
use octocrab::models::CheckRunId;
use octocrab::models::workflows::{Conclusion, Job, Status};
use octocrab::params::checks::CheckRunConclusion;
Expand Down Expand Up @@ -246,7 +246,7 @@ async fn maybe_complete_build(
Some(try_build_succeeded_comment(
&db_workflow_runs,
payload.commit_sha,
&build,
CommitSha(build.parent.clone()),
))
} else {
// Merge queue will post the build succeeded comment
Expand Down Expand Up @@ -274,7 +274,11 @@ async fn maybe_complete_build(
})
}

Some(build_failed_comment(repo.repository(), workflow_runs))
Some(build_failed_comment(
repo.repository(),
payload.commit_sha,
workflow_runs,
))
};

if let Some(comment) = comment_opt {
Expand Down Expand Up @@ -610,7 +614,7 @@ mod tests {
tester.workflow_event(WorkflowEvent::failure(w2)).await?;
insta::assert_snapshot!(
tester.get_comment().await?,
@":broken_heart: Test failed ([Workflow1](https://github.com/rust-lang/borstest/actions/runs/1), [Workflow1](https://github.com/rust-lang/borstest/actions/runs/2))"
@":broken_heart: Test for merge-0-pr-1 failed: [Workflow1](https://github.com/rust-lang/borstest/actions/runs/1), [Workflow1](https://github.com/rust-lang/borstest/actions/runs/2)"
);
Ok(())
})
Expand Down Expand Up @@ -750,7 +754,7 @@ auto_build_failed = ["+foo", "+bar", "-baz"]
}).await?;
insta::assert_snapshot!(
tester.get_comment().await?,
@":broken_heart: Test failed ([Workflow1](https://github.com/rust-lang/borstest/actions/runs/1))"
@":broken_heart: Test for merge-0-pr-1 failed: [Workflow1](https://github.com/rust-lang/borstest/actions/runs/1)"
);

Ok(())
Expand Down