|
| 1 | +// |
| 2 | +// Copyright 2022, stonebyte |
| 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 | +// IterationsAPI handles communication with the iterations related methods |
| 26 | +// of the GitLab API |
| 27 | +// |
| 28 | +// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html |
| 29 | + |
| 30 | +type GroupIterationsService struct { |
| 31 | + client *Client |
| 32 | +} |
| 33 | + |
| 34 | +// GroupInteration represents a GitLab iteration. |
| 35 | +// |
| 36 | +// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html |
| 37 | + |
| 38 | +type GroupIteration struct { |
| 39 | + ID int `json:"id"` |
| 40 | + IID int `json:"iid"` |
| 41 | + GroupID int `json:"group_id"` |
| 42 | + Title string `json:"title"` |
| 43 | + Description string `json:"description"` |
| 44 | + State int `json:"state"` |
| 45 | + CreatedAt *time.Time `json:"created_at"` |
| 46 | + UpdatedAt *time.Time `json:"updated_at"` |
| 47 | + DueDate *ISOTime `json:"due_date"` |
| 48 | + StartDate *ISOTime `json:"start_date"` |
| 49 | + WebURL string `json:"web_url"` |
| 50 | +} |
| 51 | + |
| 52 | +func (i GroupIteration) String() string { |
| 53 | + return Stringify(i) |
| 54 | +} |
| 55 | + |
| 56 | +// ListGroupIterationsOptions contains the available |
| 57 | +// ListGroupIterations() options |
| 58 | +// |
| 59 | +// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html#list-group-iterations |
| 60 | + |
| 61 | +type ListGroupIterationsOptions struct { |
| 62 | + ListOptions |
| 63 | + State *string `url:"state,omitempty" json:"state,omitempty"` |
| 64 | + Search *string `url:"search,omitempty" json:"search,omitempty"` |
| 65 | + IncludeAncestors *bool `url:"include_ancestors,omitempty" json:"include_ancestors,omitempty"` |
| 66 | +} |
| 67 | + |
| 68 | +// ListGroupIterations returns alist of group iterations. |
| 69 | +// |
| 70 | +// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html#list-group-iterations |
| 71 | + |
| 72 | +func (s *GroupIterationsService) ListGroupIterations(gid interface{}, opt *ListGroupIterationsOptions, options ...RequestOptionFunc) ([]*GroupIteration, *Response, error) { |
| 73 | + group, err := parseID(gid) |
| 74 | + if err != nil { |
| 75 | + return nil, nil, err |
| 76 | + } |
| 77 | + u := fmt.Sprintf("groups/%s/iterations", 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 i []*GroupIteration |
| 85 | + resp, err := s.client.Do(req, &i) |
| 86 | + if err != nil { |
| 87 | + return nil, nil, err |
| 88 | + } |
| 89 | + |
| 90 | + return i, resp, err |
| 91 | + |
| 92 | +} |
0 commit comments