-
Notifications
You must be signed in to change notification settings - Fork 130
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
Use merge base as base revision for PR patches #8674
base: main
Are you sure you want to change the base?
Conversation
thirdparty/github.go
Outdated
apiErr, ok := errors.Cause(err).(APIRequestError) | ||
if !ok || apiErr.StatusCode != http.StatusNotFound { | ||
return "", err | ||
} |
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.
Is there any reason to exit early on these specific error cases, rather than just retrying on any error? If the logic below ultimately behaves the same as GetGithubMergeBaseRevision
, then getting the merge base may be more resilient to other weird/unexpected GitHub results if it falls back on any error.
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.
That's fair, changed to fallback in all err cases
thirdparty/github.go
Outdated
return "", err | ||
} | ||
// If GetGithubMergeBaseRevision returns a 404 APIRequestError, fallback to the secondary way of determining a PR | ||
// merge base via API. |
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.
May be worth a clarification comment on situations where this is actually acceptable, like in the case of finding the merge base of PR based on a private fork that Evergreen doesn't have permission to access.
thirdparty/github_test.go
Outdated
@@ -325,8 +318,7 @@ func (s *githubSuite) TestGetPullRequestMergeBase() { | |||
s.ctx, s.cancel = context.WithTimeout(context.Background(), 30*time.Second) | |||
s.Require().NotNil(s.ctx) | |||
s.Require().NotNil(s.cancel) | |||
data.BaseRepo = "conifer" | |||
hash, err = GetPullRequestMergeBase(s.ctx, data) | |||
hash, err = GetPullRequestMergeBase(s.ctx, "evergreen-ci", "confier", "", "", 666) |
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.
nit: conifer? 🌲
DEVPROD-13619
Description
Re-apply #8665 & #8658
It turns out if a user has a private fork, we can't hit the https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#compare-two-commits API between the PR target branch and their fork branch, because our 10gen github app is not installed on that private repo.
There is a secondary way to figure out the merge base of a PR via API (list the PR commits and extract the parent of the first commit), so this change falls back to that method if we get a 404 from GitHub.
Testing
Found a private repo in the evergreen-ci org. Confirmed that if I make a fork off of it and try to stage a PR, no patch is created and Splunk shows the expected error:
Deployed these changes and added another commit to the test PR, and a version was created and the base revision was what I expected.