Skip to content

Commit 3d128ad

Browse files
authored
Merge pull request xanzy#1335 from Bouwdie/assignee-id-merge-request-type
Add None and Any options for AssigneeID for all merge request list fu…
2 parents c465c6c + a5081d9 commit 3d128ad

File tree

3 files changed

+202
-90
lines changed

3 files changed

+202
-90
lines changed

merge_requests.go

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ type ListMergeRequestsOptions struct {
156156
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
157157
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
158158
AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"`
159-
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
159+
AssigneeID *AssigneeIDValue `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
160+
ApproverIDs *ApproverIDsValue `url:"approver_ids,omitempty" json:"approver_ids,omitempty"`
160161
ApprovedByIDs *ApproverIDsValue `url:"approved_by_ids,omitempty" json:"approved_by_ids,omitempty"`
161-
ReviewerID *int `url:"reviewer_id,omitempty" json:"reviewer_id,omitempty"`
162+
ReviewerID *ReviewerIDValue `url:"reviewer_id,omitempty" json:"reviewer_id,omitempty"`
162163
ReviewerUsername *string `url:"reviewer_username,omitempty" json:"reviewer_username,omitempty"`
163164
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
164165
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
@@ -191,51 +192,53 @@ func (s *MergeRequestsService) ListMergeRequests(opt *ListMergeRequestsOptions,
191192
return m, resp, err
192193
}
193194

194-
// ListGroupMergeRequestsOptions represents the available ListGroupMergeRequests()
195+
// ListProjectMergeRequestsOptions represents the available ListMergeRequests()
195196
// options.
196197
//
197198
// GitLab API docs:
198-
// https://docs.gitlab.com/ce/api/merge_requests.html#list-group-merge-requests
199-
type ListGroupMergeRequestsOptions struct {
199+
// https://docs.gitlab.com/ce/api/merge_requests.html#list-project-merge-requests
200+
type ListProjectMergeRequestsOptions struct {
200201
ListOptions
201-
State *string `url:"state,omitempty" json:"state,omitempty"`
202-
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
203-
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
204-
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
205-
View *string `url:"view,omitempty" json:"view,omitempty"`
206-
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
207-
NotLabels *Labels `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
208-
WithLabelsDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
209-
WithMergeStatusRecheck *bool `url:"with_merge_status_recheck,omitempty" json:"with_merge_status_recheck,omitempty"`
210-
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
211-
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
212-
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
213-
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
214-
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
215-
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
216-
AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"`
217-
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
218-
ReviewerID *int `url:"reviewer_id,omitempty" json:"reviewer_id,omitempty"`
219-
ReviewerUsername *string `url:"reviewer_username,omitempty" json:"reviewer_username,omitempty"`
220-
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
221-
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
222-
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
223-
Search *string `url:"search,omitempty" json:"search,omitempty"`
224-
In *string `url:"in,omitempty" json:"in,omitempty"`
225-
Draft *bool `url:"draft,omitempty" json:"draft,omitempty"`
226-
WIP *string `url:"wip,omitempty" json:"wip,omitempty"`
202+
IIDs *[]int `url:"iids[],omitempty" json:"iids,omitempty"`
203+
State *string `url:"state,omitempty" json:"state,omitempty"`
204+
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
205+
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
206+
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
207+
View *string `url:"view,omitempty" json:"view,omitempty"`
208+
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
209+
NotLabels *Labels `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
210+
WithLabelsDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
211+
WithMergeStatusRecheck *bool `url:"with_merge_status_recheck,omitempty" json:"with_merge_status_recheck,omitempty"`
212+
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
213+
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
214+
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
215+
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
216+
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
217+
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
218+
AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"`
219+
AssigneeID *AssigneeIDValue `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
220+
ApproverIDs *ApproverIDsValue `url:"approver_ids,omitempty" json:"approver_ids,omitempty"`
221+
ApprovedByIDs *ApproverIDsValue `url:"approved_by_ids,omitempty" json:"approved_by_ids,omitempty"`
222+
ReviewerID *ReviewerIDValue `url:"reviewer_id,omitempty" json:"reviewer_id,omitempty"`
223+
ReviewerUsername *string `url:"reviewer_username,omitempty" json:"reviewer_username,omitempty"`
224+
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
225+
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
226+
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
227+
Search *string `url:"search,omitempty" json:"search,omitempty"`
228+
Draft *bool `url:"draft,omitempty" json:"draft,omitempty"`
229+
WIP *string `url:"wip,omitempty" json:"wip,omitempty"`
227230
}
228231

229-
// ListGroupMergeRequests gets all merge requests for this group.
232+
// ListProjectMergeRequests gets all merge requests for this project.
230233
//
231234
// GitLab API docs:
232-
// https://docs.gitlab.com/ce/api/merge_requests.html#list-group-merge-requests
233-
func (s *MergeRequestsService) ListGroupMergeRequests(gid interface{}, opt *ListGroupMergeRequestsOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
234-
group, err := parseID(gid)
235+
// https://docs.gitlab.com/ce/api/merge_requests.html#list-project-merge-requests
236+
func (s *MergeRequestsService) ListProjectMergeRequests(pid interface{}, opt *ListProjectMergeRequestsOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
237+
project, err := parseID(pid)
235238
if err != nil {
236239
return nil, nil, err
237240
}
238-
u := fmt.Sprintf("groups/%s/merge_requests", PathEscape(group))
241+
u := fmt.Sprintf("projects/%s/merge_requests", PathEscape(project))
239242

240243
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
241244
if err != nil {
@@ -251,51 +254,53 @@ func (s *MergeRequestsService) ListGroupMergeRequests(gid interface{}, opt *List
251254
return m, resp, err
252255
}
253256

254-
// ListProjectMergeRequestsOptions represents the available ListMergeRequests()
257+
// ListGroupMergeRequestsOptions represents the available ListGroupMergeRequests()
255258
// options.
256259
//
257260
// GitLab API docs:
258-
// https://docs.gitlab.com/ce/api/merge_requests.html#list-project-merge-requests
259-
type ListProjectMergeRequestsOptions struct {
261+
// https://docs.gitlab.com/ce/api/merge_requests.html#list-group-merge-requests
262+
type ListGroupMergeRequestsOptions struct {
260263
ListOptions
261-
IIDs *[]int `url:"iids[],omitempty" json:"iids,omitempty"`
262-
State *string `url:"state,omitempty" json:"state,omitempty"`
263-
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
264-
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
265-
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
266-
View *string `url:"view,omitempty" json:"view,omitempty"`
267-
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
268-
NotLabels *Labels `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
269-
WithLabelsDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
270-
WithMergeStatusRecheck *bool `url:"with_merge_status_recheck,omitempty" json:"with_merge_status_recheck,omitempty"`
271-
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
272-
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
273-
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
274-
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
275-
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
276-
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
277-
AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"`
278-
AssigneeID *int `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
279-
ReviewerID *int `url:"reviewer_id,omitempty" json:"reviewer_id,omitempty"`
280-
ReviewerUsername *string `url:"reviewer_username,omitempty" json:"reviewer_username,omitempty"`
281-
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
282-
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
283-
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
284-
Search *string `url:"search,omitempty" json:"search,omitempty"`
285-
Draft *bool `url:"draft,omitempty" json:"draft,omitempty"`
286-
WIP *string `url:"wip,omitempty" json:"wip,omitempty"`
264+
State *string `url:"state,omitempty" json:"state,omitempty"`
265+
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
266+
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
267+
Milestone *string `url:"milestone,omitempty" json:"milestone,omitempty"`
268+
View *string `url:"view,omitempty" json:"view,omitempty"`
269+
Labels *Labels `url:"labels,comma,omitempty" json:"labels,omitempty"`
270+
NotLabels *Labels `url:"not[labels],comma,omitempty" json:"not[labels],omitempty"`
271+
WithLabelsDetails *bool `url:"with_labels_details,omitempty" json:"with_labels_details,omitempty"`
272+
WithMergeStatusRecheck *bool `url:"with_merge_status_recheck,omitempty" json:"with_merge_status_recheck,omitempty"`
273+
CreatedAfter *time.Time `url:"created_after,omitempty" json:"created_after,omitempty"`
274+
CreatedBefore *time.Time `url:"created_before,omitempty" json:"created_before,omitempty"`
275+
UpdatedAfter *time.Time `url:"updated_after,omitempty" json:"updated_after,omitempty"`
276+
UpdatedBefore *time.Time `url:"updated_before,omitempty" json:"updated_before,omitempty"`
277+
Scope *string `url:"scope,omitempty" json:"scope,omitempty"`
278+
AuthorID *int `url:"author_id,omitempty" json:"author_id,omitempty"`
279+
AuthorUsername *string `url:"author_username,omitempty" json:"author_username,omitempty"`
280+
AssigneeID *AssigneeIDValue `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
281+
ApproverIDs *ApproverIDsValue `url:"approver_ids,omitempty" json:"approver_ids,omitempty"`
282+
ApprovedByIDs *ApproverIDsValue `url:"approved_by_ids,omitempty" json:"approved_by_ids,omitempty"`
283+
ReviewerID *ReviewerIDValue `url:"reviewer_id,omitempty" json:"reviewer_id,omitempty"`
284+
ReviewerUsername *string `url:"reviewer_username,omitempty" json:"reviewer_username,omitempty"`
285+
MyReactionEmoji *string `url:"my_reaction_emoji,omitempty" json:"my_reaction_emoji,omitempty"`
286+
SourceBranch *string `url:"source_branch,omitempty" json:"source_branch,omitempty"`
287+
TargetBranch *string `url:"target_branch,omitempty" json:"target_branch,omitempty"`
288+
Search *string `url:"search,omitempty" json:"search,omitempty"`
289+
In *string `url:"in,omitempty" json:"in,omitempty"`
290+
Draft *bool `url:"draft,omitempty" json:"draft,omitempty"`
291+
WIP *string `url:"wip,omitempty" json:"wip,omitempty"`
287292
}
288293

