Skip to content

Commit

Permalink
Cleanup the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
svanharmelen committed Feb 10, 2022
1 parent 0f81468 commit b65c13c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 55 deletions.
23 changes: 10 additions & 13 deletions group_iterations.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ import (
// of the GitLab API
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html

type GroupIterationsService struct {
client *Client
}

// GroupInteration represents a GitLab iteration.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html

type GroupIteration struct {
ID int `json:"id"`
IID int `json:"iid"`
Expand All @@ -54,22 +52,22 @@ func (i GroupIteration) String() string {
return Stringify(i)
}

// ListGroupIterationsOptions contains the available
// ListGroupIterations() options
// ListGroupIterationsOptions contains the available ListGroupIterations()
// options
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html#list-group-iterations

// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_iterations.html#list-group-iterations
type ListGroupIterationsOptions struct {
ListOptions
State *string `url:"state,omitempty" json:"state,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
IncludeAncestors *bool `url:"include_ancestors,omitempty" json:"include_ancestors,omitempty"`
}

// ListGroupIterations returns alist of group iterations.
// ListGroupIterations returns a list of group iterations.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html#list-group-iterations

// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_iterations.html#list-group-iterations
func (s *GroupIterationsService) ListGroupIterations(gid interface{}, opt *ListGroupIterationsOptions, options ...RequestOptionFunc) ([]*GroupIteration, *Response, error) {
group, err := parseID(gid)
if err != nil {
Expand All @@ -82,12 +80,11 @@ func (s *GroupIterationsService) ListGroupIterations(gid interface{}, opt *ListG
return nil, nil, err
}

var i []*GroupIteration
resp, err := s.client.Do(req, &i)
var gis []*GroupIteration
resp, err := s.client.Do(req, &gis)
if err != nil {
return nil, nil, err
}

return i, resp, err

return gis, resp, err
}
23 changes: 12 additions & 11 deletions group_iterations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ func TestListGroupIterations(t *testing.T) {
mux.HandleFunc("/api/v4/groups/5/iterations",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `[{
"id": 53,
"iid": 13,
"sequence": 1,
"group_id": 5,
"title": "Iteration II",
"description": "Ipsum Lorem ipsum",
"state": 2,
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
}
]`)
fmt.Fprintf(w, `[
{
"id": 53,
"iid": 13,
"sequence": 1,
"group_id": 5,
"title": "Iteration II",
"description": "Ipsum Lorem ipsum",
"state": 2,
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
}
]`)
})

iterations, _, err := client.GroupIterations.ListGroupIterations(5, &ListGroupIterationsOptions{})
Expand Down
35 changes: 17 additions & 18 deletions project_iterations.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ import (
"time"
)

// IterationsAPI handles communication with the iterations related methods
// of the GitLab API
// IterationsAPI handles communication with the project iterations related
// methods of the GitLab API
//
// GitLab API docs: https://docs.gitlab.com/ee/api/iterations.html

type ProjectIterationsService struct {
client *Client
}

// Iteration represents a GitLab iteration
// ProjectIteration represents a GitLab project iteration.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/iterations.html
// CAVEAT: GitLab docu currently misses `sequence` key.
type Iteration struct {
type ProjectIteration struct {
ID int `json:"id"`
IID int `json:"iid"`
Sequence int `json:"sequence"`
Expand All @@ -50,26 +48,27 @@ type Iteration struct {
WebURL string `json:"web_url"`
}

func (i Iteration) String() string {
func (i ProjectIteration) String() string {
return Stringify(i)
}

// ListGroupIterationsOptions contains the available
// ListGroupIterations() options
// ListProjectIterationsOptions contains the available ListProjectIterations()
// options
//
// GitLab API docs: https://docs.gitlab.com/ee/api/group_iterations.html#list-project-iterations
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_iterations.html#list-project-iterations
type ListProjectIterationsOptions struct {
ListOptions
State *string `url:"state,omitempty" json:"state,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
IncludeAncestors *bool `url:"include_ancestors,omitempty" json:"include_ancestors,omitempty"`
}

//ListProjectIterations lists all iterations of the projects ancestor groups.
//As of GitLab 13.5, there are no direct project-level iterations.

// GitLab API docs: https://docs.gitlab.com/ee/api/iterations.html
func (i *ProjectIterationsService) ListProjectIterations(pid interface{}, opt *ListProjectIterationsOptions, options ...RequestOptionFunc) ([]*Iteration, *Response, error) {
// ListProjectIterations returns a list of projects iterations.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/group_iterations.html#list-project-iterations
func (i *ProjectIterationsService) ListProjectIterations(pid interface{}, opt *ListProjectIterationsOptions, options ...RequestOptionFunc) ([]*ProjectIteration, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
Expand All @@ -81,11 +80,11 @@ func (i *ProjectIterationsService) ListProjectIterations(pid interface{}, opt *L
return nil, nil, err
}

var it []*Iteration
resp, err := i.client.Do(req, &it)
var pis []*ProjectIteration
resp, err := i.client.Do(req, &pis)
if err != nil {
return nil, resp, err
}

return it, resp, err
return pis, resp, err
}
25 changes: 13 additions & 12 deletions project_iterations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ func TestListProjectIterations(t *testing.T) {
mux.HandleFunc("/api/v4/projects/42/iterations",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprintf(w, `[{
"id": 53,
"iid": 13,
"sequence": 1,
"group_id": 5,
"title": "Iteration II",
"description": "Ipsum Lorem ipsum",
"state": 2,
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
}
]`)
fmt.Fprintf(w, `[
{
"id": 53,
"iid": 13,
"sequence": 1,
"group_id": 5,
"title": "Iteration II",
"description": "Ipsum Lorem ipsum",
"state": 2,
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
}
]`)
})

iterations, _, err := client.ProjectIterations.ListProjectIterations(42, &ListProjectIterationsOptions{})
if err != nil {
t.Errorf("GroupIterations.ListGroupIterations returned error: %v", err)
}

want := []*Iteration{{
want := []*ProjectIteration{{
ID: 53,
IID: 13,
Sequence: 1,
Expand Down
2 changes: 1 addition & 1 deletion testdata/list_group_iterations.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"start_date": "2020-02-14",
"web_url": "http://gitlab.example.com/groups/my-group/-/iterations/13"
}
]
]

0 comments on commit b65c13c

Please sign in to comment.