Commit 062bdff0 authored by François Samin's avatar François Samin Committed by Sander van Harmelen

Add support for list project forks (#305)

parent 5d0d50f4
......@@ -178,16 +178,18 @@ func (s Project) String() string {
// GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#list-projects
type ListProjectsOptions struct {
ListOptions
Archived *bool `url:"archived,omitempty" json:"archived,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
Simple *bool `url:"simple,omitempty" json:"simple,omitempty"`
Owned *bool `url:"owned,omitempty" json:"owned,omitempty"`
Membership *bool `url:"membership,omitempty" json:"membership,omitempty"`
Starred *bool `url:"starred,omitempty" json:"starred,omitempty"`
Statistics *bool `url:"statistics,omitempty" json:"statistics,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
Archived *bool `url:"archived,omitempty" json:"archived,omitempty"`
OrderBy *string `url:"order_by,omitempty" json:"order_by,omitempty"`
Sort *string `url:"sort,omitempty" json:"sort,omitempty"`
Search *string `url:"search,omitempty" json:"search,omitempty"`
Simple *bool `url:"simple,omitempty" json:"simple,omitempty"`
Owned *bool `url:"owned,omitempty" json:"owned,omitempty"`
Membership *bool `url:"membership,omitempty" json:"membership,omitempty"`
Starred *bool `url:"starred,omitempty" json:"starred,omitempty"`
Statistics *bool `url:"statistics,omitempty" json:"statistics,omitempty"`
Visibility *VisibilityValue `url:"visibility,omitempty" json:"visibility,omitempty"`
WithIssuesEnabled *bool `url:"with_issues_enabled,omitempty" json:"with_issues_enabled,omitempty"`
WithMergeRequestsEnabled *bool `url:"with_merge_requests_enabled,omitempty" json:"with_merge_requests_enabled,omitempty"`
}
// ListProjects gets a list of projects accessible by the authenticated user.
......@@ -903,3 +905,28 @@ func (s *ProjectsService) UploadFile(pid interface{}, file string, options ...Op
return uf, resp, nil
}
// ListProjectForks gets a list of project forks.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/projects.html#list-forks-of-a-project
func (s *ProjectsService) ListProjectForks(pid interface{}, opt *ListProjectsOptions, options ...OptionFunc) ([]*Project, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/forks", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt, options)
if err != nil {
return nil, nil, err
}
var forks []*Project
resp, err := s.client.Do(req, &forks)
if err != nil {
return nil, resp, err
}
return forks, resp, err
}
......@@ -233,3 +233,36 @@ func TestUploadFile(t *testing.T) {
t.Errorf("Prokects.UploadFile returned %+v, want %+v", file, want)
}
}
func TestListProjectForks(t *testing.T) {
mux, server, client := setup()
defer teardown(server)
mux.HandleFunc("/projects/", func(w http.ResponseWriter, r *http.Request) {
want := "/projects/namespace%2Fname/forks"
if !strings.HasPrefix(r.RequestURI, want) {
t.Errorf("Request url: %+v, should have prefix %s", r.RequestURI, want)
}
testMethod(t, r, "GET")
fmt.Fprint(w, `[{"id":1},{"id":2}]`)
})
opt := &ListProjectsOptions{}
opt.ListOptions = ListOptions{2, 3}
opt.Archived = Bool(true)
opt.OrderBy = String("name")
opt.Sort = String("asc")
opt.Search = String("query")
opt.Simple = Bool(true)
opt.Visibility = Visibility(PublicVisibility)
projects, _, err := client.Projects.ListProjectForks("namespace/name", opt)
if err != nil {
t.Errorf("Projects.ListProjectForks returned error: %v", err)
}
want := []*Project{{ID: 1}, {ID: 2}}
if !reflect.DeepEqual(want, projects) {
t.Errorf("Projects.ListProjects returned %+v, want %+v", projects, want)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment