...

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

Documentation: github.com/xanzy/go-gitlab

     1  //
     2  // Copyright 2021, 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  
    17  package gitlab
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  )
    23  
    24  // EpicIssuesService handles communication with the epic issue related methods
    25  // of the GitLab API.
    26  //
    27  // GitLab API docs: https://docs.gitlab.com/ee/api/epic_issues.html
    28  type EpicIssuesService struct {
    29  	client *Client
    30  }
    31  
    32  // EpicIssueAssignment contains both the epic and issue objects returned from
    33  // Gitlab with the assignment ID.
    34  //
    35  // GitLab API docs: https://docs.gitlab.com/ee/api/epic_issues.html
    36  type EpicIssueAssignment struct {
    37  	ID    int    `json:"id"`
    38  	Epic  *Epic  `json:"epic"`
    39  	Issue *Issue `json:"issue"`
    40  }
    41  
    42  // ListEpicIssues get a list of epic issues.
    43  //
    44  // Gitlab API docs:
    45  // https://docs.gitlab.com/ee/api/epic_issues.html#list-issues-for-an-epic
    46  func (s *EpicIssuesService) ListEpicIssues(gid interface{}, epic int, opt *ListOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
    47  	group, err := parseID(gid)
    48  	if err != nil {
    49  		return nil, nil, err
    50  	}
    51  	u := fmt.Sprintf("groups/%s/epics/%d/issues", PathEscape(group), epic)
    52  
    53  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
    54  	if err != nil {
    55  		return nil, nil, err
    56  	}
    57  
    58  	var is []*Issue
    59  	resp, err := s.client.Do(req, &is)
    60  	if err != nil {
    61  		return nil, resp, err
    62  	}
    63  
    64  	return is, resp, nil
    65  }
    66  
    67  // AssignEpicIssue assigns an existing issue to an epic.
    68  //
    69  // Gitlab API Docs:
    70  // https://docs.gitlab.com/ee/api/epic_issues.html#assign-an-issue-to-the-epic
    71  func (s *EpicIssuesService) AssignEpicIssue(gid interface{}, epic, issue int, options ...RequestOptionFunc) (*EpicIssueAssignment, *Response, error) {
    72  	group, err := parseID(gid)
    73  	if err != nil {
    74  		return nil, nil, err
    75  	}
    76  	u := fmt.Sprintf("groups/%s/epics/%d/issues/%d", PathEscape(group), epic, issue)
    77  
    78  	req, err := s.client.NewRequest(http.MethodPost, u, nil, options)
    79  	if err != nil {
    80  		return nil, nil, err
    81  	}
    82  
    83  	a := new(EpicIssueAssignment)
    84  	resp, err := s.client.Do(req, a)
    85  	if err != nil {
    86  		return nil, resp, err
    87  	}
    88  
    89  	return a, resp, nil
    90  }
    91  
    92  // RemoveEpicIssue removes an issue from an epic.
    93  //
    94  // Gitlab API Docs:
    95  // https://docs.gitlab.com/ee/api/epic_issues.html#remove-an-issue-from-the-epic
    96  func (s *EpicIssuesService) RemoveEpicIssue(gid interface{}, epic, epicIssue int, options ...RequestOptionFunc) (*EpicIssueAssignment, *Response, error) {
    97  	group, err := parseID(gid)
    98  	if err != nil {
    99  		return nil, nil, err
   100  	}
   101  	u := fmt.Sprintf("groups/%s/epics/%d/issues/%d", PathEscape(group), epic, epicIssue)
   102  
   103  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   104  	if err != nil {
   105  		return nil, nil, err
   106  	}
   107  
   108  	a := new(EpicIssueAssignment)
   109  	resp, err := s.client.Do(req, a)
   110  	if err != nil {
   111  		return nil, resp, err
   112  	}
   113  
   114  	return a, resp, nil
   115  }
   116  
   117  // UpdateEpicIsssueAssignmentOptions describes the UpdateEpicIssueAssignment()
   118  // options.
   119  //
   120  // Gitlab API Docs:
   121  // https://docs.gitlab.com/ee/api/epic_issues.html#update-epic---issue-association
   122  type UpdateEpicIsssueAssignmentOptions struct {
   123  	*ListOptions
   124  	MoveBeforeID *int `url:"move_before_id,omitempty" json:"move_before_id,omitempty"`
   125  	MoveAfterID  *int `url:"move_after_id,omitempty" json:"move_after_id,omitempty"`
   126  }
   127  
   128  // UpdateEpicIssueAssignment moves an issue before or after another issue in an
   129  // epic issue list.
   130  //
   131  // Gitlab API Docs:
   132  // https://docs.gitlab.com/ee/api/epic_issues.html#update-epic---issue-association
   133  func (s *EpicIssuesService) UpdateEpicIssueAssignment(gid interface{}, epic, epicIssue int, opt *UpdateEpicIsssueAssignmentOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
   134  	group, err := parseID(gid)
   135  	if err != nil {
   136  		return nil, nil, err
   137  	}
   138  	u := fmt.Sprintf("groups/%s/epics/%d/issues/%d", PathEscape(group), epic, epicIssue)
   139  
   140  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   141  	if err != nil {
   142  		return nil, nil, err
   143  	}
   144  
   145  	var is []*Issue
   146  	resp, err := s.client.Do(req, &is)
   147  	if err != nil {
   148  		return nil, resp, err
   149  	}
   150  
   151  	return is, resp, nil
   152  }
   153  

View as plain text