...

Source file src/github.com/xanzy/go-gitlab/group_boards.go

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, 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  
    17  package gitlab
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  )
    23  
    24  // GroupIssueBoardsService handles communication with the group issue board
    25  // related methods of the GitLab API.
    26  //
    27  // GitLab API docs:
    28  // https://docs.gitlab.com/ee/api/group_boards.html
    29  type GroupIssueBoardsService struct {
    30  	client *Client
    31  }
    32  
    33  // GroupIssueBoard represents a GitLab group issue board.
    34  //
    35  // GitLab API docs:
    36  // https://docs.gitlab.com/ee/api/group_boards.html
    37  type GroupIssueBoard struct {
    38  	ID        int           `json:"id"`
    39  	Name      string        `json:"name"`
    40  	Group     *Group        `json:"group"`
    41  	Milestone *Milestone    `json:"milestone"`
    42  	Labels    []*GroupLabel `json:"labels"`
    43  	Lists     []*BoardList  `json:"lists"`
    44  }
    45  
    46  func (b GroupIssueBoard) String() string {
    47  	return Stringify(b)
    48  }
    49  
    50  // ListGroupIssueBoardsOptions represents the available
    51  // ListGroupIssueBoards() options.
    52  //
    53  // GitLab API docs:
    54  // https://docs.gitlab.com/ee/api/group_boards.html#list-all-group-issue-boards-in-a-group
    55  type ListGroupIssueBoardsOptions ListOptions
    56  
    57  // ListGroupIssueBoards gets a list of all issue boards in a group.
    58  //
    59  // GitLab API docs:
    60  // https://docs.gitlab.com/ee/api/group_boards.html#list-all-group-issue-boards-in-a-group
    61  func (s *GroupIssueBoardsService) ListGroupIssueBoards(gid interface{}, opt *ListGroupIssueBoardsOptions, options ...RequestOptionFunc) ([]*GroupIssueBoard, *Response, error) {
    62  	group, err := parseID(gid)
    63  	if err != nil {
    64  		return nil, nil, err
    65  	}
    66  	u := fmt.Sprintf("groups/%s/boards", PathEscape(group))
    67  
    68  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
    69  	if err != nil {
    70  		return nil, nil, err
    71  	}
    72  
    73  	var gs []*GroupIssueBoard
    74  	resp, err := s.client.Do(req, &gs)
    75  	if err != nil {
    76  		return nil, resp, err
    77  	}
    78  
    79  	return gs, resp, nil
    80  }
    81  
    82  // CreateGroupIssueBoardOptions represents the available
    83  // CreateGroupIssueBoard() options.
    84  //
    85  // GitLab API docs:
    86  // https://docs.gitlab.com/ee/api/group_boards.html#create-a-group-issue-board
    87  type CreateGroupIssueBoardOptions struct {
    88  	Name *string `url:"name" json:"name"`
    89  }
    90  
    91  // CreateGroupIssueBoard creates a new issue board.
    92  //
    93  // GitLab API docs:
    94  // https://docs.gitlab.com/ee/api/group_boards.html#create-a-group-issue-board
    95  func (s *GroupIssueBoardsService) CreateGroupIssueBoard(gid interface{}, opt *CreateGroupIssueBoardOptions, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) {
    96  	group, err := parseID(gid)
    97  	if err != nil {
    98  		return nil, nil, err
    99  	}
   100  	u := fmt.Sprintf("groups/%s/boards", PathEscape(group))
   101  
   102  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   103  	if err != nil {
   104  		return nil, nil, err
   105  	}
   106  
   107  	gib := new(GroupIssueBoard)
   108  	resp, err := s.client.Do(req, gib)
   109  	if err != nil {
   110  		return nil, resp, err
   111  	}
   112  
   113  	return gib, resp, nil
   114  }
   115  
   116  // GetGroupIssueBoard gets a single issue board of a group.
   117  //
   118  // GitLab API docs:
   119  // https://docs.gitlab.com/ee/api/group_boards.html#single-group-issue-board
   120  func (s *GroupIssueBoardsService) GetGroupIssueBoard(gid interface{}, board int, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) {
   121  	group, err := parseID(gid)
   122  	if err != nil {
   123  		return nil, nil, err
   124  	}
   125  	u := fmt.Sprintf("groups/%s/boards/%d", PathEscape(group), board)
   126  
   127  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
   128  	if err != nil {
   129  		return nil, nil, err
   130  	}
   131  
   132  	gib := new(GroupIssueBoard)
   133  	resp, err := s.client.Do(req, gib)
   134  	if err != nil {
   135  		return nil, resp, err
   136  	}
   137  
   138  	return gib, resp, nil
   139  }
   140  
   141  // UpdateGroupIssueBoardOptions represents a group issue board.
   142  //
   143  // GitLab API docs:
   144  // https://docs.gitlab.com/ee/api/group_boards.html#update-a-group-issue-board
   145  type UpdateGroupIssueBoardOptions struct {
   146  	Name        *string       `url:"name,omitempty" json:"name,omitempty"`
   147  	AssigneeID  *int          `url:"assignee_id,omitempty" json:"assignee_id,omitempty"`
   148  	MilestoneID *int          `url:"milestone_id,omitempty" json:"milestone_id,omitempty"`
   149  	Labels      *LabelOptions `url:"labels,omitempty" json:"labels,omitempty"`
   150  	Weight      *int          `url:"weight,omitempty" json:"weight,omitempty"`
   151  }
   152  
   153  // UpdateIssueBoard updates a single issue board of a group.
   154  //
   155  // GitLab API docs:
   156  // https://docs.gitlab.com/ee/api/group_boards.html#update-a-group-issue-board
   157  func (s *GroupIssueBoardsService) UpdateIssueBoard(gid interface{}, board int, opt *UpdateGroupIssueBoardOptions, options ...RequestOptionFunc) (*GroupIssueBoard, *Response, error) {
   158  	group, err := parseID(gid)
   159  	if err != nil {
   160  		return nil, nil, err
   161  	}
   162  	u := fmt.Sprintf("groups/%s/boards/%d", PathEscape(group), board)
   163  
   164  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   165  	if err != nil {
   166  		return nil, nil, err
   167  	}
   168  
   169  	gib := new(GroupIssueBoard)
   170  	resp, err := s.client.Do(req, gib)
   171  	if err != nil {
   172  		return nil, resp, err
   173  	}
   174  
   175  	return gib, resp, nil
   176  }
   177  
   178  // DeleteIssueBoard delete a single issue board of a group.
   179  //
   180  // GitLab API docs:
   181  // https://docs.gitlab.com/ee/api/group_boards.html#delete-a-group-issue-board
   182  func (s *GroupIssueBoardsService) DeleteIssueBoard(gid interface{}, board int, options ...RequestOptionFunc) (*Response, error) {
   183  	group, err := parseID(gid)
   184  	if err != nil {
   185  		return nil, err
   186  	}
   187  	u := fmt.Sprintf("groups/%s/boards/%d", PathEscape(group), board)
   188  
   189  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   190  	if err != nil {
   191  		return nil, err
   192  	}
   193  
   194  	return s.client.Do(req, nil)
   195  }
   196  
   197  // ListGroupIssueBoardListsOptions represents the available
   198  // ListGroupIssueBoardLists() options.
   199  //
   200  // GitLab API docs:
   201  // https://docs.gitlab.com/ee/api/group_boards.html#list-group-issue-board-lists
   202  type ListGroupIssueBoardListsOptions ListOptions
   203  
   204  // ListGroupIssueBoardLists gets a list of the issue board's lists. Does not include
   205  // backlog and closed lists.
   206  //
   207  // GitLab API docs: https://docs.gitlab.com/ee/api/group_boards.html#list-group-issue-board-lists
   208  func (s *GroupIssueBoardsService) ListGroupIssueBoardLists(gid interface{}, board int, opt *ListGroupIssueBoardListsOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) {
   209  	group, err := parseID(gid)
   210  	if err != nil {
   211  		return nil, nil, err
   212  	}
   213  	u := fmt.Sprintf("groups/%s/boards/%d/lists", PathEscape(group), board)
   214  
   215  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   216  	if err != nil {
   217  		return nil, nil, err
   218  	}
   219  
   220  	var gbl []*BoardList
   221  	resp, err := s.client.Do(req, &gbl)
   222  	if err != nil {
   223  		return nil, resp, err
   224  	}
   225  
   226  	return gbl, resp, nil
   227  }
   228  
   229  // GetGroupIssueBoardList gets a single issue board list.
   230  //
   231  // GitLab API docs:
   232  // https://docs.gitlab.com/ee/api/group_boards.html#single-group-issue-board-list
   233  func (s *GroupIssueBoardsService) GetGroupIssueBoardList(gid interface{}, board, list int, options ...RequestOptionFunc) (*BoardList, *Response, error) {
   234  	group, err := parseID(gid)
   235  	if err != nil {
   236  		return nil, nil, err
   237  	}
   238  	u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
   239  		PathEscape(group),
   240  		board,
   241  		list,
   242  	)
   243  
   244  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
   245  	if err != nil {
   246  		return nil, nil, err
   247  	}
   248  
   249  	gbl := new(BoardList)
   250  	resp, err := s.client.Do(req, gbl)
   251  	if err != nil {
   252  		return nil, resp, err
   253  	}
   254  
   255  	return gbl, resp, nil
   256  }
   257  
   258  // CreateGroupIssueBoardListOptions represents the available
   259  // CreateGroupIssueBoardList() options.
   260  //
   261  // GitLab API docs:
   262  // https://docs.gitlab.com/ee/api/group_boards.html#new-group-issue-board-list
   263  type CreateGroupIssueBoardListOptions struct {
   264  	LabelID *int `url:"label_id" json:"label_id"`
   265  }
   266  
   267  // CreateGroupIssueBoardList creates a new issue board list.
   268  //
   269  // GitLab API docs:
   270  // https://docs.gitlab.com/ee/api/group_boards.html#new-group-issue-board-list
   271  func (s *GroupIssueBoardsService) CreateGroupIssueBoardList(gid interface{}, board int, opt *CreateGroupIssueBoardListOptions, options ...RequestOptionFunc) (*BoardList, *Response, error) {
   272  	group, err := parseID(gid)
   273  	if err != nil {
   274  		return nil, nil, err
   275  	}
   276  	u := fmt.Sprintf("groups/%s/boards/%d/lists", PathEscape(group), board)
   277  
   278  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   279  	if err != nil {
   280  		return nil, nil, err
   281  	}
   282  
   283  	gbl := new(BoardList)
   284  	resp, err := s.client.Do(req, gbl)
   285  	if err != nil {
   286  		return nil, resp, err
   287  	}
   288  
   289  	return gbl, resp, nil
   290  }
   291  
   292  // UpdateGroupIssueBoardListOptions represents the available
   293  // UpdateGroupIssueBoardList() options.
   294  //
   295  // GitLab API docs:
   296  // https://docs.gitlab.com/ee/api/group_boards.html#edit-group-issue-board-list
   297  type UpdateGroupIssueBoardListOptions struct {
   298  	Position *int `url:"position" json:"position"`
   299  }
   300  
   301  // UpdateIssueBoardList updates the position of an existing
   302  // group issue board list.
   303  //
   304  // GitLab API docs:
   305  // https://docs.gitlab.com/ee/api/group_boards.html#edit-group-issue-board-list
   306  func (s *GroupIssueBoardsService) UpdateIssueBoardList(gid interface{}, board, list int, opt *UpdateGroupIssueBoardListOptions, options ...RequestOptionFunc) ([]*BoardList, *Response, error) {
   307  	group, err := parseID(gid)
   308  	if err != nil {
   309  		return nil, nil, err
   310  	}
   311  	u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
   312  		PathEscape(group),
   313  		board,
   314  		list,
   315  	)
   316  
   317  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   318  	if err != nil {
   319  		return nil, nil, err
   320  	}
   321  
   322  	var gbl []*BoardList
   323  	resp, err := s.client.Do(req, &gbl)
   324  	if err != nil {
   325  		return nil, resp, err
   326  	}
   327  
   328  	return gbl, resp, nil
   329  }
   330  
   331  // DeleteGroupIssueBoardList soft deletes a group issue board list.
   332  // Only for admins and group owners.
   333  //
   334  // GitLab API docs:
   335  // https://docs.gitlab.com/ee/api/group_boards.html#delete-a-group-issue-board-list
   336  func (s *GroupIssueBoardsService) DeleteGroupIssueBoardList(gid interface{}, board, list int, options ...RequestOptionFunc) (*Response, error) {
   337  	group, err := parseID(gid)
   338  	if err != nil {
   339  		return nil, err
   340  	}
   341  	u := fmt.Sprintf("groups/%s/boards/%d/lists/%d",
   342  		PathEscape(group),
   343  		board,
   344  		list,
   345  	)
   346  
   347  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   348  	if err != nil {
   349  		return nil, err
   350  	}
   351  
   352  	return s.client.Do(req, nil)
   353  }
   354  

View as plain text