boards.go 7.1 KB

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