1//
2// Copyright 2018, Patrick Webster
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17package gitlab
18
19import (
20 "fmt"
21)
22
23// GroupIssueBoardsService handles communication with the group issue board
24// related methods of the GitLab API.
25//
26// GitLab API docs:
27// https://docs.gitlab.com/ce/api/group_boards.html
28type GroupIssueBoardsService struct {
29 client *Client
30}
31
32// GroupIssueBoard represents a GitLab group issue board.
33//
34// GitLab API docs:
35// https://docs.gitlab.com/ce/api/group_boards.html
36type GroupIssueBoard struct {
37 ID int `json:"id"`
38 Name string `json:"name"`
39 Group *Group `json:"group"`
40 Milestone *Milestone `json:"milestone"`
41 Lists []*BoardList `json:"lists"`
42}
43
44func (b GroupIssueBoard) String() string {
45 return Stringify(b)
46}
47
48// ListGroupIssueBoardsOptions represents the available
49// ListGroupIssueBoards() options.
50//
51// GitLab API docs:
52// https://docs.gitlab.com/ce/api/group_boards.html#group-board
53type ListGroupIssueBoardsOptions ListOptions
54
55// ListGroupIssueBoards gets a list of all issue boards in a group.
56//
57// GitLab API docs:
58// https://docs.gitlab.com/ce/api/group_boards.html#group-board
59func (s *GroupIssueBoardsService) ListGroupIssueBoards(gid interface{}, opt *ListGroupIssueBoardsOptions, options ...OptionFunc) ([]*GroupIssueBoard, *Response, error) {
60 group, err := parseID(gid)
61 if err != nil {
62 return nil, nil, err
63 }
64 u := fmt.Sprintf("groups/%s/boards", pathEscape(group))
65
66 req, err := s.client.NewRequest("GET", u, opt, options)
67 if err != nil {
68 return nil, nil, err
69 }
70
71 var gs []*GroupIssueBoard
72 resp, err := s.client.Do(req, &gs)
73 if err != nil {
74 return nil, resp, err
75 }
76
77 return gs, resp, err
78}
79
80// GetGroupIssueBoard gets a single issue board of a group.
81//
82// GitLab API docs:
83// https://docs.gitlab.com/ce/api/group_boards.html#single-board
84func (s *GroupIssueBoardsService) GetGroupIssueBoard(gid interface{}, board int, options ...OptionFunc) (*GroupIssueBoard, *Response, error) {
85 group, err := parseID(gid)
86 if err != nil {
87 return nil, nil, err
88 }
89 u := fmt.Sprintf("groups/%s/boards/%d", pathEscape(group), board)
90
91 req, err := s.client.NewRequest("GET", u, nil, options)
92 if err != nil {
93 return nil, nil, err
94 }
95
96 gib := new(GroupIssueBoard)
97 resp, err := s.client.Do(req, gib)
98 if err != nil {
99 return nil, resp, err
100 }
101
102 return gib, resp, err
103}
104
105// ListGroupIssueBoardListsOptions represents the available
106// ListGroupIssueBoardLists() options.
107//
108// GitLab API docs:
109// https://docs.gitlab.com/ce/api/group_boards.html#list-board-lists
110type ListGroupIssueBoardListsOptions ListOptions
111
112// ListGroupIssueBoardLists gets a list of the issue board's lists. Does not include
113// backlog and closed lists.
114//
115// GitLab API docs: https://docs.gitlab.com/ce/api/group_boards.html#list-board-lists
116func (s *GroupIssueBoardsService) ListGroupIssueBoardLists(gid interface{}, board int, opt *ListGroupIssueBoardListsOptions, options ...OptionFunc) ([]*BoardList, *Response, error) {
117 group, err := parseID(gid)
118 if err != nil {
119 return nil, nil, err
120 }
121 u := fmt.Sprintf("groups/%s/boards/%d/lists", pathEscape(group), board)
122
123 req, err := s.client.NewRequest("GET", u, opt, options)
124 if err != nil {
125 return nil, nil, err
126 }
127
128 var gbl []*BoardList
129 resp, err := s.client.Do(req, &gbl)
130 if err != nil {
131 return nil, resp, err
132 }
133
134 return gbl, resp, err
135}
136
137// GetGroupIssueBoardList gets a single issue board list.
138//
139// GitLab API docs:
140// https://docs.gitlab.com/ce/api/group_boards.html#single-board-list
141func (s *GroupIssueBoardsService) GetGroupIssueBoardList(gid interface{}, board, list int, options ...OptionFunc) (*BoardList, *Response, error) {
142 group, err := parseID(gid)
143 if err != nil {
144 return nil, nil, err
145 }
146 u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
147 pathEscape(group),
148 board,
149 list,
150 )
151
152 req, err := s.client.NewRequest("GET", u, nil, options)
153 if err != nil {
154 return nil, nil, err
155 }
156
157 gbl := new(BoardList)
158 resp, err := s.client.Do(req, gbl)
159 if err != nil {
160 return nil, resp, err
161 }
162
163 return gbl, resp, err
164}
165
166// CreateGroupIssueBoardListOptions represents the available
167// CreateGroupIssueBoardList() options.
168//
169// GitLab API docs:
170// https://docs.gitlab.com/ce/api/group_boards.html#new-board-list
171type CreateGroupIssueBoardListOptions struct {
172 LabelID *int `url:"label_id" json:"label_id"`
173}
174
175// CreateGroupIssueBoardList creates a new issue board list.
176//
177// GitLab API docs:
178// https://docs.gitlab.com/ce/api/group_boards.html#new-board-list
179func (s *GroupIssueBoardsService) CreateGroupIssueBoardList(gid interface{}, board int, opt *CreateGroupIssueBoardListOptions, options ...OptionFunc) (*BoardList, *Response, error) {
180 group, err := parseID(gid)
181 if err != nil {
182 return nil, nil, err
183 }
184 u := fmt.Sprintf("groups/%s/boards/%d/lists", pathEscape(group), board)
185
186 req, err := s.client.NewRequest("POST", u, opt, options)
187 if err != nil {
188 return nil, nil, err
189 }
190
191 gbl := new(BoardList)
192 resp, err := s.client.Do(req, gbl)
193 if err != nil {
194 return nil, resp, err
195 }
196
197 return gbl, resp, err
198}
199
200// UpdateGroupIssueBoardListOptions represents the available
201// UpdateGroupIssueBoardList() options.
202//
203// GitLab API docs:
204// https://docs.gitlab.com/ce/api/group_boards.html#edit-board-list
205type UpdateGroupIssueBoardListOptions struct {
206 Position *int `url:"position" json:"position"`
207}
208
209// UpdateIssueBoardList updates the position of an existing
210// group issue board list.
211//
212// GitLab API docs:
213// https://docs.gitlab.com/ce/api/group_boards.html#edit-board-list
214func (s *GroupIssueBoardsService) UpdateIssueBoardList(gid interface{}, board, list int, opt *UpdateGroupIssueBoardListOptions, options ...OptionFunc) ([]*BoardList, *Response, error) {
215 group, err := parseID(gid)
216 if err != nil {
217 return nil, nil, err
218 }
219 u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
220 pathEscape(group),
221 board,
222 list,
223 )
224
225 req, err := s.client.NewRequest("PUT", u, opt, options)
226 if err != nil {
227 return nil, nil, err
228 }
229
230 var gbl []*BoardList
231 resp, err := s.client.Do(req, gbl)
232 if err != nil {
233 return nil, resp, err
234 }
235
236 return gbl, resp, err
237}
238
239// DeleteGroupIssueBoardList soft deletes a group issue board list.
240// Only for admins and group owners.
241//
242// GitLab API docs:
243// https://docs.gitlab.com/ce/api/group_boards.html#delete-a-board-list
244func (s *GroupIssueBoardsService) DeleteGroupIssueBoardList(gid interface{}, board, list int, options ...OptionFunc) (*Response, error) {
245 group, err := parseID(gid)
246 if err != nil {
247 return nil, err
248 }
249 u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
250 pathEscape(group),
251 board,
252 list,
253 )
254
255 req, err := s.client.NewRequest("DELETE", u, nil, options)
256 if err != nil {
257 return nil, err
258 }
259
260 return s.client.Do(req, nil)
261}