-
Notifications
You must be signed in to change notification settings - Fork 100
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
Support required statuses for Bulldozer to update PRs #307
Support required statuses for Bulldozer to update PRs #307
Conversation
So it looks like status changes not being fulfilled is working correctly as implemented 🎉 However, status changes themselves are not triggering an update, from the local testing I've done. Looks like I need to update the check run I'm not sure what implications this might have. Open to any thoughts or feedback. |
Yes, this sounds correct. Because statuses are pretty frequent events, it's important to filter them if we're not already doing so. At minimum, we should exit the handler immediately for non-successful statuses. Offhand, I'm not sure if there are any other optimizations to make here. |
It looks like both already handle this logic bulldozer/server/handler/status.go Lines 52 to 55 in c5b5340
bulldozer/server/handler/check_run.go Lines 47 to 50 in c5b5340
It looks like both of these handlers act on every open PR when processing bulldozer/server/handler/status.go Lines 72 to 82 in c5b5340
bulldozer/server/handler/check_run.go Lines 63 to 86 in c5b5340
Whereas we'd want the update logic to only act on the PR to which the check or status update corresponds? |
Actually, I think I'm misunderstanding how that looping to try to merge works. Perhaps we should try updates in the same places. I'll make an attempt at that now |
Yeah, both checks and statuses are attached to commits, which could be the HEAD of multiple open PRs (but in practice are usually only part of one.) The loops iterate over all of the open PRs associated with the updated commit, meaning you'll want to check if updates are necessary inside the loop, either before or after checking if merges are necessary. |
I've finished most of the code changes here. I'm rewriting the Do you think we need the full matrix of all combinations of test scenarios? It seems like a lot of tests, and I'm not sure how valuable all of the permutations are vs having tests covering the major scenarios. I can push what I have so far to help with considering, if needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing this and especially for updating the tests - I really appreciate you leaving those better than you found them!
Overall this looks good, just a minor behavior question and some style suggestions.
@@ -102,34 +102,34 @@ func ShouldMergePR(ctx context.Context, pullCtx pull.Context, mergeConfig MergeC | |||
if mergeConfig.Ignore.Enabled() { | |||
ignored, reason, err := IsPRIgnored(ctx, pullCtx, mergeConfig.Ignore) | |||
if err != nil { | |||
return false, errors.Wrap(err, "failed to determine if pull request is ignored") | |||
return false, errors.Wrap(err, "failed to determine if pull request is ignored for merge") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying/deduplicating these messages!
bulldozer/evaluate_test.go
Outdated
func TestShouldUpdatePR(t *testing.T) { | ||
ctx := context.Background() | ||
tests := []struct { | ||
name string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating these tests! The new structure is much easier to read and follow.
When I write tests like this, I tend to use a map where the test name is the key. Do you have any thoughts on that style vs. including the name as a property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no preference either way 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored to map in 96baa96. I do kind of like how this format looks. Helps compact the cases down a bit with one less line per case.
bulldozer/evaluate_test.go
Outdated
expectingUpdate: true, | ||
}, | ||
// Test error handling | ||
// TestShouldUpdatePR TODO: add error scenario coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a new TODO, it's probably fine to ignore for now, since I don't think we covered the error cases in the old tests either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I'm fine leaving it out. I mainly added it to consider implementing error tests in a future update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 75c6e43
server/handler/check_run.go
Outdated
var err error | ||
didUpdatePR, err = h.UpdatePullRequest(logger.WithContext(ctx), pullCtx, client, config, pr, base) | ||
if err != nil { | ||
logger.Error().Err(errors.WithStack(err)).Msg("Error updating pull request") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be a little simpler (and match the pull request handler) to invert this condition: instead of checking !didUpdatePR
outside of this branch, check didUpdatePR
here and continue.
var err error | |
didUpdatePR, err = h.UpdatePullRequest(logger.WithContext(ctx), pullCtx, client, config, pr, base) | |
if err != nil { | |
logger.Error().Err(errors.WithStack(err)).Msg("Error updating pull request") | |
} | |
didUpdatePR, err := h.UpdatePullRequest(logger.WithContext(ctx), pullCtx, client, config, pr, base) | |
if err != nil { | |
logger.Error().Err(errors.WithStack(err)).Msg("Error updating pull request") | |
} | |
if didUpdatePR { | |
continue | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, happy to make this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed for both check_run and status events in 92aad8f
cc8eaed
to
96baa96
Compare
Thanks again. I'll try to make a release with this early next week, but feel free to tag me here if that doesn't happen. For now, you can use the |
Thank you! |
Summary
Closes #259
required_statuses
to Bulldozer update configShouldUpdatePR
toevaluate.go
to be alongsideShouldMergePR
and reuse some status checks codeupdate_test.go
since they all coveredShouldUpdatePR
and were refactored toevaluate_test.go
TestShouldUpdatePR
to table-based tests so it is easier to understand the test cases