Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
go-gitlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
go-gitlab
Commits
062bdff0
Commit
062bdff0
authored
Jan 26, 2018
by
François Samin
Committed by
Sander van Harmelen
Jan 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for list project forks (#305)
parent
5d0d50f4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
10 deletions
+70
-10
projects.go
projects.go
+37
-10
projects_test.go
projects_test.go
+33
-0
No files found.
projects.go
View file @
062bdff0
...
@@ -178,16 +178,18 @@ func (s Project) String() string {
...
@@ -178,16 +178,18 @@ func (s Project) String() string {
// GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#list-projects
// GitLab API docs: https://docs.gitlab.com/ce/api/projects.html#list-projects
type
ListProjectsOptions
struct
{
type
ListProjectsOptions
struct
{
ListOptions
ListOptions
Archived
*
bool
`url:"archived,omitempty" json:"archived,omitempty"`
Archived
*
bool
`url:"archived,omitempty" json:"archived,omitempty"`
OrderBy
*
string
`url:"order_by,omitempty" json:"order_by,omitempty"`
OrderBy
*
string
`url:"order_by,omitempty" json:"order_by,omitempty"`
Sort
*
string
`url:"sort,omitempty" json:"sort,omitempty"`
Sort
*
string
`url:"sort,omitempty" json:"sort,omitempty"`
Search
*
string
`url:"search,omitempty" json:"search,omitempty"`
Search
*
string
`url:"search,omitempty" json:"search,omitempty"`
Simple
*
bool
`url:"simple,omitempty" json:"simple,omitempty"`
Simple
*
bool
`url:"simple,omitempty" json:"simple,omitempty"`
Owned
*
bool
`url:"owned,omitempty" json:"owned,omitempty"`
Owned
*
bool
`url:"owned,omitempty" json:"owned,omitempty"`
Membership
*
bool
`url:"membership,omitempty" json:"membership,omitempty"`
Membership
*
bool
`url:"membership,omitempty" json:"membership,omitempty"`
Starred
*
bool
`url:"starred,omitempty" json:"starred,omitempty"`
Starred
*
bool
`url:"starred,omitempty" json:"starred,omitempty"`
Statistics
*
bool
`url:"statistics,omitempty" json:"statistics,omitempty"`
Statistics
*
bool
`url:"statistics,omitempty" json:"statistics,omitempty"`
Visibility
*
VisibilityValue
`url:"visibility,omitempty" json:"visibility,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.
// 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
...
@@ -903,3 +905,28 @@ func (s *ProjectsService) UploadFile(pid interface{}, file string, options ...Op
return
uf
,
resp
,
nil
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
}
projects_test.go
View file @
062bdff0
...
@@ -233,3 +233,36 @@ func TestUploadFile(t *testing.T) {
...
@@ -233,3 +233,36 @@ func TestUploadFile(t *testing.T) {
t
.
Errorf
(
"Prokects.UploadFile returned %+v, want %+v"
,
file
,
want
)
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
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment