From 407ef678872ed1c3cc0e2df7053bd6cb84f6b844 Mon Sep 17 00:00:00 2001 From: Eko Simanjuntak Date: Thu, 29 Sep 2022 14:09:49 +0800 Subject: [PATCH] fix: add option to accept mr when pipeline succeed --- pkg/gitlab/gitlab_mock/merge_request.go | 14 +++++++------- pkg/gitlab/merge_request.go | 7 ++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/gitlab/gitlab_mock/merge_request.go b/pkg/gitlab/gitlab_mock/merge_request.go index c72343e..87d8e2f 100644 --- a/pkg/gitlab/gitlab_mock/merge_request.go +++ b/pkg/gitlab/gitlab_mock/merge_request.go @@ -14,13 +14,13 @@ type MergeRequest struct { mock.Mock } -// Accept provides a mock function with given fields: projectId, mergeRequestID, removeBranch -func (_m *MergeRequest) Accept(projectId gitlab.NameOrId, mergeRequestID int, removeBranch bool) (*go_gitlab.MergeRequest, error) { - ret := _m.Called(projectId, mergeRequestID, removeBranch) +// Accept provides a mock function with given fields: projectId, mergeRequestID, removeBranch, whenPipelinePassed +func (_m *MergeRequest) Accept(projectId gitlab.NameOrId, mergeRequestID int, removeBranch bool, whenPipelinePassed bool) (*go_gitlab.MergeRequest, error) { + ret := _m.Called(projectId, mergeRequestID, removeBranch, whenPipelinePassed) var r0 *go_gitlab.MergeRequest - if rf, ok := ret.Get(0).(func(gitlab.NameOrId, int, bool) *go_gitlab.MergeRequest); ok { - r0 = rf(projectId, mergeRequestID, removeBranch) + if rf, ok := ret.Get(0).(func(gitlab.NameOrId, int, bool, bool) *go_gitlab.MergeRequest); ok { + r0 = rf(projectId, mergeRequestID, removeBranch, whenPipelinePassed) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*go_gitlab.MergeRequest) @@ -28,8 +28,8 @@ func (_m *MergeRequest) Accept(projectId gitlab.NameOrId, mergeRequestID int, re } var r1 error - if rf, ok := ret.Get(1).(func(gitlab.NameOrId, int, bool) error); ok { - r1 = rf(projectId, mergeRequestID, removeBranch) + if rf, ok := ret.Get(1).(func(gitlab.NameOrId, int, bool, bool) error); ok { + r1 = rf(projectId, mergeRequestID, removeBranch, whenPipelinePassed) } else { r1 = ret.Error(1) } diff --git a/pkg/gitlab/merge_request.go b/pkg/gitlab/merge_request.go index 6369a04..c234f7a 100644 --- a/pkg/gitlab/merge_request.go +++ b/pkg/gitlab/merge_request.go @@ -26,7 +26,7 @@ type MergeRequest interface { CreateToMaster(projectId NameOrId, sourceBranch string, title string) (*gl.MergeRequest, error) Approve(projectId NameOrId, mergeRequestID int) error Close(projectId NameOrId, mergeRequestID int) error - Accept(projectId NameOrId, mergeRequestID int, removeBranch bool) (*gl.MergeRequest, error) + Accept(projectId NameOrId, mergeRequestID int, removeBranch bool, whenPipelinePassed bool) (*gl.MergeRequest, error) } type mergeRequest struct { @@ -94,9 +94,10 @@ func (e *mergeRequest) Close(projectId NameOrId, mergeRequestID int) error { return err } -func (e *mergeRequest) Accept(projectId NameOrId, mergeRequestID int, removeBranch bool) (*gl.MergeRequest, error) { +func (e *mergeRequest) Accept(projectId NameOrId, mergeRequestID int, removeBranch bool, whenPipelinePassed bool) (*gl.MergeRequest, error) { mr, _, err := e.client.MergeRequests.AcceptMergeRequest(projectId.Get(), mergeRequestID, &gl.AcceptMergeRequestOptions{ - ShouldRemoveSourceBranch: gl.Bool(removeBranch), + ShouldRemoveSourceBranch: gl.Bool(removeBranch), + MergeWhenPipelineSucceeds: gl.Bool(whenPipelinePassed), }) if err != nil { return nil, err