Verified Commit 22c480d7 authored by José M. Requena Plens's avatar José M. Requena Plens Committed by GitLab
Browse files

fix(group_boards): return the single updated list from UpdateIssueBoardList

Changelog: Improvements
parent 75a2e500
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -180,3 +180,28 @@ for _, reviewer := range event.Reviewers {
    fmt.Println(reviewer.Username, reviewer.State, reviewer.ReRequested)
}
```

## Return a single "BoardList" from group "UpdateIssueBoardList"

`GroupIssueBoardsService.UpdateIssueBoardList` declared `[]*BoardList` as its
return type, but the [edit group issue board list API](https://docs.gitlab.com/api/group_boards/#edit-group-issue-board-list)
returns the updated list as a single JSON object. Successful calls could never
be decoded (`json: cannot unmarshal object into Go value of type
[]*gitlab.BoardList`), so the method now returns `*BoardList`, matching the
project-level `IssueBoardsService.UpdateIssueBoardList`.

**Changes:**

```go
// Before (v2.x)
lists, _, err := client.GroupIssueBoards.UpdateIssueBoardList(5, 1, 2, &UpdateGroupIssueBoardListOptions{
    Position: Ptr(int64(1)),
})
// err was always non-nil on success responses; lists was never populated.

// After (v3.0)
list, _, err := client.GroupIssueBoards.UpdateIssueBoardList(5, 1, 2, &UpdateGroupIssueBoardListOptions{
    Position: Ptr(int64(1)),
})
// list is the updated board list.
```
+3 −3
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ type (
		//
		// GitLab API docs:
		// https://docs.gitlab.com/api/group_boards/#edit-group-issue-board-list
		UpdateIssueBoardList(gid any, board, list int64, opt *UpdateGroupIssueBoardListOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error)
		UpdateIssueBoardList(gid any, board, list int64, opt *UpdateGroupIssueBoardListOptions, options ...RequestOptionFunc) (*BoardList, *Response, error)
		DeleteGroupIssueBoardList(gid any, board, list int64, options ...RequestOptionFunc) (*Response, error)
	}

@@ -227,8 +227,8 @@ type UpdateGroupIssueBoardListOptions struct {
	Position *int64 `url:"position" json:"position"`
}

func (s *GroupIssueBoardsService) UpdateIssueBoardList(gid any, board, list int64, opt *UpdateGroupIssueBoardListOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) {
	return do[[]*BoardList](s.client,
func (s *GroupIssueBoardsService) UpdateIssueBoardList(gid any, board, list int64, opt *UpdateGroupIssueBoardListOptions, options ...RequestOptionFunc) (*BoardList, *Response, error) {
	return do[*BoardList](s.client,
		withMethod(http.MethodPut),
		withPath("groups/%s/boards/%d/lists/%d", GroupID{gid}, board, list),
		withAPIOpts(opt),
+1 −41
Original line number Diff line number Diff line
@@ -665,7 +665,6 @@ func TestGroupIssueBoardsService_UpdateIssueBoardList(t *testing.T) {
	mux.HandleFunc("/api/v4/groups/5/boards/1/lists/1", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodPut)
		fmt.Fprintf(w, `
			[
			{
			  "id" : 1,
			  "label" : {
@@ -674,31 +673,11 @@ func TestGroupIssueBoardsService_UpdateIssueBoardList(t *testing.T) {
				"description" : null
			  },
			  "position" : 1
			  },
			  {
				"id" : 2,
				"label" : {
				  "name" : "Ready",
				  "color" : "#FF0000",
				  "description" : null
				},
				"position" : 2
			  },
			  {
				"id" : 3,
				"label" : {
				  "name" : "Production",
				  "color" : "#FF5F00",
				  "description" : null
				},
				"position" : 3
			}
			]
		`)
	})

	want := []*BoardList{
		{
	want := &BoardList{
		ID: 1,
		Label: &Label{
			Name:        "Testing",
@@ -706,25 +685,6 @@ func TestGroupIssueBoardsService_UpdateIssueBoardList(t *testing.T) {
			Description: "",
		},
		Position: 1,
		},
		{
			ID: 2,
			Label: &Label{
				Name:        "Ready",
				Color:       "#FF0000",
				Description: "",
			},
			Position: 2,
		},
		{
			ID: 3,
			Label: &Label{
				Name:        "Production",
				Color:       "#FF5F00",
				Description: "",
			},
			Position: 3,
		},
	}

	bl, resp, err := client.GroupIssueBoards.UpdateIssueBoardList(5, 1, 1, nil, nil)
+5 −5
Original line number Diff line number Diff line
@@ -443,14 +443,14 @@ func (c *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardCall) DoAndReturn(f
}

// UpdateIssueBoardList mocks base method.
func (m *MockGroupIssueBoardsServiceInterface) UpdateIssueBoardList(gid any, board, list int64, opt *gitlab.UpdateGroupIssueBoardListOptions, options ...gitlab.RequestOptionFunc) ([]*gitlab.BoardList, *gitlab.Response, error) {
func (m *MockGroupIssueBoardsServiceInterface) UpdateIssueBoardList(gid any, board, list int64, opt *gitlab.UpdateGroupIssueBoardListOptions, options ...gitlab.RequestOptionFunc) (*gitlab.BoardList, *gitlab.Response, error) {
	m.ctrl.T.Helper()
	varargs := []any{gid, board, list, opt}
	for _, a := range options {
		varargs = append(varargs, a)
	}
	ret := m.ctrl.Call(m, "UpdateIssueBoardList", varargs...)
	ret0, _ := ret[0].([]*gitlab.BoardList)
	ret0, _ := ret[0].(*gitlab.BoardList)
	ret1, _ := ret[1].(*gitlab.Response)
	ret2, _ := ret[2].(error)
	return ret0, ret1, ret2
@@ -470,19 +470,19 @@ type MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall struct {
}

// Return rewrite *gomock.Call.Return
func (c *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall) Return(arg0 []*gitlab.BoardList, arg1 *gitlab.Response, arg2 error) *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall {
func (c *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall) Return(arg0 *gitlab.BoardList, arg1 *gitlab.Response, arg2 error) *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall {
	c.Call = c.Call.Return(arg0, arg1, arg2)
	return c
}

// Do rewrite *gomock.Call.Do
func (c *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall) Do(f func(any, int64, int64, *gitlab.UpdateGroupIssueBoardListOptions, ...gitlab.RequestOptionFunc) ([]*gitlab.BoardList, *gitlab.Response, error)) *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall {
func (c *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall) Do(f func(any, int64, int64, *gitlab.UpdateGroupIssueBoardListOptions, ...gitlab.RequestOptionFunc) (*gitlab.BoardList, *gitlab.Response, error)) *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall {
	c.Call = c.Call.Do(f)
	return c
}

// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall) DoAndReturn(f func(any, int64, int64, *gitlab.UpdateGroupIssueBoardListOptions, ...gitlab.RequestOptionFunc) ([]*gitlab.BoardList, *gitlab.Response, error)) *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall {
func (c *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall) DoAndReturn(f func(any, int64, int64, *gitlab.UpdateGroupIssueBoardListOptions, ...gitlab.RequestOptionFunc) (*gitlab.BoardList, *gitlab.Response, error)) *MockGroupIssueBoardsServiceInterfaceUpdateIssueBoardListCall {
	c.Call = c.Call.DoAndReturn(f)
	return c
}