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

Use merge base as base revision for PR patches #8674

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hadjri
Copy link
Contributor

@hadjri hadjri commented Jan 29, 2025

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:

getting merge base between branches 'evergreen-ci:main' and 'hadjri:malik-test-fork': retreiving comparison between commit hashses 'evergreen-ci:main' and 'hadjri:malik-test-fork': API request error: Not Found

Deployed these changes and added another commit to the test PR, and a version was created and the base revision was what I expected.

@hadjri hadjri requested review from a team and bynn January 29, 2025 19:09
apiErr, ok := errors.Cause(err).(APIRequestError)
if !ok || apiErr.StatusCode != http.StatusNotFound {
return "", err
}
Copy link
Contributor

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.

Copy link
Contributor Author

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

return "", err
}
// If GetGithubMergeBaseRevision returns a 404 APIRequestError, fallback to the secondary way of determining a PR
// merge base via API.
Copy link
Contributor

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.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: conifer? 🌲

@hadjri hadjri requested a review from Kimchelly January 30, 2025 23:37
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