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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Project-Configuration/Project-Configuration-Files.md
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ Every task has some expansions available by default:
- `${workdir}` is the task's working directory
- `${revision}` is the commit hash of the base commit that a patch's changes
are being applied to, or of the commit for a mainline build. For PR patches,
the base commit is the PR base chosen by GitHub.
this is the merge base of the PR branch and the target branch.
- `${github_commit}` is the commit hash of the commit that triggered
the patch run
- `${branch_name}` is the name of the branch tracked by the
Expand Down
3 changes: 2 additions & 1 deletion model/patch/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (g *githubIntent) NewPatch() *Patch {
Author: evergreen.GithubPatchUser,
Status: evergreen.VersionCreated,
CreateTime: g.CreatedAt,
Githash: g.BaseHash,
Githash: g.MergeBase,
GithubPatchData: thirdparty.GithubPatch{
PRNumber: g.PRNumber,
BaseOwner: baseRepo[0],
Expand All @@ -302,6 +302,7 @@ func (g *githubIntent) NewPatch() *Patch {
HeadOwner: headRepo[0],
HeadRepo: headRepo[1],
HeadHash: g.HeadHash,
BaseHash: g.BaseHash,
MergeBase: g.MergeBase,
Author: g.User,
AuthorUID: g.UID,
Expand Down
2 changes: 1 addition & 1 deletion model/patch/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (s *GithubSuite) TestFindUnprocessedGithubIntents() {

func (s *GithubSuite) TestNewPatch() {
s.NoError(db.Clear(IntentCollection))
intent, err := NewGithubIntent("4", "", "", "", "", testutil.NewGithubPR(s.pr, s.baseRepo, s.baseHash, s.headRepo, s.hash, s.user, s.title))
intent, err := NewGithubIntent("4", "", "", "", s.baseHash, testutil.NewGithubPR(s.pr, s.baseRepo, s.baseHash, s.headRepo, s.hash, s.user, s.title))
s.NoError(err)
s.NotNil(intent)
s.NoError(intent.Insert())
Expand Down
2 changes: 1 addition & 1 deletion rest/data/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (s *PatchConnectorAbortByIdSuite) SetupSuite() {
var err error
s.prBody, err = os.ReadFile(filepath.Join(testutil.GetDirectoryOfFile(), "..", "route", "testdata", "pull_request.json"))
s.NoError(err)
s.Len(s.prBody, 24692)
s.Len(s.prBody, 24073)
}

func (s *PatchConnectorAbortByIdSuite) TearDownSuite() {
Expand Down
21 changes: 9 additions & 12 deletions rest/route/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,19 +721,16 @@ func (gh *githubHookApi) AddIntentForPR(ctx context.Context, pr *github.PullRequ
if projectRef == nil {
return nil
}
var mergeBase string
if projectRef.OldestAllowedMergeBase != "" {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
baseOwnerAndRepo := strings.Split(pr.Base.Repo.GetFullName(), "/")
if len(baseOwnerAndRepo) != 2 {
return errors.New("PR base repo name is invalid (expected [owner]/[repo])")
}
mergeBase, err = thirdparty.GetGithubMergeBaseRevision(ctx, baseOwnerAndRepo[0], baseOwnerAndRepo[1], pr.Base.GetRef(), pr.Head.GetRef())
if err != nil {
return errors.Wrapf(err, "getting merge base between branches '%s' and '%s'", pr.Base.GetRef(), pr.Head.GetRef())
}

baseOwnerAndRepo := strings.Split(pr.Base.Repo.GetFullName(), "/")
if len(baseOwnerAndRepo) != 2 {
return errors.New("PR base repo name is invalid (expected [owner]/[repo])")
}
mergeBase, err := thirdparty.GetPullRequestMergeBase(ctx, baseOwnerAndRepo[0], baseOwnerAndRepo[1], pr.Base.GetLabel(), pr.Head.GetLabel(), pr.GetNumber())
if err != nil {
return errors.Wrapf(err, "getting merge base between branches '%s' and '%s'", pr.Base.GetLabel(), pr.Head.GetLabel())
}

ghi, err := patch.NewGithubIntent(gh.msgID, owner, calledBy, alias, mergeBase, pr)
if err != nil {
return errors.Wrap(err, "creating GitHub patch intent")
Expand Down
13 changes: 7 additions & 6 deletions rest/route/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (s *GithubWebhookRouteSuite) SetupSuite() {

s.conf = testutil.TestConfig()
s.NotNil(s.conf)
testutil.ConfigureIntegrationTest(s.T(), s.conf)
}

func (s *GithubWebhookRouteSuite) TearDownSuite() {
Expand All @@ -81,10 +82,10 @@ func (s *GithubWebhookRouteSuite) SetupTest() {
var err error
s.prBody, err = os.ReadFile(filepath.Join(testutil.GetDirectoryOfFile(), "testdata", "pull_request.json"))
s.NoError(err)
s.Len(s.prBody, 24692)
s.Len(s.prBody, 24073)
s.pushBody, err = os.ReadFile(filepath.Join(testutil.GetDirectoryOfFile(), "testdata", "push_event.json"))
s.NoError(err)
s.Len(s.pushBody, 7597)
s.Len(s.pushBody, 7378)
s.commitQueueCommentBody, err = os.ReadFile(filepath.Join(testutil.GetDirectoryOfFile(), "testdata", "commit_queue_comment_event.json"))
s.NoError(err)
s.Len(s.commitQueueCommentBody, 11494)
Expand Down Expand Up @@ -112,9 +113,9 @@ func (s *GithubWebhookRouteSuite) TestAddIntentAndFailsWithDuplicate() {
s.NoError(db.ClearCollections(model.ProjectRefCollection, patch.IntentCollection))

doc := &model.ProjectRef{
Owner: "baxterthehacker",
Repo: "public-repo",
Branch: "main",
Owner: "evergreen-ci",
Repo: "evergreen",
Branch: "105bbb4b34e7da59c42cb93d92954710b1f101ee",
Enabled: true,
BatchTime: 10,
Id: "ident0",
Expand Down Expand Up @@ -212,7 +213,7 @@ func (s *GithubWebhookRouteSuite) TestPushEventTriggersRepoTracker() {
ref := &model.ProjectRef{
Id: "meh",
Enabled: true,
Owner: "baxterthehacker",
Owner: "evergreen-ci",
Repo: "public-repo",
Branch: "changes",
}
Expand Down
Loading
Loading