Skip to content
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

Fix prematurely merging PR after update #242

Merged
merged 1 commit into from
Apr 22, 2021

Conversation

f1sherman
Copy link
Contributor

After my changes in #235, I noticed that sometimes a PR is updated and then merged as part of the same webhook request, before the required statuses are fulfilled. This is because bulldozer was still using the stale statuses from before the update was performed.

This change skips the merge if the PR was updated to avoid using the stale PR status.

After my changes in palantir#235,
I noticed that sometimes a PR is updated and then merged as part of the
same webhook request, before the required statuses are fulfilled. This
is because bulldozer was still using the stale statuses from before the
update was performed.
@f1sherman
Copy link
Contributor Author

@bluekeyes sorry for the bother, I'd love your thoughts on this when you have a chance. It's a pretty big deal for us to make sure that all checks are passing after integrating the latest version of the main branch before merging and I'm hoping to get this bug fix into our environment ASAP.

@bluekeyes
Copy link
Member

I think this change makes sense, but I'd like to understand more about the situation where it happens. Specifically, I want to understand if this is a normal thing that happens in certain conditions or if Bulldozer is racing against GitHub and catching an open merge window that we expected GitHub to prevent. I think an example of your branch protection settings, Bulldozer settings, and sequence of events that led to one of these merges would help.

For instance, do you have branch protection set to enforce that branches must be up-to-date before merging?

@f1sherman
Copy link
Contributor Author

Sounds good!

For branch protection settings, the people that can merge to main are limited to a specific group of people. PRs are not required to be up to date with main in branch protection settings but I don't think that would matter in this case.

Bulldozer configuration is set to both update and merge when the ready-for-merge label is added, and requires specific CI statuses before merging.

What I've seen happen is that, given a PR that is behind main and all CI is passing, when the ready-for-merge label is added the branch is updated and merged as part of the same webhook handler instance. This is before CI is run on the updated branch. The reason for this is that, when evaluating whether it should merge, Bulldozer uses the CI statuses from before it performed the update.

This happens in the following code:

if event.GetAction() == "labeled" || event.GetAction() == "opened" {
base, _ := pullCtx.Branches()
if err := h.UpdatePullRequest(logger.WithContext(ctx), pullCtx, client, config, pr, base); err != nil {
logger.Error().Err(errors.WithStack(err)).Msg("Error updating pull request")
}
}
if err := h.ProcessPullRequest(ctx, pullCtx, client, config, pr); err != nil {
logger.Error().Err(errors.WithStack(err)).Msg("Error processing pull request")
}

You can see how after UpdatePullRequest is called, Bulldozer is still using the (now stale) Github Context for evaluating whether it should merge when ProcessPullRequest is called.

Does that make sense?

@bluekeyes
Copy link
Member

Thanks, this all makes sense to me. The situation you described is basically the only one I could think of, so it's good to have confirmation that this is what's happening.

If PRs are required to be up-to-date in branch protection, then I expect GitHub to return an error when Bulldozer attempts to merge the just-updated PR. Bulldozer detects and ignores this error and waits for future events, which would most likely be for the status checks on the update commit.

@bluekeyes bluekeyes merged commit 63ef92d into palantir:develop Apr 22, 2021
@f1sherman
Copy link
Contributor Author

Thank you!

If PRs are required to be up-to-date in branch protection, then I expect GitHub to return an error when Bulldozer attempts to merge the just-updated PR.

That's interesting. I was actually expecting GitHub to allow the merge, since Bulldozer had (just) previously updated it.

@f1sherman f1sherman mentioned this pull request May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants