Skip to content

Commit

Permalink
Fix GitLab Update MR (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea authored Sep 14, 2023
1 parent 2c007f4 commit 7371a84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion vcsclient/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions vcsclient/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7371a84

Please sign in to comment.