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

autoupdate: fix: status of previous HEAD commit is evaluated after base branch update #109

Merged
merged 6 commits into from
Mar 13, 2024
Merged
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 internal/autoupdate/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const defPeriodicTriggerInterval = 30 * time.Minute
// GithubClient defines the methods of a GithubAPI Client that are used by the
// autoupdate implementation.
type GithubClient interface {
UpdateBranch(ctx context.Context, owner, repo string, pullRequestNumber int) (changed bool, scheduled bool, err error)
UpdateBranch(ctx context.Context, owner, repo string, pullRequestNumber int) (*githubclt.UpdateBranchResult, error)
CreateIssueComment(ctx context.Context, owner, repo string, issueOrPRNr int, comment string) error
ListPullRequests(ctx context.Context, owner, repo, state, sort, sortDirection string) githubclt.PRIterator
ReadyForMerge(ctx context.Context, owner, repo string, prNumber int) (*githubclt.ReadyForMergeStatus, error)
Expand Down
20 changes: 7 additions & 13 deletions internal/autoupdate/autoupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,14 @@ func mockSuccessfulGithubUpdateBranchCall(clt *mocks.MockGithubClient, expectedP
return clt.
EXPECT().
UpdateBranch(gomock.Any(), gomock.Eq(repoOwner), gomock.Eq(repo), gomock.Eq(expectedPRNr)).
Return(branchChanged, false, nil)
Return(&githubclt.UpdateBranchResult{HeadCommitID: headCommitID, Changed: branchChanged}, nil)
}

func mockFailedGithubUpdateBranchCall(clt *mocks.MockGithubClient, expectedPRNr int) *gomock.Call {
return clt.
EXPECT().
UpdateBranch(gomock.Any(), gomock.Eq(repoOwner), gomock.Eq(repo), gomock.Eq(expectedPRNr)).
DoAndReturn(func(context.Context, string, string, int) (bool, bool, error) {
return false, false, errors.New("error mocked by mockFailedGithubUpdateBranchCall")
})
Return(nil, errors.New("error mocked by mockFailedGithubUpdateBranchCall"))
}

func mockSuccesssfulCreateIssueCommentCall(clt *mocks.MockGithubClient, expectedPRNr int) *gomock.Call {
Expand Down Expand Up @@ -718,9 +716,7 @@ func TestSuccessStatusOrCheckEventResumesPRs(t *testing.T) {
ghClient.
EXPECT().
UpdateBranch(gomock.Any(), gomock.Eq(repoOwner), gomock.Eq(repo), gomock.Any()).
DoAndReturn(func(context.Context, string, string, int) (bool, bool, error) {
return false, false, nil
}).
Return(&githubclt.UpdateBranchResult{HeadCommitID: headCommitID}, nil).
MinTimes(3)

mergeStatusPr1 := mockReadyForMergeStatus(
Expand Down Expand Up @@ -905,9 +901,7 @@ func TestFailedStatusEventSuspendsFirstPR(t *testing.T) {
ghClient.
EXPECT().
UpdateBranch(gomock.Any(), gomock.Eq(repoOwner), gomock.Eq(repo), gomock.Any()).
DoAndReturn(func(context.Context, string, string, int) (bool, bool, error) {
return false, false, nil
}).
Return(&githubclt.UpdateBranchResult{HeadCommitID: headCommitID}, nil).
AnyTimes()

retryer := goordinator.NewRetryer()
Expand Down Expand Up @@ -1163,7 +1157,7 @@ func TestInitialSync(t *testing.T) {
ghClient.
EXPECT().
UpdateBranch(gomock.Any(), gomock.Eq(repoOwner), gomock.Eq(repo), gomock.Any()).
Return(true, false, nil).
Return(&githubclt.UpdateBranchResult{Changed: true, HeadCommitID: headCommitID}, nil).
AnyTimes()

prIterNone := mocks.NewMockPRIterator(mockctrl)
Expand Down Expand Up @@ -1541,9 +1535,9 @@ func TestBaseBranchUpdatesBlockUntilFinished(t *testing.T) {
ghClient.
EXPECT().
UpdateBranch(gomock.Any(), gomock.Eq(repoOwner), gomock.Eq(repo), gomock.Any()).
DoAndReturn(func(context.Context, string, string, int) (bool, bool, error) {
DoAndReturn(func(context.Context, string, string, int) (*githubclt.UpdateBranchResult, error) {
atomic.AddInt64(&updateBranchCalls, 1)
return true, scheduledReturnVal.Load(), nil
return &githubclt.UpdateBranchResult{Changed: true, HeadCommitID: headCommitID, Scheduled: scheduledReturnVal.Load()}, nil
}).MinTimes(1)

mockSuccessfulGithubAddLabelQueueHeadCall(ghClient, prNumber).AnyTimes()
Expand Down
7 changes: 5 additions & 2 deletions internal/autoupdate/drygithubclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/simplesurance/goordinator/internal/githubclt"
)

const headCommitID = "32d4ff96ea72412277bbfd22ff1bab3a5263b415"

// DryGithubClient is a github-client that does not do any changes on github.
// All operations that could cause a change are simulated and always succeed.
// All all other operations are forwarded to a wrapped GithubClient.
Expand All @@ -23,9 +25,9 @@ func NewDryGithubClient(clt GithubClient, logger *zap.Logger) *DryGithubClient {
}
}

func (c *DryGithubClient) UpdateBranch(context.Context, string, string, int) (bool, bool, error) {
func (c *DryGithubClient) UpdateBranch(context.Context, string, string, int) (*githubclt.UpdateBranchResult, error) {
c.logger.Info("simulated updating of github branch, returning is uptodate")
return false, false, nil
return &githubclt.UpdateBranchResult{HeadCommitID: headCommitID}, nil
}

func (c *DryGithubClient) ReadyForMerge(context.Context, string, string, int) (*githubclt.ReadyForMergeStatus, error) {
Expand All @@ -34,6 +36,7 @@ func (c *DryGithubClient) ReadyForMerge(context.Context, string, string, int) (*
return &githubclt.ReadyForMergeStatus{
ReviewDecision: githubclt.ReviewDecisionApproved,
CIStatus: githubclt.CIStatusSuccess,
Commit: headCommitID,
}, nil
}

Expand Down
9 changes: 4 additions & 5 deletions internal/autoupdate/mocks/autoupdate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading