Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit 72fb745

Browse files
authored
Merge pull request #1353 from stonebyte/feature/iterations
Add support for iterations
2 parents b347d31 + b65c13c commit 72fb745

6 files changed

+298
-0
lines changed

gitlab.go

+4
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type Client struct {
132132
GroupCluster *GroupClustersService
133133
GroupImportExport *GroupImportExportService
134134
GroupIssueBoards *GroupIssueBoardsService
135+
GroupIterations *GroupIterationsService
135136
GroupLabels *GroupLabelsService
136137
GroupMembers *GroupMembersService
137138
GroupMilestones *GroupMilestonesService
@@ -168,6 +169,7 @@ type Client struct {
168169
ProjectAccessTokens *ProjectAccessTokensService
169170
ProjectCluster *ProjectClustersService
170171
ProjectImportExport *ProjectImportExportService
172+
ProjectIterations *ProjectIterationsService
171173
ProjectMembers *ProjectMembersService
172174
ProjectMirrors *ProjectMirrorService
173175
ProjectSnippets *ProjectSnippetsService
@@ -327,6 +329,7 @@ func newClient(options ...ClientOptionFunc) (*Client, error) {
327329
c.GroupCluster = &GroupClustersService{client: c}
328330
c.GroupImportExport = &GroupImportExportService{client: c}
329331
c.GroupIssueBoards = &GroupIssueBoardsService{client: c}
332+
c.GroupIterations = &GroupIterationsService{client: c}
330333
c.GroupLabels = &GroupLabelsService{client: c}
331334
c.GroupMembers = &GroupMembersService{client: c}
332335
c.GroupMilestones = &GroupMilestonesService{client: c}
@@ -363,6 +366,7 @@ func newClient(options ...ClientOptionFunc) (*Client, error) {
363366
c.ProjectAccessTokens = &ProjectAccessTokensService{client: c}
364367
c.ProjectCluster = &ProjectClustersService{client: c}
365368
c.ProjectImportExport = &ProjectImportExportService{client: c}
369+
c.ProjectIterations = &ProjectIterationsService{client: c}
366370
c.ProjectMembers = &ProjectMembersService{client: c}
367371
c.ProjectMirrors = &ProjectMirrorService{client: c}
368372
c.ProjectSnippets = &ProjectSnippetsService{client: c}

group_iterations.go

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

group_iterations_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package gitlab
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"reflect"
7+
"testing"
8+
)
9+
10+
func TestListGroupIterations(t *testing.T) {
11+
mux, server, client := setup(t)
12+
defer teardown(server)
13+
14+
mux.HandleFunc("/api/v4/groups/5/iterations",
15+
func(w http.ResponseWriter, r *http.Request) {
16+
testMethod(t, r, http.MethodGet)
17+
fmt.Fprintf(w, `[
18+
{
19+
"id": 53,
20+
"iid": 13,
21+
"sequence": 1,
22+
"group_id": 5,
23+
"title": "Iteration II",
24+
"description": "Ipsum Lorem ipsum",
25+
"state": 2,
26+
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
27+
}
28+
]`)
29+
})
30+
31+
iterations, _, err := client.GroupIterations.ListGroupIterations(5, &ListGroupIterationsOptions{})
32+
if err != nil {
33+
t.Errorf("GroupIterations.ListGroupIterations returned error: %v", err)
34+
}
35+
36+
want := []*GroupIteration{{
37+
ID: 53,
38+
IID: 13,
39+
Sequence: 1,
40+
GroupID: 5,
41+
Title: "Iteration II",
42+
Description: "Ipsum Lorem ipsum",
43+
State: 2,
44+
WebURL: "http://gitlab.example.com/groups/my-group/-/iterations/13",
45+
}}
46+
if !reflect.DeepEqual(want, iterations) {
47+
t.Errorf("GroupIterations.ListGroupIterations returned %+v, want %+v", iterations, want)
48+
}
49+
}

project_iterations.go

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

project_iterations_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package gitlab
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"reflect"
7+
"testing"
8+
)
9+
10+
func TestListProjectIterations(t *testing.T) {
11+
mux, server, client := setup(t)
12+
defer teardown(server)
13+
14+
mux.HandleFunc("/api/v4/projects/42/iterations",
15+
func(w http.ResponseWriter, r *http.Request) {
16+
testMethod(t, r, http.MethodGet)
17+
fmt.Fprintf(w, `[
18+
{
19+
"id": 53,
20+
"iid": 13,
21+
"sequence": 1,
22+
"group_id": 5,
23+
"title": "Iteration II",
24+
"description": "Ipsum Lorem ipsum",
25+
"state": 2,
26+
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
27+
}
28+
]`)
29+
})
30+
31+
iterations, _, err := client.ProjectIterations.ListProjectIterations(42, &ListProjectIterationsOptions{})
32+
if err != nil {
33+
t.Errorf("GroupIterations.ListGroupIterations returned error: %v", err)
34+
}
35+
36+
want := []*ProjectIteration{{
37+
ID: 53,
38+
IID: 13,
39+
Sequence: 1,
40+
GroupID: 5,
41+
Title: "Iteration II",
42+
Description: "Ipsum Lorem ipsum",
43+
State: 2,
44+
WebURL: "http://gitlab.example.com/groups/my-group/-/iterations/13",
45+
}}
46+
if !reflect.DeepEqual(want, iterations) {
47+
t.Errorf("ProjectIterations.ListProjectIterations returned %+v, want %+v", iterations, want)
48+
}
49+
}

testdata/list_group_iterations.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"id": 53,
4+
"iid": 13,
5+
"sequence": 1,
6+
"group_id": 5,
7+
"title": "Iteration II",
8+
"description": "Ipsum Lorem ipsum",
9+
"state": 2,
10+
"created_at": "2020-01-27T05:07:12.573Z",
11+
"updated_at": "2020-01-27T05:07:12.573Z",
12+
"due_date": "2020-02-01",
13+
"start_date": "2020-02-14",
14+
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
15+
}
16+
]

0 commit comments

Comments
 (0)