Skip to content

Commit 1bdc420

Browse files
committed
Use second parent of merge commit when detecting outdated 'try' build
In #540, I used the `build_sha` field to detect when the current PR head does not match the PR head used when creating the 'try' build. However, 'build_sha' corresponds to the *first* parent of the merge commit, which corresponds to the commit on the rust-lang/rust 'master' branch. We now retrieve the parents of the merge commit from GitHub, and check the first parent against the current head commit of the PR. During local testing, I had created a merge commit with the order of the parents reversed, so the check appeared to work fine for me.
1 parent 674e4c2 commit 1bdc420

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/server/routes/webhooks/commands.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,24 @@ pub fn run(
8383
format!("Automatically detected try build {}", build.merge_sha),
8484
);
8585
let pr_head = data.github.get_pr_head_sha(&repo.full_name, issue.number)?;
86-
if pr_head != build.base_sha {
86+
let mut merge_commit = data.github.get_commit(&repo.full_name, &build.merge_sha)?;
87+
if merge_commit.parents.len() == 2 {
88+
// The first parent is the rust-lang/rust commit, and the second
89+
// parent (index 1) is the PR commit
90+
let old_pr_head = merge_commit.parents.remove(1).sha;
91+
if pr_head != old_pr_head {
92+
message = message.line(
93+
"warning",
94+
format!(
95+
"Try build based on commit {}, but latest commit is {}. Did you forget to make a new try build?",
96+
old_pr_head, pr_head
97+
),
98+
);
99+
}
100+
} else {
87101
message = message.line(
88102
"warning",
89-
format!(
90-
"Try build based on commit {}, but latest commit is {}. Did you forget to make a new try build?",
91-
build.base_sha, pr_head
92-
),
103+
format!("Unexpected parents for merge commit {}", build.merge_sha),
93104
);
94105
}
95106
}

0 commit comments

Comments
 (0)