Skip to content

Commit

Permalink
fix: pass gitlab mergerequest param via json body (#322)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Vernin <[email protected]>
  • Loading branch information
olblak authored Nov 21, 2024
1 parent 7dc2e34 commit d5ed63c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 16 additions & 7 deletions scm/driver/gitlab/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,23 @@ func (s *pullService) ListCommits(ctx context.Context, repo string, number int,
}

func (s *pullService) Create(ctx context.Context, repo string, input *scm.PullRequestInput) (*scm.PullRequest, *scm.Response, error) {
in := url.Values{}
in.Set("title", input.Title)
in.Set("description", input.Body)
in.Set("source_branch", input.Source)
in.Set("target_branch", input.Target)
path := fmt.Sprintf("api/v4/projects/%s/merge_requests?%s", encode(repo), in.Encode())
// https://docs.gitlab.com/ee/api/merge_requests.html#create-mr
in := struct {
Title string `json:"title"`
Description string `json:"description"`
SourceBranch string `json:"source_branch"`
TargetBranch string `json:"target_branch"`
}{
Title: input.Title,
Description: input.Body,
SourceBranch: input.Source,
TargetBranch: input.Target,
}

path := fmt.Sprintf("api/v4/projects/%s/merge_requests", encode(repo))

out := new(pr)
res, err := s.client.do(ctx, "POST", path, nil, out)
res, err := s.client.do(ctx, "POST", path, in, out)
return convertPullRequest(out), res, err
}

Expand Down
4 changes: 0 additions & 4 deletions scm/driver/gitlab/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ func TestPullCreate(t *testing.T) {

gock.New("https://gitlab.com").
Post("/api/v4/projects/diaspora/diaspora/merge_requests").
MatchParam("title", input.Title).
MatchParam("description", input.Body).
MatchParam("source_branch", input.Source).
MatchParam("target_branch", input.Target).
Reply(201).
Type("application/json").
SetHeaders(mockHeaders).
Expand Down

0 comments on commit d5ed63c

Please sign in to comment.