Skip to content

Commit fc4f5cd

Browse files
author
Daniel Steinke
committed
Added support for iterations and group iterations
1 parent 35322d7 commit fc4f5cd

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed

group_iterations.go

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
}

iterations.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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/iterations.html
29+
30+
type IterationsService struct {
31+
client *Client
32+
}
33+
34+
type Iteration struct {
35+
ID int `json:"id"`
36+
IID int `json:"iid"`
37+
GroupID int `json:"group_id"`
38+
Title string `json:"title"`
39+
Description string `json:"description"`
40+
State int `json:"state"`
41+
CreatedAt *time.Time `json:"created_at"`
42+
UpdatedAt *time.Time `json:"updated_at"`
43+
DueDate *ISOTime `json:"due_date"`
44+
StartDate *ISOTime `json:"start_date"`
45+
WebURL string `json:"web_url"`
46+
}
47+
48+
func (i Iteration) String() string {
49+
return Stringify(i)
50+
}
51+
52+
// ListGroupIterationsOptions contains the available
53+
// ListGroupIterations() options
54+
//
55+
// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html#list-project-iterations
56+
type ListProjectIterationsOptions struct {
57+
ListOptions
58+
State *string `url:"state,omitempty" json:"state,omitempty"`
59+
Search *string `url:"search,omitempty" json:"search,omitempty"`
60+
IncludeAncestors *bool `url:"include_ancestors,omitempty" json:"include_ancestors,omitempty"`
61+
}
62+
63+
//ListProjectIterations lists all iterations of the projects ancestor groups.
64+
//As of GitLab 13.5, there are not direct project-level iterations.
65+
66+
// GitLab API docs: https://docs.gitlab.com/ee/api/iterations.html
67+
func (i *IterationsService) ListProjectIterations(pid interface{}, opt *ListGroupProjectsOptions, options ...RequestOptionFunc) ([]*Iteration, *Response, error) {
68+
project, err := parseID(pid)
69+
if err != nil {
70+
return nil, nil, err
71+
}
72+
u := fmt.Sprintf("projects/%s/iterations", PathEscape(project))
73+
74+
req, err := i.client.NewRequest(http.MethodGet, u, opt, options)
75+
if err != nil {
76+
return nil, nil, err
77+
}
78+
79+
var it []*Iteration
80+
resp, err := i.client.Do(req, &it)
81+
if err != nil {
82+
return nil, resp, err
83+
}
84+
85+
return it, resp, err
86+
}

0 commit comments

Comments
 (0)