group_boards.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. package gitlab
  17. import (
  18. "fmt"
  19. "net/url"
  20. )
  21. // GroupIssueBoardsService handles communication with the group issue board
  22. // related methods of the GitLab API.
  23. //
  24. // GitLab API docs:
  25. // https://docs.gitlab.com/ce/api/group_boards.html
  26. type GroupIssueBoardsService struct {
  27. client *Client
  28. }
  29. // GroupIssueBoard represents a GitLab group issue board.
  30. //
  31. // GitLab API docs:
  32. // https://docs.gitlab.com/ce/api/group_boards.html
  33. type GroupIssueBoard struct {
  34. ID int `json:"id"`
  35. Name string `json:"name"`
  36. Group *Group `json:"group"`
  37. Milestone *Milestone `json:"milestone"`
  38. Lists []*BoardList `json:"lists"`
  39. }
  40. func (b GroupIssueBoard) String() string {
  41. return Stringify(b)
  42. }
  43. // ListGroupIssueBoardsOptions represents the available
  44. // ListGroupIssueBoards() options.
  45. //
  46. // GitLab API docs:
  47. // https://docs.gitlab.com/ce/api/group_boards.html#group-board
  48. type ListGroupIssueBoardsOptions ListOptions
  49. // ListGroupIssueBoards gets a list of all issue boards in a group.
  50. //
  51. // GitLab API docs:
  52. // https://docs.gitlab.com/ce/api/group_boards.html#group-board
  53. func (s *GroupIssueBoardsService) ListGroupIssueBoards(gid interface{}, opt *ListGroupIssueBoardsOptions, options ...OptionFunc) ([]*GroupIssueBoard, *Response, error) {
  54. group, err := parseID(gid)
  55. if err != nil {
  56. return nil, nil, err
  57. }
  58. u := fmt.Sprintf("groups/%s/boards", url.QueryEscape(group))
  59. req, err := s.client.NewRequest("GET", u, opt, options)
  60. if err != nil {
  61. return nil, nil, err
  62. }
  63. var gs []*GroupIssueBoard
  64. resp, err := s.client.Do(req, &gs)
  65. if err != nil {
  66. return nil, resp, err
  67. }
  68. return gs, resp, err
  69. }
  70. // GetGroupIssueBoard gets a single issue board of a group.
  71. //
  72. // GitLab API docs:
  73. // https://docs.gitlab.com/ce/api/group_boards.html#single-board
  74. func (s *GroupIssueBoardsService) GetGroupIssueBoard(gid interface{}, board int, options ...OptionFunc) (*GroupIssueBoard, *Response, error) {
  75. group, err := parseID(gid)
  76. if err != nil {
  77. return nil, nil, err
  78. }
  79. u := fmt.Sprintf("groups/%s/boards/%d", url.QueryEscape(group), board)
  80. req, err := s.client.NewRequest("GET", u, nil, options)
  81. if err != nil {
  82. return nil, nil, err
  83. }
  84. gib := new(GroupIssueBoard)
  85. resp, err := s.client.Do(req, gib)
  86. if err != nil {
  87. return nil, resp, err
  88. }
  89. return gib, resp, err
  90. }
  91. // ListGroupIssueBoardListsOptions represents the available
  92. // ListGroupIssueBoardLists() options.
  93. //
  94. // GitLab API docs:
  95. // https://docs.gitlab.com/ce/api/group_boards.html#list-board-lists
  96. type ListGroupIssueBoardListsOptions ListOptions
  97. // ListGroupIssueBoardLists gets a list of the issue board's lists. Does not include
  98. // backlog and closed lists.
  99. //
  100. // GitLab API docs: https://docs.gitlab.com/ce/api/group_boards.html#list-board-lists
  101. func (s *GroupIssueBoardsService) ListGroupIssueBoardLists(gid interface{}, board int, opt *ListGroupIssueBoardListsOptions, options ...OptionFunc) ([]*BoardList, *Response, error) {
  102. group, err := parseID(gid)
  103. if err != nil {
  104. return nil, nil, err
  105. }
  106. u := fmt.Sprintf("groups/%s/boards/%d/lists", url.QueryEscape(group), board)
  107. req, err := s.client.NewRequest("GET", u, opt, options)
  108. if err != nil {
  109. return nil, nil, err
  110. }
  111. var gbl []*BoardList
  112. resp, err := s.client.Do(req, &gbl)
  113. if err != nil {
  114. return nil, resp, err
  115. }
  116. return gbl, resp, err
  117. }
  118. // GetGroupIssueBoardList gets a single issue board list.
  119. //
  120. // GitLab API docs:
  121. // https://docs.gitlab.com/ce/api/group_boards.html#single-board-list
  122. func (s *GroupIssueBoardsService) GetGroupIssueBoardList(gid interface{}, board, list int, options ...OptionFunc) (*BoardList, *Response, error) {
  123. group, err := parseID(gid)
  124. if err != nil {
  125. return nil, nil, err
  126. }
  127. u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
  128. url.QueryEscape(group),
  129. board,
  130. list,
  131. )
  132. req, err := s.client.NewRequest("GET", u, nil, options)
  133. if err != nil {
  134. return nil, nil, err
  135. }
  136. gbl := new(BoardList)
  137. resp, err := s.client.Do(req, gbl)
  138. if err != nil {
  139. return nil, resp, err
  140. }
  141. return gbl, resp, err
  142. }
  143. // CreateGroupIssueBoardListOptions represents the available
  144. // CreateGroupIssueBoardList() options.
  145. //
  146. // GitLab API docs:
  147. // https://docs.gitlab.com/ce/api/group_boards.html#new-board-list
  148. type CreateGroupIssueBoardListOptions struct {
  149. LabelID *int `url:"label_id" json:"label_id"`
  150. }
  151. // CreateGroupIssueBoardList creates a new issue board list.
  152. //
  153. // GitLab API docs:
  154. // https://docs.gitlab.com/ce/api/group_boards.html#new-board-list
  155. func (s *GroupIssueBoardsService) CreateGroupIssueBoardList(gid interface{}, board int, opt *CreateGroupIssueBoardListOptions, options ...OptionFunc) (*BoardList, *Response, error) {
  156. group, err := parseID(gid)
  157. if err != nil {
  158. return nil, nil, err
  159. }
  160. u := fmt.Sprintf("groups/%s/boards/%d/lists", url.QueryEscape(group), board)
  161. req, err := s.client.NewRequest("POST", u, opt, options)
  162. if err != nil {
  163. return nil, nil, err
  164. }
  165. gbl := new(BoardList)
  166. resp, err := s.client.Do(req, gbl)
  167. if err != nil {
  168. return nil, resp, err
  169. }
  170. return gbl, resp, err
  171. }
  172. // UpdateGroupIssueBoardListOptions represents the available
  173. // UpdateGroupIssueBoardList() options.
  174. //
  175. // GitLab API docs:
  176. // https://docs.gitlab.com/ce/api/group_boards.html#edit-board-list
  177. type UpdateGroupIssueBoardListOptions struct {
  178. Position *int `url:"position" json:"position"`
  179. }
  180. // UpdateIssueBoardList updates the position of an existing
  181. // group issue board list.
  182. //
  183. // GitLab API docs:
  184. // https://docs.gitlab.com/ce/api/group_boards.html#edit-board-list
  185. func (s *GroupIssueBoardsService) UpdateIssueBoardList(gid interface{}, board, list int, opt *UpdateGroupIssueBoardListOptions, options ...OptionFunc) ([]*BoardList, *Response, error) {
  186. group, err := parseID(gid)
  187. if err != nil {
  188. return nil, nil, err
  189. }
  190. u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
  191. url.QueryEscape(group),
  192. board,
  193. list,
  194. )
  195. req, err := s.client.NewRequest("PUT", u, opt, options)
  196. if err != nil {
  197. return nil, nil, err
  198. }
  199. var gbl []*BoardList
  200. resp, err := s.client.Do(req, gbl)
  201. if err != nil {
  202. return nil, resp, err
  203. }
  204. return gbl, resp, err
  205. }
  206. // DeleteGroupIssueBoardList soft deletes a group issue board list.
  207. // Only for admins and group owners.
  208. //
  209. // GitLab API docs:
  210. // https://docs.gitlab.com/ce/api/group_boards.html#delete-a-board-list
  211. func (s *GroupIssueBoardsService) DeleteGroupIssueBoardList(gid interface{}, board, list int, options ...OptionFunc) (*Response, error) {
  212. group, err := parseID(gid)
  213. if err != nil {
  214. return nil, err
  215. }
  216. u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
  217. url.QueryEscape(group),
  218. board,
  219. list,
  220. )
  221. req, err := s.client.NewRequest("DELETE", u, nil, options)
  222. if err != nil {
  223. return nil, err
  224. }
  225. return s.client.Do(req, nil)
  226. }