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
a5ba2c86
Commit
a5ba2c86
authored
Oct 31, 2017
by
dongmx
Committed by
Sander van Harmelen
Oct 31, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
# 204 add support for GET /users/:user_id/projects (#234)
parent
e6f4b9d4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
+50
-0
projects.go
projects.go
+20
-0
projects_test.go
projects_test.go
+30
-0
No files found.
projects.go
View file @
a5ba2c86
...
...
@@ -197,6 +197,26 @@ func (s *ProjectsService) ListProjects(opt *ListProjectsOptions, options ...Opti
return
p
,
resp
,
err
}
// ListUserProjects gets a list of projects for the given user.
//
// GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#list-user-projects
func
(
s
*
ProjectsService
)
ListUserProjects
(
user
int
,
opt
*
ListProjectsOptions
,
options
...
OptionFunc
)
([]
*
Project
,
*
Response
,
error
)
{
u
:=
fmt
.
Sprintf
(
"users/%d/projects"
,
user
)
req
,
err
:=
s
.
client
.
NewRequest
(
"GET"
,
u
,
opt
,
options
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
var
p
[]
*
Project
resp
,
err
:=
s
.
client
.
Do
(
req
,
&
p
)
if
err
!=
nil
{
return
nil
,
resp
,
err
}
return
p
,
resp
,
err
}
// GetProject gets a specific project, identified by project ID or
// NAMESPACE/PROJECT_NAME, which is owned by the authenticated user.
//
...
...
projects_test.go
View file @
a5ba2c86
...
...
@@ -40,6 +40,36 @@ func TestListProjects(t *testing.T) {
}
}
func
TestListUserProjects
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
mux
.
HandleFunc
(
"/users/1/projects"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
testMethod
(
t
,
r
,
"GET"
)
fmt
.
Fprint
(
w
,
`[{"id":1},{"id":2}]`
)
})
opt
:=
&
ListProjectsOptions
{
ListOptions
:
ListOptions
{
2
,
3
},
Archived
:
Bool
(
true
),
OrderBy
:
String
(
"name"
),
Sort
:
String
(
"asc"
),
Search
:
String
(
"query"
),
Simple
:
Bool
(
true
),
Visibility
:
Visibility
(
PublicVisibility
),
}
projects
,
_
,
err
:=
client
.
Projects
.
ListUserProjects
(
1
,
opt
)
if
err
!=
nil
{
t
.
Errorf
(
"Projects.ListUserProjects returned error: %v"
,
err
)
}
want
:=
[]
*
Project
{{
ID
:
1
},
{
ID
:
2
}}
if
!
reflect
.
DeepEqual
(
want
,
projects
)
{
t
.
Errorf
(
"Projects.ListUserProjects returned %+v, want %+v"
,
projects
,
want
)
}
}
func
TestListOwnedProjects
(
t
*
testing
.
T
)
{
mux
,
server
,
client
:=
setup
()
defer
teardown
(
server
)
...
...
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