diff --git a/vcsclient/gitlab.go b/vcsclient/gitlab.go index 643f0006..54006109 100644 --- a/vcsclient/gitlab.go +++ b/vcsclient/gitlab.go @@ -246,7 +246,7 @@ func (client *GitLabClient) UpdatePullRequest(ctx context.Context, owner, reposi Title: &title, Description: &body, TargetBranch: &targetBranchName, - StateEvent: vcsutils.MapPullRequestState(&state), + StateEvent: mapGitLabPullRequestState(&state), } client.logger.Debug("updating details of merge request ID:", prId) _, _, err := client.glClient.MergeRequests.UpdateMergeRequest(getProjectID(owner, repository), prId, options, gitlab.WithContext(ctx)) @@ -827,3 +827,16 @@ func (client *GitLabClient) getProjectOwnerByID(projectID int) (string, error) { } return project.Namespace.Name, nil } + +func mapGitLabPullRequestState(state *vcsutils.PullRequestState) *string { + var stateStringValue string + switch *state { + case vcsutils.Open: + stateStringValue = "reopen" + case vcsutils.Closed: + stateStringValue = "closed" + default: + return nil + } + return &stateStringValue +} diff --git a/vcsclient/gitlab_test.go b/vcsclient/gitlab_test.go index b324fcb1..2bbaa0fa 100644 --- a/vcsclient/gitlab_test.go +++ b/vcsclient/gitlab_test.go @@ -177,6 +177,12 @@ func TestGitLabClient_UpdatePullRequest(t *testing.T) { err := client.UpdatePullRequest(ctx, owner, repo1, "PR title", "PR body", "master", prId, vcsutils.Open) assert.NoError(t, err) + err = client.UpdatePullRequest(ctx, owner, repo1, "PR title", "PR body", "", prId, vcsutils.Open) + assert.NoError(t, err) + err = client.UpdatePullRequest(ctx, owner, repo1, "PR title", "PR body", "", prId, vcsutils.Closed) + assert.NoError(t, err) + err = client.UpdatePullRequest(ctx, owner, repo1, "PR title", "PR body", "", prId, "default") + assert.NoError(t, err) } func TestGitLabClient_AddPullRequestComment(t *testing.T) {