Commit 7ef3a0e1 authored by Sander van Harmelen's avatar Sander van Harmelen

Fix a small issue with the `ListUserProjects`

A user can be either an ID or a name.
parent a5ba2c86
......@@ -16,29 +16,29 @@ incompatible changes that were needed to fully support the V4 Gitlab API.
This API client package covers **100%** of the existing GitLab API calls! So this
includes all calls to the following services:
- [x] Users
- [x] Session
- [x] Projects (including setting Webhooks)
- [x] Project Snippets
- [x] Services
- [x] Repositories
- [x] Repository Files
- [x] Commits
- [x] Branches
- [x] Merge Requests
- [x] Commits
- [x] Deploy Keys
- [x] Environments
- [x] Groups
- [x] Issues
- [x] Labels
- [x] Merge Requests
- [x] Milestones
- [x] Notes (comments)
- [x] Deploy Keys
- [x] System Hooks
- [x] Groups
- [x] Namespaces
- [x] Settings
- [x] Notes (comments)
- [x] Pipelines
- [x] Project Snippets
- [x] Projects (including setting Webhooks)
- [x] Repositories
- [x] Repository Files
- [x] Services
- [x] Session
- [x] Settings
- [x] System Hooks
- [x] Users
- [x] Version
- [x] Wikis
- [x] Environments
## Usage
......
......@@ -551,16 +551,12 @@ type OptionFunc func(*http.Request) error
// WithSudo takes either a username or user ID and sets the SUDO request header
func WithSudo(uid interface{}) OptionFunc {
return func(req *http.Request) error {
switch uid := uid.(type) {
case int:
req.Header.Set("SUDO", strconv.Itoa(uid))
return nil
case string:
req.Header.Set("SUDO", uid)
return nil
default:
return fmt.Errorf("uid must be either a username or user ID")
user, err := parseID(uid)
if err != nil {
return err
}
req.Header.Set("SUDO", user)
return nil
}
}
......
......@@ -199,10 +199,15 @@ func (s *ProjectsService) ListProjects(opt *ListProjectsOptions, options ...Opti
// 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) {
// GitLab API docs:
// https://docs.gitlab.com/ce/api/projects.html#list-user-projects
func (s *ProjectsService) ListUserProjects(uid interface{}, opt *ListProjectsOptions, options ...OptionFunc) ([]*Project, *Response, error) {
user, err := parseID(uid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("users/%s/projects", user)
u := fmt.Sprintf("users/%d/projects", user)
req, err := s.client.NewRequest("GET", u, opt, options)
if err != nil {
return nil, nil, err
......
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