289-
// ListProjectMergeRequests gets all merge requests for this project.
294+
// ListGroupMergeRequests gets all merge requests for this group.
290295
//
291296
// GitLab API docs:
292-
// https://docs.gitlab.com/ce/api/merge_requests.html#list-project-merge-requests
293-
func (s *MergeRequestsService) ListProjectMergeRequests(pid interface{}, opt *ListProjectMergeRequestsOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
294-
project, err := parseID(pid)
297+
// https://docs.gitlab.com/ce/api/merge_requests.html#list-group-merge-requests
298+
func (s *MergeRequestsService) ListGroupMergeRequests(gid interface{}, opt *ListGroupMergeRequestsOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
299+
group, err := parseID(gid)
295300
if err != nil {
296301
return nil, nil, err
297302
}
298-
u := fmt.Sprintf("projects/%s/merge_requests", PathEscape(project))
303+
u := fmt.Sprintf("groups/%s/merge_requests", PathEscape(group))
299304

300305
req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
301306
if err != nil {

merge_requests_test.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package gitlab
1818

1919
import (
20+
"encoding/json"
2021
"fmt"
2122
"log"
2223
"net/http"
@@ -153,11 +154,12 @@ func TestListProjectMergeRequests(t *testing.T) {
153154

154155
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
155156
testMethod(t, r, http.MethodGet)
156-
testParams(t, r, "with_labels_details=true&with_merge_status_recheck=true")
157+
testParams(t, r, "assignee_id=Any&with_labels_details=true&with_merge_status_recheck=true")
157158
mustWriteHTTPResponse(t, w, "testdata/get_merge_requests.json")
158159
})
159160

160161
opts := ListProjectMergeRequestsOptions{
162+
AssigneeID: AssigneeID(UserIDAny),
161163
WithLabelsDetails: Bool(true),
162164
WithMergeStatusRecheck: Bool(true),
163165
}
@@ -250,14 +252,14 @@ func TestGetIssuesClosedOnMerge_Jira(t *testing.T) {
250252
func TestIntSliceOrString(t *testing.T) {
251253
t.Run("any", func(t *testing.T) {
252254
opts := &ListMergeRequestsOptions{}
253-
opts.ApprovedByIDs = ApproverIDs(ApproverIDAny)
255+
opts.ApprovedByIDs = ApproverIDs(UserIDAny)
254256
q, err := query.Values(opts)
255257
assert.NoError(t, err)
256258
assert.Equal(t, "Any", q.Get("approved_by_ids"))
257259
})
258260
t.Run("none", func(t *testing.T) {
259261
opts := &ListMergeRequestsOptions{}
260-
opts.ApprovedByIDs = ApproverIDs(ApproverIDNone)
262+
opts.ApprovedByIDs = ApproverIDs(UserIDNone)
261263
q, err := query.Values(opts)
262264
assert.NoError(t, err)
263265
assert.Equal(t, "None", q.Get("approved_by_ids"))
@@ -271,3 +273,33 @@ func TestIntSliceOrString(t *testing.T) {
271273
assert.Equal(t, []string{"1", "2", "3"}, includedIDs)
272274
})
273275
}
276+
277+
func TestAssigneeIDMarshalling(t *testing.T) {
278+
t.Run("any", func(t *testing.T) {
279+
opts := &ListMergeRequestsOptions{}
280+
opts.AssigneeID = AssigneeID(UserIDAny)
281+
q, err := query.Values(opts)
282+
assert.NoError(t, err)
283+
assert.Equal(t, "Any", q.Get("assignee_id"))
284+
js, _ := json.Marshal(opts)
285+
assert.Equal(t, `{"assignee_id":"Any"}`, string(js))
286+
})
287+
t.Run("none", func(t *testing.T) {
288+
opts := &ListMergeRequestsOptions{}
289+
opts.AssigneeID = AssigneeID(UserIDNone)
290+
q, err := query.Values(opts)
291+
assert.NoError(t, err)
292+
assert.Equal(t, "None", q.Get("assignee_id"))
293+
js, _ := json.Marshal(opts)
294+
assert.Equal(t, `{"assignee_id":"None"}`, string(js))
295+
})
296+
t.Run("id", func(t *testing.T) {
297+
opts := &ListMergeRequestsOptions{}
298+
opts.AssigneeID = AssigneeID(5)
299+
q, err := query.Values(opts)
300+
assert.NoError(t, err)
301+
assert.Equal(t, "5", q.Get("assignee_id"))
302+
js, _ := json.Marshal(opts)
303+
assert.Equal(t, `{"assignee_id":5}`, string(js))
304+
})
305+
}

0 commit comments

Comments
 (0)