...

Source file src/github.com/xanzy/go-gitlab/group_milestones.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  	"time"
    23  )
    24  
    25  // GroupMilestonesService handles communication with the milestone related
    26  // methods of the GitLab API.
    27  //
    28  // GitLab API docs: https://docs.gitlab.com/ee/api/group_milestones.html
    29  type GroupMilestonesService struct {
    30  	client *Client
    31  }
    32  
    33  // GroupMilestone represents a GitLab milestone.
    34  //
    35  // GitLab API docs: https://docs.gitlab.com/ee/api/group_milestones.html
    36  type GroupMilestone struct {
    37  	ID          int        `json:"id"`
    38  	IID         int        `json:"iid"`
    39  	GroupID     int        `json:"group_id"`
    40  	Title       string     `json:"title"`
    41  	Description string     `json:"description"`
    42  	StartDate   *ISOTime   `json:"start_date"`
    43  	DueDate     *ISOTime   `json:"due_date"`
    44  	State       string     `json:"state"`
    45  	UpdatedAt   *time.Time `json:"updated_at"`
    46  	CreatedAt   *time.Time `json:"created_at"`
    47  	Expired     *bool      `json:"expired"`
    48  }
    49  
    50  func (m GroupMilestone) String() string {
    51  	return Stringify(m)
    52  }
    53  
    54  // ListGroupMilestonesOptions represents the available
    55  // ListGroupMilestones() options.
    56  //
    57  // GitLab API docs:
    58  // https://docs.gitlab.com/ee/api/group_milestones.html#list-group-milestones
    59  type ListGroupMilestonesOptions struct {
    60  	ListOptions
    61  	IIDs                    *[]int  `url:"iids[],omitempty" json:"iids,omitempty"`
    62  	State                   *string `url:"state,omitempty" json:"state,omitempty"`
    63  	Title                   *string `url:"title,omitempty" json:"title,omitempty"`
    64  	Search                  *string `url:"search,omitempty" json:"search,omitempty"`
    65  	IncludeParentMilestones *bool   `url:"include_parent_milestones,omitempty" json:"include_parent_milestones,omitempty"`
    66  }
    67  
    68  // ListGroupMilestones returns a list of group milestones.
    69  //
    70  // GitLab API docs:
    71  // https://docs.gitlab.com/ee/api/group_milestones.html#list-group-milestones
    72  func (s *GroupMilestonesService) ListGroupMilestones(gid interface{}, opt *ListGroupMilestonesOptions, options ...RequestOptionFunc) ([]*GroupMilestone, *Response, error) {
    73  	group, err := parseID(gid)
    74  	if err != nil {
    75  		return nil, nil, err
    76  	}
    77  	u := fmt.Sprintf("groups/%s/milestones", PathEscape(group))
    78  
    79  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
    80  	if err != nil {
    81  		return nil, nil, err
    82  	}
    83  
    84  	var m []*GroupMilestone
    85  	resp, err := s.client.Do(req, &m)
    86  	if err != nil {
    87  		return nil, resp, err
    88  	}
    89  
    90  	return m, resp, nil
    91  }
    92  
    93  // GetGroupMilestone gets a single group milestone.
    94  //
    95  // GitLab API docs:
    96  // https://docs.gitlab.com/ee/api/group_milestones.html#get-single-milestone
    97  func (s *GroupMilestonesService) GetGroupMilestone(gid interface{}, milestone int, options ...RequestOptionFunc) (*GroupMilestone, *Response, error) {
    98  	group, err := parseID(gid)
    99  	if err != nil {
   100  		return nil, nil, err
   101  	}
   102  	u := fmt.Sprintf("groups/%s/milestones/%d", PathEscape(group), milestone)
   103  
   104  	req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
   105  	if err != nil {
   106  		return nil, nil, err
   107  	}
   108  
   109  	m := new(GroupMilestone)
   110  	resp, err := s.client.Do(req, m)
   111  	if err != nil {
   112  		return nil, resp, err
   113  	}
   114  
   115  	return m, resp, nil
   116  }
   117  
   118  // CreateGroupMilestoneOptions represents the available CreateGroupMilestone() options.
   119  //
   120  // GitLab API docs:
   121  // https://docs.gitlab.com/ee/api/group_milestones.html#create-new-milestone
   122  type CreateGroupMilestoneOptions struct {
   123  	Title       *string  `url:"title,omitempty" json:"title,omitempty"`
   124  	Description *string  `url:"description,omitempty" json:"description,omitempty"`
   125  	StartDate   *ISOTime `url:"start_date,omitempty" json:"start_date,omitempty"`
   126  	DueDate     *ISOTime `url:"due_date,omitempty" json:"due_date,omitempty"`
   127  }
   128  
   129  // CreateGroupMilestone creates a new group milestone.
   130  //
   131  // GitLab API docs:
   132  // https://docs.gitlab.com/ee/api/group_milestones.html#create-new-milestone
   133  func (s *GroupMilestonesService) CreateGroupMilestone(gid interface{}, opt *CreateGroupMilestoneOptions, options ...RequestOptionFunc) (*GroupMilestone, *Response, error) {
   134  	group, err := parseID(gid)
   135  	if err != nil {
   136  		return nil, nil, err
   137  	}
   138  	u := fmt.Sprintf("groups/%s/milestones", PathEscape(group))
   139  
   140  	req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
   141  	if err != nil {
   142  		return nil, nil, err
   143  	}
   144  
   145  	m := new(GroupMilestone)
   146  	resp, err := s.client.Do(req, m)
   147  	if err != nil {
   148  		return nil, resp, err
   149  	}
   150  
   151  	return m, resp, nil
   152  }
   153  
   154  // UpdateGroupMilestoneOptions represents the available UpdateGroupMilestone() options.
   155  //
   156  // GitLab API docs:
   157  // https://docs.gitlab.com/ee/api/group_milestones.html#edit-milestone
   158  type UpdateGroupMilestoneOptions struct {
   159  	Title       *string  `url:"title,omitempty" json:"title,omitempty"`
   160  	Description *string  `url:"description,omitempty" json:"description,omitempty"`
   161  	StartDate   *ISOTime `url:"start_date,omitempty" json:"start_date,omitempty"`
   162  	DueDate     *ISOTime `url:"due_date,omitempty" json:"due_date,omitempty"`
   163  	StateEvent  *string  `url:"state_event,omitempty" json:"state_event,omitempty"`
   164  }
   165  
   166  // UpdateGroupMilestone updates an existing group milestone.
   167  //
   168  // GitLab API docs:
   169  // https://docs.gitlab.com/ee/api/group_milestones.html#edit-milestone
   170  func (s *GroupMilestonesService) UpdateGroupMilestone(gid interface{}, milestone int, opt *UpdateGroupMilestoneOptions, options ...RequestOptionFunc) (*GroupMilestone, *Response, error) {
   171  	group, err := parseID(gid)
   172  	if err != nil {
   173  		return nil, nil, err
   174  	}
   175  	u := fmt.Sprintf("groups/%s/milestones/%d", PathEscape(group), milestone)
   176  
   177  	req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
   178  	if err != nil {
   179  		return nil, nil, err
   180  	}
   181  
   182  	m := new(GroupMilestone)
   183  	resp, err := s.client.Do(req, m)
   184  	if err != nil {
   185  		return nil, resp, err
   186  	}
   187  
   188  	return m, resp, nil
   189  }
   190  
   191  // DeleteGroupMilestone deletes a specified group milestone.
   192  //
   193  // GitLab API docs:
   194  // https://docs.gitlab.com/ee/api/group_milestones.html#delete-group-milestone
   195  func (s *GroupMilestonesService) DeleteGroupMilestone(pid interface{}, milestone int, options ...RequestOptionFunc) (*Response, error) {
   196  	project, err := parseID(pid)
   197  	if err != nil {
   198  		return nil, err
   199  	}
   200  	u := fmt.Sprintf("groups/%s/milestones/%d", PathEscape(project), milestone)
   201  
   202  	req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
   203  	if err != nil {
   204  		return nil, err
   205  	}
   206  	return s.client.Do(req, nil)
   207  }
   208  
   209  // GetGroupMilestoneIssuesOptions represents the available GetGroupMilestoneIssues() options.
   210  //
   211  // GitLab API docs:
   212  // https://docs.gitlab.com/ee/api/group_milestones.html#get-all-issues-assigned-to-a-single-milestone
   213  type GetGroupMilestoneIssuesOptions ListOptions
   214  
   215  // GetGroupMilestoneIssues gets all issues assigned to a single group milestone.
   216  //
   217  // GitLab API docs:
   218  // https://docs.gitlab.com/ee/api/group_milestones.html#get-all-issues-assigned-to-a-single-milestone
   219  func (s *GroupMilestonesService) GetGroupMilestoneIssues(gid interface{}, milestone int, opt *GetGroupMilestoneIssuesOptions, options ...RequestOptionFunc) ([]*Issue, *Response, error) {
   220  	group, err := parseID(gid)
   221  	if err != nil {
   222  		return nil, nil, err
   223  	}
   224  	u := fmt.Sprintf("groups/%s/milestones/%d/issues", PathEscape(group), milestone)
   225  
   226  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   227  	if err != nil {
   228  		return nil, nil, err
   229  	}
   230  
   231  	var i []*Issue
   232  	resp, err := s.client.Do(req, &i)
   233  	if err != nil {
   234  		return nil, resp, err
   235  	}
   236  
   237  	return i, resp, nil
   238  }
   239  
   240  // GetGroupMilestoneMergeRequestsOptions represents the available
   241  // GetGroupMilestoneMergeRequests() options.
   242  //
   243  // GitLab API docs:
   244  // https://docs.gitlab.com/ee/api/group_milestones.html#get-all-merge-requests-assigned-to-a-single-milestone
   245  type GetGroupMilestoneMergeRequestsOptions ListOptions
   246  
   247  // GetGroupMilestoneMergeRequests gets all merge requests assigned to a
   248  // single group milestone.
   249  //
   250  // GitLab API docs:
   251  // https://docs.gitlab.com/ee/api/group_milestones.html#get-all-merge-requests-assigned-to-a-single-milestone
   252  func (s *GroupMilestonesService) GetGroupMilestoneMergeRequests(gid interface{}, milestone int, opt *GetGroupMilestoneMergeRequestsOptions, options ...RequestOptionFunc) ([]*MergeRequest, *Response, error) {
   253  	group, err := parseID(gid)
   254  	if err != nil {
   255  		return nil, nil, err
   256  	}
   257  	u := fmt.Sprintf("groups/%s/milestones/%d/merge_requests", PathEscape(group), milestone)
   258  
   259  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   260  	if err != nil {
   261  		return nil, nil, err
   262  	}
   263  
   264  	var mr []*MergeRequest
   265  	resp, err := s.client.Do(req, &mr)
   266  	if err != nil {
   267  		return nil, resp, err
   268  	}
   269  
   270  	return mr, resp, nil
   271  }
   272  
   273  // BurndownChartEvent reprensents a burnout chart event
   274  //
   275  // GitLab API docs:
   276  // https://docs.gitlab.com/ee/api/group_milestones.html#get-all-burndown-chart-events-for-a-single-milestone
   277  type BurndownChartEvent struct {
   278  	CreatedAt *time.Time `json:"created_at"`
   279  	Weight    *int       `json:"weight"`
   280  	Action    *string    `json:"action"`
   281  }
   282  
   283  // GetGroupMilestoneBurndownChartEventsOptions represents the available
   284  // GetGroupMilestoneBurndownChartEventsOptions() options.
   285  //
   286  // GitLab API docs:
   287  // https://docs.gitlab.com/ee/api/group_milestones.html#get-all-burndown-chart-events-for-a-single-milestone
   288  type GetGroupMilestoneBurndownChartEventsOptions ListOptions
   289  
   290  // GetGroupMilestoneBurndownChartEvents gets all merge requests assigned to a
   291  // single group milestone.
   292  //
   293  // GitLab API docs:
   294  // https://docs.gitlab.com/ee/api/group_milestones.html#get-all-burndown-chart-events-for-a-single-milestone
   295  func (s *GroupMilestonesService) GetGroupMilestoneBurndownChartEvents(gid interface{}, milestone int, opt *GetGroupMilestoneBurndownChartEventsOptions, options ...RequestOptionFunc) ([]*BurndownChartEvent, *Response, error) {
   296  	group, err := parseID(gid)
   297  	if err != nil {
   298  		return nil, nil, err
   299  	}
   300  	u := fmt.Sprintf("groups/%s/milestones/%d/burndown_events", PathEscape(group), milestone)
   301  
   302  	req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
   303  	if err != nil {
   304  		return nil, nil, err
   305  	}
   306  
   307  	var be []*BurndownChartEvent
   308  	resp, err := s.client.Do(req, &be)
   309  	if err != nil {
   310  		return nil, resp, err
   311  	}
   312  
   313  	return be, resp, nil
   314  }
   315  

View as plain text