Commit 0b200094 authored by Sander van Harmelen's avatar Sander van Harmelen Committed by GitHub

Add sudo support for all calls (#132)

https://docs.gitlab.com/ce/api/README.html#sudo
parent 055ffe6f
......@@ -47,14 +47,14 @@ func (b Branch) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/branches.html#list-repository-branches
func (s *BranchesService) ListBranches(pid interface{}) ([]*Branch, *Response, error) {
func (s *BranchesService) ListBranches(pid interface{}, sudoFunc ...SudoFunc) ([]*Branch, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -72,14 +72,14 @@ func (s *BranchesService) ListBranches(pid interface{}) ([]*Branch, *Response, e
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/branches.html#get-single-repository-branch
func (s *BranchesService) GetBranch(pid interface{}, branch string) (*Branch, *Response, error) {
func (s *BranchesService) GetBranch(pid interface{}, branch string, sudoFunc ...SudoFunc) (*Branch, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches/%s", url.QueryEscape(project), branch)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -99,14 +99,14 @@ func (s *BranchesService) GetBranch(pid interface{}, branch string) (*Branch, *R
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/branches.html#protect-repository-branch
func (s *BranchesService) ProtectBranch(pid interface{}, branch string) (*Branch, *Response, error) {
func (s *BranchesService) ProtectBranch(pid interface{}, branch string, sudoFunc ...SudoFunc) (*Branch, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches/%s/protect", url.QueryEscape(project), branch)
req, err := s.client.NewRequest("PUT", u, nil)
req, err := s.client.NewRequest("PUT", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -126,14 +126,14 @@ func (s *BranchesService) ProtectBranch(pid interface{}, branch string) (*Branch
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/branches.html#unprotect-repository-branch
func (s *BranchesService) UnprotectBranch(pid interface{}, branch string) (*Branch, *Response, error) {
func (s *BranchesService) UnprotectBranch(pid interface{}, branch string, sudoFunc ...SudoFunc) (*Branch, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches/%s/unprotect", url.QueryEscape(project), branch)
req, err := s.client.NewRequest("PUT", u, nil)
req, err := s.client.NewRequest("PUT", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -160,14 +160,14 @@ type CreateBranchOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/branches.html#create-repository-branch
func (s *BranchesService) CreateBranch(pid interface{}, opt *CreateBranchOptions) (*Branch, *Response, error) {
func (s *BranchesService) CreateBranch(pid interface{}, opt *CreateBranchOptions, sudoFunc ...SudoFunc) (*Branch, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -185,14 +185,14 @@ func (s *BranchesService) CreateBranch(pid interface{}, opt *CreateBranchOptions
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/branches.html#delete-repository-branch
func (s *BranchesService) DeleteBranch(pid interface{}, branch string) (*Response, error) {
func (s *BranchesService) DeleteBranch(pid interface{}, branch string, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/repository/branches/%s", url.QueryEscape(project), branch)
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......
......@@ -29,14 +29,14 @@ func (v BuildVariable) String() string {
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#list-project-variables
func (s *BuildVariablesService) ListBuildVariables(pid interface{}) ([]*BuildVariable, *Response, error) {
func (s *BuildVariablesService) ListBuildVariables(pid interface{}, sudoFunc ...SudoFunc) ([]*BuildVariable, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/variables", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -54,14 +54,14 @@ func (s *BuildVariablesService) ListBuildVariables(pid interface{}) ([]*BuildVar
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#show-variable-details
func (s *BuildVariablesService) GetBuildVariable(pid interface{}, key string) (*BuildVariable, *Response, error) {
func (s *BuildVariablesService) GetBuildVariable(pid interface{}, key string, sudoFunc ...SudoFunc) (*BuildVariable, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/variables/%s", url.QueryEscape(project), key)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -79,14 +79,14 @@ func (s *BuildVariablesService) GetBuildVariable(pid interface{}, key string) (*
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#create-variable
func (s *BuildVariablesService) CreateBuildVariable(pid interface{}, key, value string) (*BuildVariable, *Response, error) {
func (s *BuildVariablesService) CreateBuildVariable(pid interface{}, key, value string, sudoFunc ...SudoFunc) (*BuildVariable, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/variables", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, BuildVariable{key, value})
req, err := s.client.NewRequest("POST", u, BuildVariable{key, value}, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -105,14 +105,14 @@ func (s *BuildVariablesService) CreateBuildVariable(pid interface{}, key, value
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#update-variable
func (s *BuildVariablesService) UpdateBuildVariable(pid interface{}, key, value string) (*BuildVariable, *Response, error) {
func (s *BuildVariablesService) UpdateBuildVariable(pid interface{}, key, value string, sudoFunc ...SudoFunc) (*BuildVariable, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/variables/%s", url.QueryEscape(project), key)
req, err := s.client.NewRequest("PUT", u, BuildVariable{key, value})
req, err := s.client.NewRequest("PUT", u, BuildVariable{key, value}, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -130,14 +130,14 @@ func (s *BuildVariablesService) UpdateBuildVariable(pid interface{}, key, value
//
// Gitlab API Docs:
// https://docs.gitlab.com/ce/api/build_variables.html#remove-variable
func (s *BuildVariablesService) RemoveBuildVariable(pid interface{}, key string) (*Response, error) {
func (s *BuildVariablesService) RemoveBuildVariable(pid interface{}, key string, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/variables/%s", url.QueryEscape(project), key)
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......
......@@ -73,14 +73,14 @@ type Build struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#list-project-builds
func (s *BuildsService) ListProjectBuilds(pid interface{}, opts *ListBuildsOptions) ([]Build, *Response, error) {
func (s *BuildsService) ListProjectBuilds(pid interface{}, opts *ListBuildsOptions, sudoFunc ...SudoFunc) ([]Build, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opts)
req, err := s.client.NewRequest("GET", u, opts, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -99,14 +99,14 @@ func (s *BuildsService) ListProjectBuilds(pid interface{}, opts *ListBuildsOptio
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#list-commit-builds
func (s *BuildsService) ListCommitBuilds(pid interface{}, sha string, opts *ListBuildsOptions) ([]Build, *Response, error) {
func (s *BuildsService) ListCommitBuilds(pid interface{}, sha string, opts *ListBuildsOptions, sudoFunc ...SudoFunc) ([]Build, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/builds", project, sha)
req, err := s.client.NewRequest("GET", u, opts)
req, err := s.client.NewRequest("GET", u, opts, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -124,14 +124,14 @@ func (s *BuildsService) ListCommitBuilds(pid interface{}, sha string, opts *List
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#get-a-single-build
func (s *BuildsService) GetBuild(pid interface{}, buildID int) (*Build, *Response, error) {
func (s *BuildsService) GetBuild(pid interface{}, buildID int, sudoFunc ...SudoFunc) (*Build, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds/%d", project, buildID)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -149,14 +149,14 @@ func (s *BuildsService) GetBuild(pid interface{}, buildID int) (*Build, *Respons
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#get-build-artifacts
func (s *BuildsService) GetBuildArtifacts(pid interface{}, buildID int) (io.Reader, *Response, error) {
func (s *BuildsService) GetBuildArtifacts(pid interface{}, buildID int, sudoFunc ...SudoFunc) (io.Reader, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds/%d/artifacts", project, buildID)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -175,14 +175,14 @@ func (s *BuildsService) GetBuildArtifacts(pid interface{}, buildID int) (io.Read
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#download-the-artifacts-file
func (s *BuildsService) DownloadArtifactsFile(pid interface{}, refName string, job string) (io.Reader, *Response, error) {
func (s *BuildsService) DownloadArtifactsFile(pid interface{}, refName string, job string, sudoFunc ...SudoFunc) (io.Reader, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds/artifacts/%s/download?job=%s", project, refName, job)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -200,14 +200,14 @@ func (s *BuildsService) DownloadArtifactsFile(pid interface{}, refName string, j
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#get-a-trace-file
func (s *BuildsService) GetTraceFile(pid interface{}, buildID int) (io.Reader, *Response, error) {
func (s *BuildsService) GetTraceFile(pid interface{}, buildID int, sudoFunc ...SudoFunc) (io.Reader, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds/%d/trace", project, buildID)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -225,14 +225,14 @@ func (s *BuildsService) GetTraceFile(pid interface{}, buildID int) (io.Reader, *
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#cancel-a-build
func (s *BuildsService) CancelBuild(pid interface{}, buildID int) (*Build, *Response, error) {
func (s *BuildsService) CancelBuild(pid interface{}, buildID int, sudoFunc ...SudoFunc) (*Build, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds/%d/cancel", project, buildID)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -250,14 +250,14 @@ func (s *BuildsService) CancelBuild(pid interface{}, buildID int) (*Build, *Resp
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#retry-a-build
func (s *BuildsService) RetryBuild(pid interface{}, buildID int) (*Build, *Response, error) {
func (s *BuildsService) RetryBuild(pid interface{}, buildID int, sudoFunc ...SudoFunc) (*Build, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds/%d/retry", project, buildID)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -276,14 +276,14 @@ func (s *BuildsService) RetryBuild(pid interface{}, buildID int) (*Build, *Respo
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#erase-a-build
func (s *BuildsService) EraseBuild(pid interface{}, buildID int) (*Build, *Response, error) {
func (s *BuildsService) EraseBuild(pid interface{}, buildID int, sudoFunc ...SudoFunc) (*Build, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds/%d/erase", project, buildID)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -302,14 +302,14 @@ func (s *BuildsService) EraseBuild(pid interface{}, buildID int) (*Build, *Respo
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#keep-artifacts
func (s *BuildsService) KeepArtifacts(pid interface{}, buildID int) (*Build, *Response, error) {
func (s *BuildsService) KeepArtifacts(pid interface{}, buildID int, sudoFunc ...SudoFunc) (*Build, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds/%d/artifacts/keep", project, buildID)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -327,14 +327,14 @@ func (s *BuildsService) KeepArtifacts(pid interface{}, buildID int) (*Build, *Re
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/builds.html#play-a-build
func (s *BuildsService) PlayBuild(pid interface{}, buildID int) (*Build, *Response, error) {
func (s *BuildsService) PlayBuild(pid interface{}, buildID int, sudoFunc ...SudoFunc) (*Build, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/builds/%d/play", project, buildID)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -63,14 +63,14 @@ type ListCommitsOptions struct {
// ListCommits gets a list of repository commits in a project.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#list-commits
func (s *CommitsService) ListCommits(pid interface{}, opt *ListCommitsOptions) ([]*Commit, *Response, error) {
func (s *CommitsService) ListCommits(pid interface{}, opt *ListCommitsOptions, sudoFunc ...SudoFunc) ([]*Commit, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -88,14 +88,14 @@ func (s *CommitsService) ListCommits(pid interface{}, opt *ListCommitsOptions) (
// branch or tag.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#get-a-single-commit
func (s *CommitsService) GetCommit(pid interface{}, sha string) (*Commit, *Response, error) {
func (s *CommitsService) GetCommit(pid interface{}, sha string, sudoFunc ...SudoFunc) (*Commit, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s", url.QueryEscape(project), sha)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -131,14 +131,14 @@ func (d Diff) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/commits.html#get-the-diff-of-a-commit
func (s *CommitsService) GetCommitDiff(pid interface{}, sha string) ([]*Diff, *Response, error) {
func (s *CommitsService) GetCommitDiff(pid interface{}, sha string, sudoFunc ...SudoFunc) ([]*Diff, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/diff", url.QueryEscape(project), sha)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -182,14 +182,14 @@ func (c CommitComment) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/commits.html#get-the-comments-of-a-commit
func (s *CommitsService) GetCommitComments(pid interface{}, sha string) ([]*CommitComment, *Response, error) {
func (s *CommitsService) GetCommitComments(pid interface{}, sha string, sudoFunc ...SudoFunc) ([]*CommitComment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/comments", url.QueryEscape(project), sha)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -221,14 +221,14 @@ type PostCommitCommentOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/commits.html#post-comment-to-commit
func (s *CommitsService) PostCommitComment(pid interface{}, sha string, opt *PostCommitCommentOptions) (*CommitComment, *Response, error) {
func (s *CommitsService) PostCommitComment(pid interface{}, sha string, opt *PostCommitCommentOptions, sudoFunc ...SudoFunc) (*CommitComment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/comments", url.QueryEscape(project), sha)
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -272,14 +272,14 @@ type CommitStatus struct {
// GetCommitStatuses gets the statuses of a commit in a project.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#get-the-status-of-a-commit
func (s *CommitsService) GetCommitStatuses(pid interface{}, sha string, opt *GetCommitStatusesOptions) ([]*CommitStatus, *Response, error) {
func (s *CommitsService) GetCommitStatuses(pid interface{}, sha string, opt *GetCommitStatusesOptions, sudoFunc ...SudoFunc) ([]*CommitStatus, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/commits/%s/statuses", url.QueryEscape(project), sha)
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -320,14 +320,14 @@ const (
// SetCommitStatus sets the status of a commit in a project.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/commits.html#post-the-status-to-commit
func (s *CommitsService) SetCommitStatus(pid interface{}, sha string, opt *SetCommitStatusOptions) (*CommitStatus, *Response, error) {
func (s *CommitsService) SetCommitStatus(pid interface{}, sha string, opt *SetCommitStatusOptions, sudoFunc ...SudoFunc) (*CommitStatus, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/statuses/%s", url.QueryEscape(project), sha)
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -46,14 +46,14 @@ func (k DeployKey) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/deploy_keys.html#list-deploy-keys
func (s *DeployKeysService) ListDeployKeys(pid interface{}) ([]*DeployKey, *Response, error) {
func (s *DeployKeysService) ListDeployKeys(pid interface{}, sudoFunc ...SudoFunc) ([]*DeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/keys", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -71,14 +71,14 @@ func (s *DeployKeysService) ListDeployKeys(pid interface{}) ([]*DeployKey, *Resp
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/deploy_keys.html#single-deploy-key
func (s *DeployKeysService) GetDeployKey(pid interface{}, deployKey int) (*DeployKey, *Response, error) {
func (s *DeployKeysService) GetDeployKey(pid interface{}, deployKey int, sudoFunc ...SudoFunc) (*DeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/keys/%d", url.QueryEscape(project), deployKey)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -107,14 +107,14 @@ type AddDeployKeyOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/deploy_keys.html#add-deploy-key
func (s *DeployKeysService) AddDeployKey(pid interface{}, opt *AddDeployKeyOptions) (*DeployKey, *Response, error) {
func (s *DeployKeysService) AddDeployKey(pid interface{}, opt *AddDeployKeyOptions, sudoFunc ...SudoFunc) (*DeployKey, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/keys", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -132,14 +132,14 @@ func (s *DeployKeysService) AddDeployKey(pid interface{}, opt *AddDeployKeyOptio
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/deploy_keys.html#delete-deploy-key
func (s *DeployKeysService) DeleteDeployKey(pid interface{}, deployKey int) (*Response, error) {
func (s *DeployKeysService) DeleteDeployKey(pid interface{}, deployKey int, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/keys/%d", url.QueryEscape(project), deployKey)
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......
......@@ -66,22 +66,61 @@ const (
OwnerPermission AccessLevelValue = 50
)
// NotificationLevelValue represents a notification level within Gitlab.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/
// NotificationLevelValue represents a notification level.
type NotificationLevelValue int
// List of available notification levels
//
// GitLab API docs: https://docs.gitlab.com/ce/api/
// String implements the fmt.Stringer interface.
func (l NotificationLevelValue) String() string {
return notificationLevelNames[l]
}
// UnmarshalJSON implements the json.Unmarshaler interface.
func (l *NotificationLevelValue) UnmarshalJSON(data []byte) error {
var raw interface{}
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
switch raw := raw.(type) {
case float64:
*l = NotificationLevelValue(raw)
case string:
*l = notificationLevelTypes[raw]
default:
return fmt.Errorf("json: cannot unmarshal %T into Go value of type %T", raw, *l)
}
return nil
}
// List of valid notification levels.
const (
DisabledNotifications NotificationLevelValue = iota
ParticipatingNotifications
WatchNotifications
GlobalNotifications
MentionNotifications
DisabledNotificationLevel NotificationLevelValue = iota
ParticipatingNotificationLevel
WatchNotificationLevel
GlobalNotificationLevel
MentionNotificationLevel
CustomNotificationLevel
)
var notificationLevelNames = [...]string{
"disabled",
"participating",
"watch",
"global",
"mention",
"custom",
}
var notificationLevelTypes = map[string]NotificationLevelValue{
"disabled": DisabledNotificationLevel,
"participating": ParticipatingNotificationLevel,
"watch": WatchNotificationLevel,
"global": GlobalNotificationLevel,
"mention": MentionNotificationLevel,
"custom": CustomNotificationLevel,
}
// VisibilityLevelValue represents a visibility level within GitLab.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/
......@@ -231,7 +270,7 @@ func (c *Client) SetBaseURL(urlStr string) error {
// Relative URL paths should always be specified without a preceding slash. If
// specified, the value pointed to by body is JSON encoded and included as the
// request body.
func (c *Client) NewRequest(method, path string, opt interface{}) (*http.Request, error) {
func (c *Client) NewRequest(method, path string, opt interface{}, sudoFunc []SudoFunc) (*http.Request, error) {
u := *c.baseURL
// Set the encoded opaque data
u.Opaque = c.baseURL.Path + path
......@@ -254,6 +293,12 @@ func (c *Client) NewRequest(method, path string, opt interface{}) (*http.Request
Host: u.Host,
}
for _, fn := range sudoFunc {
if err := fn(req); err != nil {
return nil, err
}
}
if method == "POST" || method == "PUT" {
bodyBytes, err := json.Marshal(opt)
if err != nil {
......@@ -396,23 +441,6 @@ func parseID(id interface{}) (string, error) {
}
// An ErrorResponse reports one or more errors caused by an API request.
// Format:
// {
// "message": {
// "<property-name>": [
// "<error-message>",
// "<error-message>",
// ...
// ],
// "<embed-entity>": {
// "<property-name>": [
// "<error-message>",
// "<error-message>",
// ...
// ],
// }
// }
// }
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/README.html#data-validation-and-error-reporting
......@@ -448,6 +476,24 @@ func CheckResponse(r *http.Response) error {
return errorResponse
}
// Format:
// {
// "message": {
// "<property-name>": [
// "<error-message>",
// "<error-message>",
// ...
// ],
// "<embed-entity>": {
// "<property-name>": [
// "<error-message>",
// "<error-message>",
// ...
// ],
// }
// },
// "error": "<error-message>"
// }
func parseError(raw interface{}) string {
switch raw := raw.(type) {
case string:
......@@ -473,6 +519,28 @@ func parseError(raw interface{}) string {
}
}
// SudoFunc can be passed to all API requests to make the API call as if you were
// another user, provided your private token is from an administrator account.
//
// GitLab docs: https://docs.gitlab.com/ce/api/README.html#sudo
type SudoFunc func(*http.Request) error
// SudoUser takes either a username or user ID and sets the SUDO request header
func SudoUser(uid interface{}) SudoFunc {
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")
}
}
}
// Bool is a helper routine that allocates a new bool value
// to store v and returns a pointer to it.
func Bool(v bool) *bool {
......@@ -506,6 +574,14 @@ func AccessLevel(v AccessLevelValue) *AccessLevelValue {
return p
}
// NotificationLevel is a helper routine that allocates a new NotificationLevelValue
// to store v and returns a pointer to it.
func NotificationLevel(v NotificationLevelValue) *NotificationLevelValue {
p := new(NotificationLevelValue)
*p = v
return p
}
// VisibilityLevel is a helper routine that allocates a new VisibilityLevelValue
// to store v and returns a pointer to it.
func VisibilityLevel(v VisibilityLevelValue) *VisibilityLevelValue {
......
......@@ -92,7 +92,7 @@ func TestNewClient(t *testing.T) {
}
func TestCheckResponse(t *testing.T) {
req, err := NewClient(nil, "").NewRequest("GET", "test", nil)
req, err := NewClient(nil, "").NewRequest("GET", "test", nil, nil)
if err != nil {
t.Fatalf("Failed to create request: %v", err)
}
......
......@@ -52,8 +52,8 @@ type ListGroupsOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/groups.html#list-project-groups
func (s *GroupsService) ListGroups(opt *ListGroupsOptions) ([]*Group, *Response, error) {
req, err := s.client.NewRequest("GET", "groups", opt)
func (s *GroupsService) ListGroups(opt *ListGroupsOptions, sudoFunc ...SudoFunc) ([]*Group, *Response, error) {
req, err := s.client.NewRequest("GET", "groups", opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -70,14 +70,14 @@ func (s *GroupsService) ListGroups(opt *ListGroupsOptions) ([]*Group, *Response,
// GetGroup gets all details of a group.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#details-of-a-group
func (s *GroupsService) GetGroup(gid interface{}) (*Group, *Response, error) {
func (s *GroupsService) GetGroup(gid interface{}, sudoFunc ...SudoFunc) (*Group, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s", group)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -105,8 +105,8 @@ type CreateGroupOptions struct {
// create groups.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#new-group
func (s *GroupsService) CreateGroup(opt *CreateGroupOptions) (*Group, *Response, error) {
req, err := s.client.NewRequest("POST", "groups", opt)
func (s *GroupsService) CreateGroup(opt *CreateGroupOptions, sudoFunc ...SudoFunc) (*Group, *Response, error) {
req, err := s.client.NewRequest("POST", "groups", opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -125,14 +125,14 @@ func (s *GroupsService) CreateGroup(opt *CreateGroupOptions) (*Group, *Response,
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/groups.html#transfer-project-to-group
func (s *GroupsService) TransferGroup(gid interface{}, project int) (*Group, *Response, error) {
func (s *GroupsService) TransferGroup(gid interface{}, project int, sudoFunc ...SudoFunc) (*Group, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/projects/%d", group, project)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -149,14 +149,14 @@ func (s *GroupsService) TransferGroup(gid interface{}, project int) (*Group, *Re
// DeleteGroup removes group with all projects inside.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#remove-group
func (s *GroupsService) DeleteGroup(gid interface{}) (*Response, error) {
func (s *GroupsService) DeleteGroup(gid interface{}, sudoFunc ...SudoFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s", group)
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......@@ -167,13 +167,13 @@ func (s *GroupsService) DeleteGroup(gid interface{}) (*Response, error) {
// SearchGroup get all groups that match your string in their name or path.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/groups.html#search-for-group
func (s *GroupsService) SearchGroup(query string) ([]*Group, *Response, error) {
func (s *GroupsService) SearchGroup(query string, sudoFunc ...SudoFunc) ([]*Group, *Response, error) {
var q struct {
Search string `url:"search,omitempty" json:"search,omitempty"`
}
q.Search = query
req, err := s.client.NewRequest("GET", "groups", &q)
req, err := s.client.NewRequest("GET", "groups", &q, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -214,14 +214,14 @@ type ListGroupMembersOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/groups.html#list-group-members
func (s *GroupsService) ListGroupMembers(gid interface{}, opt *ListGroupMembersOptions) ([]*GroupMember, *Response, error) {
func (s *GroupsService) ListGroupMembers(gid interface{}, opt *ListGroupMembersOptions, sudoFunc ...SudoFunc) ([]*GroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/members", group)
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -248,14 +248,14 @@ type ListGroupProjectsOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/groups.html#list-a-group-s-projects
func (s *GroupsService) ListGroupProjects(gid interface{}, opt *ListGroupProjectsOptions) ([]*Project, *Response, error) {
func (s *GroupsService) ListGroupProjects(gid interface{}, opt *ListGroupProjectsOptions, sudoFunc ...SudoFunc) ([]*Project, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/projects", group)
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -281,14 +281,14 @@ type AddGroupMemberOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/groups.html#list-group-members
func (s *GroupsService) AddGroupMember(gid interface{}, opt *AddGroupMemberOptions) (*GroupMember, *Response, error) {
func (s *GroupsService) AddGroupMember(gid interface{}, opt *AddGroupMemberOptions, sudoFunc ...SudoFunc) (*GroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/members", group)
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -315,14 +315,14 @@ type UpdateGroupMemberOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/groups.html#list-group-members
func (s *GroupsService) UpdateGroupMember(gid interface{}, user int, opt *UpdateGroupMemberOptions) (*GroupMember, *Response, error) {
func (s *GroupsService) UpdateGroupMember(gid interface{}, user int, opt *UpdateGroupMemberOptions, sudoFunc ...SudoFunc) (*GroupMember, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/members/%d", group, user)
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -340,14 +340,14 @@ func (s *GroupsService) UpdateGroupMember(gid interface{}, user int, opt *Update
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/groups.html#remove-user-from-user-team
func (s *GroupsService) RemoveGroupMember(gid interface{}, user int) (*Response, error) {
func (s *GroupsService) RemoveGroupMember(gid interface{}, user int, sudoFunc ...SudoFunc) (*Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("groups/%s/members/%d", group, user)
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......
......@@ -96,8 +96,8 @@ type ListIssuesOptions struct {
// takes pagination parameters page and per_page to restrict the list of issues.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-issues
func (s *IssuesService) ListIssues(opt *ListIssuesOptions) ([]*Issue, *Response, error) {
req, err := s.client.NewRequest("GET", "issues", opt)
func (s *IssuesService) ListIssues(opt *ListIssuesOptions, sudoFunc ...SudoFunc) ([]*Issue, *Response, error) {
req, err := s.client.NewRequest("GET", "issues", opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -128,14 +128,14 @@ type ListProjectIssuesOptions struct {
// pagination parameters page and per_page to return the list of project issues.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#list-project-issues
func (s *IssuesService) ListProjectIssues(pid interface{}, opt *ListProjectIssuesOptions) ([]*Issue, *Response, error) {
func (s *IssuesService) ListProjectIssues(pid interface{}, opt *ListProjectIssuesOptions, sudoFunc ...SudoFunc) ([]*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -152,14 +152,14 @@ func (s *IssuesService) ListProjectIssues(pid interface{}, opt *ListProjectIssue
// GetIssue gets a single project issue.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#single-issues
func (s *IssuesService) GetIssue(pid interface{}, issue int) (*Issue, *Response, error) {
func (s *IssuesService) GetIssue(pid interface{}, issue int, sudoFunc ...SudoFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -187,14 +187,14 @@ type CreateIssueOptions struct {
// CreateIssue creates a new project issue.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#new-issues
func (s *IssuesService) CreateIssue(pid interface{}, opt *CreateIssueOptions) (*Issue, *Response, error) {
func (s *IssuesService) CreateIssue(pid interface{}, opt *CreateIssueOptions, sudoFunc ...SudoFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -224,14 +224,14 @@ type UpdateIssueOptions struct {
// to mark an issue as closed.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#edit-issues
func (s *IssuesService) UpdateIssue(pid interface{}, issue int, opt *UpdateIssueOptions) (*Issue, *Response, error) {
func (s *IssuesService) UpdateIssue(pid interface{}, issue int, opt *UpdateIssueOptions, sudoFunc ...SudoFunc) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -248,14 +248,14 @@ func (s *IssuesService) UpdateIssue(pid interface{}, issue int, opt *UpdateIssue
// DeleteIssue deletes a single project issue.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/issues.html#delete-an-issue
func (s *IssuesService) DeleteIssue(pid interface{}, issue int) (*Response, error) {
func (s *IssuesService) DeleteIssue(pid interface{}, issue int, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......
......@@ -48,14 +48,14 @@ func (l Label) String() string {
// ListLabels gets all labels for given project.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/labels.html#list-labels
func (s *LabelsService) ListLabels(pid interface{}) ([]*Label, *Response, error) {
func (s *LabelsService) ListLabels(pid interface{}, sudoFunc ...SudoFunc) ([]*Label, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/labels", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -82,14 +82,14 @@ type CreateLabelOptions struct {
// color.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/labels.html#create-a-new-label
func (s *LabelsService) CreateLabel(pid interface{}, opt *CreateLabelOptions) (*Label, *Response, error) {
func (s *LabelsService) CreateLabel(pid interface{}, opt *CreateLabelOptions, sudoFunc ...SudoFunc) (*Label, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/labels", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -113,14 +113,14 @@ type DeleteLabelOptions struct {
// DeleteLabel deletes a label given by its name.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/labels.html#delete-a-label
func (s *LabelsService) DeleteLabel(pid interface{}, opt *DeleteLabelOptions) (*Response, error) {
func (s *LabelsService) DeleteLabel(pid interface{}, opt *DeleteLabelOptions, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/labels", url.QueryEscape(project))
req, err := s.client.NewRequest("DELETE", u, opt)
req, err := s.client.NewRequest("DELETE", u, opt, sudoFunc)
if err != nil {
return nil, err
}
......@@ -142,14 +142,14 @@ type UpdateLabelOptions struct {
// one parameter is required, to update the label.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/labels.html#edit-an-existing-label
func (s *LabelsService) UpdateLabel(pid interface{}, opt *UpdateLabelOptions) (*Label, *Response, error) {
func (s *LabelsService) UpdateLabel(pid interface{}, opt *UpdateLabelOptions, sudoFunc ...SudoFunc) (*Label, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/labels", url.QueryEscape(project))
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -118,14 +118,14 @@ type ListMergeRequestsOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#list-merge-requests
func (s *MergeRequestsService) ListMergeRequests(pid interface{}, opt *ListMergeRequestsOptions) ([]*MergeRequest, *Response, error) {
func (s *MergeRequestsService) ListMergeRequests(pid interface{}, opt *ListMergeRequestsOptions, sudoFunc ...SudoFunc) ([]*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -143,14 +143,14 @@ func (s *MergeRequestsService) ListMergeRequests(pid interface{}, opt *ListMerge
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#get-single-mr
func (s *MergeRequestsService) GetMergeRequest(pid interface{}, mergeRequest int) (*MergeRequest, *Response, error) {
func (s *MergeRequestsService) GetMergeRequest(pid interface{}, mergeRequest int, sudoFunc ...SudoFunc) (*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -168,14 +168,14 @@ func (s *MergeRequestsService) GetMergeRequest(pid interface{}, mergeRequest int
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#get-single-mr-commits
func (s *MergeRequestsService) GetMergeRequestCommits(pid interface{}, mergeRequest int) ([]*Commit, *Response, error) {
func (s *MergeRequestsService) GetMergeRequestCommits(pid interface{}, mergeRequest int, sudoFunc ...SudoFunc) ([]*Commit, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d/commits", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -194,14 +194,14 @@ func (s *MergeRequestsService) GetMergeRequestCommits(pid interface{}, mergeRequ
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#get-single-mr-changes
func (s *MergeRequestsService) GetMergeRequestChanges(pid interface{}, mergeRequest int) (*MergeRequest, *Response, error) {
func (s *MergeRequestsService) GetMergeRequestChanges(pid interface{}, mergeRequest int, sudoFunc ...SudoFunc) (*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d/changes", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -233,14 +233,14 @@ type CreateMergeRequestOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#create-mr
func (s *MergeRequestsService) CreateMergeRequest(pid interface{}, opt *CreateMergeRequestOptions) (*MergeRequest, *Response, error) {
func (s *MergeRequestsService) CreateMergeRequest(pid interface{}, opt *CreateMergeRequestOptions, sudoFunc ...SudoFunc) (*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -271,14 +271,14 @@ type UpdateMergeRequestOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#update-mr
func (s *MergeRequestsService) UpdateMergeRequest(pid interface{}, mergeRequest int, opt *UpdateMergeRequestOptions) (*MergeRequest, *Response, error) {
func (s *MergeRequestsService) UpdateMergeRequest(pid interface{}, mergeRequest int, opt *UpdateMergeRequestOptions, sudoFunc ...SudoFunc) (*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -311,14 +311,14 @@ type AcceptMergeRequestOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#accept-mr
func (s *MergeRequestsService) AcceptMergeRequest(pid interface{}, mergeRequest int, opt *AcceptMergeRequestOptions) (*MergeRequest, *Response, error) {
func (s *MergeRequestsService) AcceptMergeRequest(pid interface{}, mergeRequest int, opt *AcceptMergeRequestOptions, sudoFunc ...SudoFunc) (*MergeRequest, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d/merge", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -331,91 +331,3 @@ func (s *MergeRequestsService) AcceptMergeRequest(pid interface{}, mergeRequest
return m, resp, err
}
// MergeRequestComment represents a GitLab merge request comment.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/merge_requests.html
type MergeRequestComment struct {
Note string `json:"note"`
Author struct {
ID int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Name string `json:"name"`
State string `json:"state"`
CreatedAt *time.Time `json:"created_at"`
} `json:"author"`
}
func (m MergeRequestComment) String() string {
return Stringify(m)
}
// GetMergeRequestCommentsOptions represents the available GetMergeRequestComments()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#get-the-comments-on-a-mr
type GetMergeRequestCommentsOptions struct {
ListOptions
}
// GetMergeRequestComments gets all the comments associated with a merge
// request.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/merge_requests.html#get-the-comments-on-a-mr
func (s *MergeRequestsService) GetMergeRequestComments(pid interface{}, mergeRequest int, opt *GetMergeRequestCommentsOptions) ([]*MergeRequestComment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_request/%d/comments", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("GET", u, opt)
if err != nil {
return nil, nil, err
}
var c []*MergeRequestComment
resp, err := s.client.Do(req, &c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// PostMergeRequestCommentOptions represents the available
// PostMergeRequestComment() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/commits.html#post-comment-to-mr
type PostMergeRequestCommentOptions struct {
Note *string `url:"note,omitempty" json:"note,omitempty"`
}
// PostMergeRequestComment dds a comment to a merge request.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/commits.html#post-comment-to-mr
func (s *MergeRequestsService) PostMergeRequestComment(pid interface{}, mergeRequest int, opt *PostMergeRequestCommentOptions) (*MergeRequestComment, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_request/%d/comments", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("POST", u, opt)
if err != nil {
return nil, nil, err
}
c := new(MergeRequestComment)
resp, err := s.client.Do(req, c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
......@@ -63,14 +63,14 @@ type ListMilestonesOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/milestones.html#list-project-milestones
func (s *MilestonesService) ListMilestones(pid interface{}, opt *ListMilestonesOptions) ([]*Milestone, *Response, error) {
func (s *MilestonesService) ListMilestones(pid interface{}, opt *ListMilestonesOptions, sudoFunc ...SudoFunc) ([]*Milestone, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/milestones", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -88,14 +88,14 @@ func (s *MilestonesService) ListMilestones(pid interface{}, opt *ListMilestonesO
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/milestones.html#get-single-milestone
func (s *MilestonesService) GetMilestone(pid interface{}, milestone int) (*Milestone, *Response, error) {
func (s *MilestonesService) GetMilestone(pid interface{}, milestone int, sudoFunc ...SudoFunc) (*Milestone, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/milestones/%d", url.QueryEscape(project), milestone)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -124,14 +124,14 @@ type CreateMilestoneOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/milestones.html#create-new-milestone
func (s *MilestonesService) CreateMilestone(pid interface{}, opt *CreateMilestoneOptions) (*Milestone, *Response, error) {
func (s *MilestonesService) CreateMilestone(pid interface{}, opt *CreateMilestoneOptions, sudoFunc ...SudoFunc) (*Milestone, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/milestones", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -161,14 +161,14 @@ type UpdateMilestoneOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/milestones.html#edit-milestone
func (s *MilestonesService) UpdateMilestone(pid interface{}, milestone int, opt *UpdateMilestoneOptions) (*Milestone, *Response, error) {
func (s *MilestonesService) UpdateMilestone(pid interface{}, milestone int, opt *UpdateMilestoneOptions, sudoFunc ...SudoFunc) (*Milestone, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/milestones/%d", url.QueryEscape(project), milestone)
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -194,14 +194,14 @@ type GetMilestoneIssuesOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/milestones.html#get-all-issues-assigned-to-a-single-milestone
func (s *MilestonesService) GetMilestoneIssues(pid interface{}, milestone int, opt *GetMilestoneIssuesOptions) ([]*Issue, *Response, error) {
func (s *MilestonesService) GetMilestoneIssues(pid interface{}, milestone int, opt *GetMilestoneIssuesOptions, sudoFunc ...SudoFunc) ([]*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/milestones/%d/issues", url.QueryEscape(project), milestone)
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -48,8 +48,8 @@ type ListNamespacesOptions struct {
// ListNamespaces gets a list of projects accessible by the authenticated user.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/namespaces.html#list-namespaces
func (s *NamespacesService) ListNamespaces(opt *ListNamespacesOptions) ([]*Namespace, *Response, error) {
req, err := s.client.NewRequest("GET", "namespaces", opt)
func (s *NamespacesService) ListNamespaces(opt *ListNamespacesOptions, sudoFunc ...SudoFunc) ([]*Namespace, *Response, error) {
req, err := s.client.NewRequest("GET", "namespaces", opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -68,13 +68,13 @@ func (s *NamespacesService) ListNamespaces(opt *ListNamespacesOptions) ([]*Names
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/namespaces.html#search-for-namespace
func (s *NamespacesService) SearchNamespace(query string) ([]*Namespace, *Response, error) {
func (s *NamespacesService) SearchNamespace(query string, sudoFunc ...SudoFunc) ([]*Namespace, *Response, error) {
var q struct {
Search string `url:"search,omitempty" json:"search,omitempty"`
}
q.Search = query
req, err := s.client.NewRequest("GET", "namespaces", &q)
req, err := s.client.NewRequest("GET", "namespaces", &q, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -68,14 +68,14 @@ type ListIssueNotesOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notes.html#list-project-issue-notes
func (s *NotesService) ListIssueNotes(pid interface{}, issue int, opt *ListIssueNotesOptions) ([]*Note, *Response, error) {
func (s *NotesService) ListIssueNotes(pid interface{}, issue int, opt *ListIssueNotesOptions, sudoFunc ...SudoFunc) ([]*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/notes", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -93,14 +93,14 @@ func (s *NotesService) ListIssueNotes(pid interface{}, issue int, opt *ListIssue
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notes.html#get-single-issue-note
func (s *NotesService) GetIssueNote(pid interface{}, issue int, note int) (*Note, *Response, error) {
func (s *NotesService) GetIssueNote(pid interface{}, issue int, note int, sudoFunc ...SudoFunc) (*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", url.QueryEscape(project), issue, note)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -127,14 +127,14 @@ type CreateIssueNoteOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notes.html#create-new-issue-note
func (s *NotesService) CreateIssueNote(pid interface{}, issue int, opt *CreateIssueNoteOptions) (*Note, *Response, error) {
func (s *NotesService) CreateIssueNote(pid interface{}, issue int, opt *CreateIssueNoteOptions, sudoFunc ...SudoFunc) (*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/notes", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -160,14 +160,14 @@ type UpdateIssueNoteOptions struct {
// UpdateIssueNote modifies existing note of an issue.
//
// https://docs.gitlab.com/ce/api/notes.html#modify-existing-issue-note
func (s *NotesService) UpdateIssueNote(pid interface{}, issue int, note int, opt *UpdateIssueNoteOptions) (*Note, *Response, error) {
func (s *NotesService) UpdateIssueNote(pid interface{}, issue int, note int, opt *UpdateIssueNoteOptions, sudoFunc ...SudoFunc) (*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/notes/%d", url.QueryEscape(project), issue, note)
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -186,14 +186,14 @@ func (s *NotesService) UpdateIssueNote(pid interface{}, issue int, note int, opt
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notes.html#list-all-snippet-notes
func (s *NotesService) ListSnippetNotes(pid interface{}, snippet int) ([]*Note, *Response, error) {
func (s *NotesService) ListSnippetNotes(pid interface{}, snippet int, sudoFunc ...SudoFunc) ([]*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/snippets/%d/notes", url.QueryEscape(project), snippet)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -211,14 +211,14 @@ func (s *NotesService) ListSnippetNotes(pid interface{}, snippet int) ([]*Note,
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notes.html#get-single-snippet-note
func (s *NotesService) GetSnippetNote(pid interface{}, snippet int, note int) (*Note, *Response, error) {
func (s *NotesService) GetSnippetNote(pid interface{}, snippet int, note int, sudoFunc ...SudoFunc) (*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", url.QueryEscape(project), snippet, note)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -246,14 +246,14 @@ type CreateSnippetNoteOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notes.html#create-new-snippet-note
func (s *NotesService) CreateSnippetNote(pid interface{}, snippet int, opt *CreateSnippetNoteOptions) (*Note, *Response, error) {
func (s *NotesService) CreateSnippetNote(pid interface{}, snippet int, opt *CreateSnippetNoteOptions, sudoFunc ...SudoFunc) (*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/snippets/%d/notes", url.QueryEscape(project), snippet)
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -279,14 +279,14 @@ type UpdateSnippetNoteOptions struct {
// UpdateSnippetNote modifies existing note of a snippet.
//
// https://docs.gitlab.com/ce/api/notes.html#modify-existing-snippet-note
func (s *NotesService) UpdateSnippetNote(pid interface{}, snippet int, note int, opt *UpdateSnippetNoteOptions) (*Note, *Response, error) {
func (s *NotesService) UpdateSnippetNote(pid interface{}, snippet int, note int, opt *UpdateSnippetNoteOptions, sudoFunc ...SudoFunc) (*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/snippets/%d/notes/%d", url.QueryEscape(project), snippet, note)
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -304,14 +304,14 @@ func (s *NotesService) UpdateSnippetNote(pid interface{}, snippet int, note int,
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notes.html#list-all-merge-request-notes
func (s *NotesService) ListMergeRequestNotes(pid interface{}, mergeRequest int) ([]*Note, *Response, error) {
func (s *NotesService) ListMergeRequestNotes(pid interface{}, mergeRequest int, sudoFunc ...SudoFunc) ([]*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d/notes", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -329,14 +329,14 @@ func (s *NotesService) ListMergeRequestNotes(pid interface{}, mergeRequest int)
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notes.html#get-single-merge-request-note
func (s *NotesService) GetMergeRequestNote(pid interface{}, mergeRequest int, note int) (*Note, *Response, error) {
func (s *NotesService) GetMergeRequestNote(pid interface{}, mergeRequest int, note int, sudoFunc ...SudoFunc) (*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d/notes/%d", url.QueryEscape(project), mergeRequest, note)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -363,14 +363,14 @@ type CreateMergeRequestNoteOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notes.html#create-new-merge-request-note
func (s *NotesService) CreateMergeRequestNote(pid interface{}, mergeRequest int, opt *CreateMergeRequestNoteOptions) (*Note, *Response, error) {
func (s *NotesService) CreateMergeRequestNote(pid interface{}, mergeRequest int, opt *CreateMergeRequestNoteOptions, sudoFunc ...SudoFunc) (*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/merge_requests/%d/notes", url.QueryEscape(project), mergeRequest)
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -396,15 +396,14 @@ type UpdateMergeRequestNoteOptions struct {
// UpdateMergeRequestNote modifies existing note of a merge request.
//
// https://docs.gitlab.com/ce/api/notes.html#modify-existing-merge-request-note
func (s *NotesService) UpdateMergeRequestNote(pid interface{}, mergeRequest int, note int, opt *UpdateMergeRequestNoteOptions) (*Note, *Response, error) {
func (s *NotesService) UpdateMergeRequestNote(pid interface{}, mergeRequest int, note int, opt *UpdateMergeRequestNoteOptions, sudoFunc ...SudoFunc) (*Note, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf(
"projects/%s/merge_requests/%d/notes/%d", url.QueryEscape(project), mergeRequest, note)
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -14,27 +14,14 @@ type NotificationSettingsService struct {
client *Client
}
// NotificationLevel represents a notification level.
type NotificationLevel string
// List of valid notification levels.
const (
CustomNotificationLevel NotificationLevel = "custom"
DisabledNotificationLevel NotificationLevel = "disabled"
GlobalNotificationLevel NotificationLevel = "global"
MentionNotificationLevel NotificationLevel = "mention"
ParticipatingNotificationLevel NotificationLevel = "participating"
WatchNotificationLevel NotificationLevel = "watch"
)
// NotificationSettings represents the Gitlab notification setting.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notification_settings.html#notification-settings
type NotificationSettings struct {
Level NotificationLevel `json:"level"`
NotificationEmail string `json:"notification_email"`
Events *NotificationEvents `json:"events"`
Level NotificationLevelValue `json:"level"`
NotificationEmail string `json:"notification_email"`
Events *NotificationEvents `json:"events"`
}
// NotificationEvents represents the avialable notification setting events.
......@@ -64,10 +51,10 @@ func (ns NotificationSettings) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notification_settings.html#global-notification-settings
func (s *NotificationSettingsService) GetGlobalSettings() (*NotificationSettings, *Response, error) {
func (s *NotificationSettingsService) GetGlobalSettings(sudoFunc ...SudoFunc) (*NotificationSettings, *Response, error) {
u := "notification_settings"
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -84,27 +71,27 @@ func (s *NotificationSettingsService) GetGlobalSettings() (*NotificationSettings
// NotificationSettingsOptions represents the available options that can be passed
// to the API when updating the notification settings.
type NotificationSettingsOptions struct {
Level *NotificationLevel `url:"level,omitempty" json:"level,omitempty"`
NotificationEmail *string `url:"notification_email,omitempty" json:"notification_email,omitempty"`
CloseIssue *bool `url:"close_issue,omitempty" json:"close_issue,omitempty"`
CloseMergeRequest *bool `url:"close_merge_request,omitempty" json:"close_merge_request,omitempty"`
FailedPipeline *bool `url:"failed_pipeline,omitempty" json:"failed_pipeline,omitempty"`
MergeMergeRequest *bool `url:"merge_merge_request,omitempty" json:"merge_merge_request,omitempty"`
NewIssue *bool `url:"new_issue,omitempty" json:"new_issue,omitempty"`
NewMergeRequest *bool `url:"new_merge_request,omitempty" json:"new_merge_request,omitempty"`
NewNote *bool `url:"new_note,omitempty" json:"new_note,omitempty"`
ReassignIssue *bool `url:"reassign_issue,omitempty" json:"reassign_issue,omitempty"`
ReassignMergeRequest *bool `url:"reassign_merge_request,omitempty" json:"reassign_merge_request,omitempty"`
ReopenIssue *bool `url:"reopen_issue,omitempty" json:"reopen_issue,omitempty"`
ReopenMergeRequest *bool `url:"reopen_merge_request,omitempty" json:"reopen_merge_request,omitempty"`
SuccessPipeline *bool `url:"success_pipeline,omitempty" json:"success_pipeline,omitempty"`
Level *NotificationLevelValue `url:"level,omitempty" json:"level,omitempty"`
NotificationEmail *string `url:"notification_email,omitempty" json:"notification_email,omitempty"`
CloseIssue *bool `url:"close_issue,omitempty" json:"close_issue,omitempty"`
CloseMergeRequest *bool `url:"close_merge_request,omitempty" json:"close_merge_request,omitempty"`
FailedPipeline *bool `url:"failed_pipeline,omitempty" json:"failed_pipeline,omitempty"`
MergeMergeRequest *bool `url:"merge_merge_request,omitempty" json:"merge_merge_request,omitempty"`
NewIssue *bool `url:"new_issue,omitempty" json:"new_issue,omitempty"`
NewMergeRequest *bool `url:"new_merge_request,omitempty" json:"new_merge_request,omitempty"`
NewNote *bool `url:"new_note,omitempty" json:"new_note,omitempty"`
ReassignIssue *bool `url:"reassign_issue,omitempty" json:"reassign_issue,omitempty"`
ReassignMergeRequest *bool `url:"reassign_merge_request,omitempty" json:"reassign_merge_request,omitempty"`
ReopenIssue *bool `url:"reopen_issue,omitempty" json:"reopen_issue,omitempty"`
ReopenMergeRequest *bool `url:"reopen_merge_request,omitempty" json:"reopen_merge_request,omitempty"`
SuccessPipeline *bool `url:"success_pipeline,omitempty" json:"success_pipeline,omitempty"`
}
// UpdateGlobalSettings updates current notification settings and email address.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notification_settings.html#update-global-notification-settings
func (s *NotificationSettingsService) UpdateGlobalSettings(opt *NotificationSettingsOptions) (*NotificationSettings, *Response, error) {
func (s *NotificationSettingsService) UpdateGlobalSettings(opt *NotificationSettingsOptions, sudoFunc ...SudoFunc) (*NotificationSettings, *Response, error) {
if opt.Level != nil && *opt.Level == GlobalNotificationLevel {
return nil, nil, errors.New(
"notification level 'global' is not valid for global notification settings")
......@@ -112,7 +99,7 @@ func (s *NotificationSettingsService) UpdateGlobalSettings(opt *NotificationSett
u := "notification_settings"
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -130,14 +117,14 @@ func (s *NotificationSettingsService) UpdateGlobalSettings(opt *NotificationSett
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notification_settings.html#group-project-level-notification-settings
func (s *NotificationSettingsService) GetSettingsForGroup(gid interface{}) (*NotificationSettings, *Response, error) {
func (s *NotificationSettingsService) GetSettingsForGroup(gid interface{}, sudoFunc ...SudoFunc) (*NotificationSettings, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/notification_settings", url.QueryEscape(group))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -155,14 +142,14 @@ func (s *NotificationSettingsService) GetSettingsForGroup(gid interface{}) (*Not
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notification_settings.html#group-project-level-notification-settings
func (s *NotificationSettingsService) GetSettingsForProject(pid interface{}) (*NotificationSettings, *Response, error) {
func (s *NotificationSettingsService) GetSettingsForProject(pid interface{}, sudoFunc ...SudoFunc) (*NotificationSettings, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/notification_settings", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -180,14 +167,14 @@ func (s *NotificationSettingsService) GetSettingsForProject(pid interface{}) (*N
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notification_settings.html#update-group-project-level-notification-settings
func (s *NotificationSettingsService) UpdateSettingsForGroup(gid interface{}, opt *NotificationSettingsOptions) (*NotificationSettings, *Response, error) {
func (s *NotificationSettingsService) UpdateSettingsForGroup(gid interface{}, opt *NotificationSettingsOptions, sudoFunc ...SudoFunc) (*NotificationSettings, *Response, error) {
group, err := parseID(gid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("groups/%s/notification_settings", url.QueryEscape(group))
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -205,14 +192,14 @@ func (s *NotificationSettingsService) UpdateSettingsForGroup(gid interface{}, op
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/notification_settings.html#update-group-project-level-notification-settings
func (s *NotificationSettingsService) UpdateSettingsForProject(pid interface{}, opt *NotificationSettingsOptions) (*NotificationSettings, *Response, error) {
func (s *NotificationSettingsService) UpdateSettingsForProject(pid interface{}, opt *NotificationSettingsOptions, sudoFunc ...SudoFunc) (*NotificationSettings, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/notification_settings", url.QueryEscape(project))
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
......@@ -46,7 +47,7 @@ type Pipeline struct {
ID int `json:"id"`
State string `json:"state"`
AvatarURL string `json:"avatar_url"`
WebUrl string `json:"web_url"`
WebURL string `json:"web_url"`
}
UpdatedAt *time.Time `json:"updated_at"`
CreatedAt *time.Time `json:"created_at"`
......@@ -64,14 +65,14 @@ func (i Pipeline) String() string {
// ListProjectPipelines gets a list of project piplines.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/pipelines.html#list-project-pipelines
func (s *PipelinesService) ListProjectPipelines(pid interface{}) ([]*Pipeline, *Response, error) {
func (s *PipelinesService) ListProjectPipelines(pid interface{}, sudoFunc ...SudoFunc) ([]*Pipeline, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pipelines", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -87,14 +88,14 @@ func (s *PipelinesService) ListProjectPipelines(pid interface{}) ([]*Pipeline, *
// GetPipeline gets a single project pipeline.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/pipelines.html#get-a-single-pipeline
func (s *PipelinesService) GetPipeline(pid interface{}, pipeline int) (*Pipeline, *Response, error) {
func (s *PipelinesService) GetPipeline(pid interface{}, pipeline int, sudoFunc ...SudoFunc) (*Pipeline, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pipelines/%d", url.QueryEscape(project), pipeline)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -118,14 +119,14 @@ type CreatePipelineOptions struct {
// CreatePipeline creates a new project pipeline.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/pipelines.html#create-a-new-pipeline
func (s *PipelinesService) CreatePipeline(pid interface{}, opt *CreatePipelineOptions) (*Pipeline, *Response, error) {
func (s *PipelinesService) CreatePipeline(pid interface{}, opt *CreatePipelineOptions, sudoFunc ...SudoFunc) (*Pipeline, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pipeline", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -143,14 +144,14 @@ func (s *PipelinesService) CreatePipeline(pid interface{}, opt *CreatePipelineOp
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/pipelines.html#retry-failed-builds-in-a-pipeline
func (s *PipelinesService) RetryPipelineBuild(pid interface{}, pipelineID int) (*Pipeline, *Response, error) {
func (s *PipelinesService) RetryPipelineBuild(pid interface{}, pipelineID int, sudoFunc ...SudoFunc) (*Pipeline, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pipelines/%d/retry", project, pipelineID)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -168,14 +169,14 @@ func (s *PipelinesService) RetryPipelineBuild(pid interface{}, pipelineID int) (
//
// GitLab API docs:
//https://docs.gitlab.com/ce/api/pipelines.html#cancel-a-pipelines-builds
func (s *PipelinesService) CancelPipelineBuild(pid interface{}, pipelineID int) (*Pipeline, *Response, error) {
func (s *PipelinesService) CancelPipelineBuild(pid interface{}, pipelineID int, sudoFunc ...SudoFunc) (*Pipeline, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/pipelines/%d/cancel", project, pipelineID)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -65,14 +65,14 @@ type ListSnippetsOptions struct {
// ListSnippets gets a list of project snippets.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/project_snippets.html#list-snippets
func (s *ProjectSnippetsService) ListSnippets(pid interface{}, opt *ListSnippetsOptions) ([]*Snippet, *Response, error) {
func (s *ProjectSnippetsService) ListSnippets(pid interface{}, opt *ListSnippetsOptions, sudoFunc ...SudoFunc) ([]*Snippet, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/snippets", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -90,14 +90,14 @@ func (s *ProjectSnippetsService) ListSnippets(pid interface{}, opt *ListSnippets
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_snippets.html#single-snippet
func (s *ProjectSnippetsService) GetSnippet(pid interface{}, snippet int) (*Snippet, *Response, error) {
func (s *ProjectSnippetsService) GetSnippet(pid interface{}, snippet int, sudoFunc ...SudoFunc) (*Snippet, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/snippets/%d", url.QueryEscape(project), snippet)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -127,14 +127,14 @@ type CreateSnippetOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_snippets.html#create-new-snippet
func (s *ProjectSnippetsService) CreateSnippet(pid interface{}, opt *CreateSnippetOptions) (*Snippet, *Response, error) {
func (s *ProjectSnippetsService) CreateSnippet(pid interface{}, opt *CreateSnippetOptions, sudoFunc ...SudoFunc) (*Snippet, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/snippets", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -164,14 +164,14 @@ type UpdateSnippetOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_snippets.html#update-snippet
func (s *ProjectSnippetsService) UpdateSnippet(pid interface{}, snippet int, opt *UpdateSnippetOptions) (*Snippet, *Response, error) {
func (s *ProjectSnippetsService) UpdateSnippet(pid interface{}, snippet int, opt *UpdateSnippetOptions, sudoFunc ...SudoFunc) (*Snippet, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/snippets/%d", url.QueryEscape(project), snippet)
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -191,14 +191,14 @@ func (s *ProjectSnippetsService) UpdateSnippet(pid interface{}, snippet int, opt
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_snippets.html#delete-snippet
func (s *ProjectSnippetsService) DeleteSnippet(pid interface{}, snippet int) (*Response, error) {
func (s *ProjectSnippetsService) DeleteSnippet(pid interface{}, snippet int, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/snippets/%d", url.QueryEscape(project), snippet)
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......@@ -210,14 +210,14 @@ func (s *ProjectSnippetsService) DeleteSnippet(pid interface{}, snippet int) (*R
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/project_snippets.html#snippet-content
func (s *ProjectSnippetsService) SnippetContent(pid interface{}, snippet int) ([]byte, *Response, error) {
func (s *ProjectSnippetsService) SnippetContent(pid interface{}, snippet int, sudoFunc ...SudoFunc) ([]byte, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/snippets/%d/raw", url.QueryEscape(project), snippet)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......
This diff is collapsed.
......@@ -57,14 +57,14 @@ type ListTreeOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repositories.html#list-repository-tree
func (s *RepositoriesService) ListTree(pid interface{}, opt *ListTreeOptions) ([]*TreeNode, *Response, error) {
func (s *RepositoriesService) ListTree(pid interface{}, opt *ListTreeOptions, sudoFunc ...SudoFunc) ([]*TreeNode, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/tree", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -90,14 +90,14 @@ type RawFileContentOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repositories.html#raw-file-content
func (s *RepositoriesService) RawFileContent(pid interface{}, sha string, opt *RawFileContentOptions) ([]byte, *Response, error) {
func (s *RepositoriesService) RawFileContent(pid interface{}, sha string, opt *RawFileContentOptions, sudoFunc ...SudoFunc) ([]byte, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/blobs/%s", url.QueryEscape(project), sha)
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -115,14 +115,14 @@ func (s *RepositoriesService) RawFileContent(pid interface{}, sha string, opt *R
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repositories.html#raw-blob-content
func (s *RepositoriesService) RawBlobContent(pid interface{}, sha string) ([]byte, *Response, error) {
func (s *RepositoriesService) RawBlobContent(pid interface{}, sha string, sudoFunc ...SudoFunc) ([]byte, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/raw_blobs/%s", url.QueryEscape(project), sha)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -148,14 +148,14 @@ type ArchiveOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repositories.html#get-file-archive
func (s *RepositoriesService) Archive(pid interface{}, opt *ArchiveOptions) ([]byte, *Response, error) {
func (s *RepositoriesService) Archive(pid interface{}, opt *ArchiveOptions, sudoFunc ...SudoFunc) ([]byte, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/archive", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -198,14 +198,14 @@ type CompareOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repositories.html#compare-branches-tags-or-commits
func (s *RepositoriesService) Compare(pid interface{}, opt *CompareOptions) (*Compare, *Response, error) {
func (s *RepositoriesService) Compare(pid interface{}, opt *CompareOptions, sudoFunc ...SudoFunc) (*Compare, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/compare", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -237,14 +237,14 @@ func (c Contributor) String() string {
// Contributors gets the repository contributors list.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/repositories.html#contributer
func (s *RepositoriesService) Contributors(pid interface{}) ([]*Contributor, *Response, error) {
func (s *RepositoriesService) Contributors(pid interface{}, sudoFunc ...SudoFunc) ([]*Contributor, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/contributors", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -61,14 +61,14 @@ type GetFileOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#get-file-from-respository
func (s *RepositoryFilesService) GetFile(pid interface{}, opt *GetFileOptions) (*File, *Response, error) {
func (s *RepositoryFilesService) GetFile(pid interface{}, opt *GetFileOptions, sudoFunc ...SudoFunc) (*File, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/files", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, opt)
req, err := s.client.NewRequest("GET", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -112,14 +112,14 @@ type CreateFileOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#create-new-file-in-repository
func (s *RepositoryFilesService) CreateFile(pid interface{}, opt *CreateFileOptions) (*FileInfo, *Response, error) {
func (s *RepositoryFilesService) CreateFile(pid interface{}, opt *CreateFileOptions, sudoFunc ...SudoFunc) (*FileInfo, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/files", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -151,14 +151,14 @@ type UpdateFileOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#update-existing-file-in-repository
func (s *RepositoryFilesService) UpdateFile(pid interface{}, opt *UpdateFileOptions) (*FileInfo, *Response, error) {
func (s *RepositoryFilesService) UpdateFile(pid interface{}, opt *UpdateFileOptions, sudoFunc ...SudoFunc) (*FileInfo, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/files", url.QueryEscape(project))
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -188,14 +188,14 @@ type DeleteFileOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/repository_files.html#delete-existing-file-in-repository
func (s *RepositoryFilesService) DeleteFile(pid interface{}, opt *DeleteFileOptions) (*FileInfo, *Response, error) {
func (s *RepositoryFilesService) DeleteFile(pid interface{}, opt *DeleteFileOptions, sudoFunc ...SudoFunc) (*FileInfo, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/files", url.QueryEscape(project))
req, err := s.client.NewRequest("DELETE", u, opt)
req, err := s.client.NewRequest("DELETE", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -60,14 +60,14 @@ type SetGitLabCIServiceOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#edit-gitlab-ci-service
func (s *ServicesService) SetGitLabCIService(pid interface{}, opt *SetGitLabCIServiceOptions) (*Response, error) {
func (s *ServicesService) SetGitLabCIService(pid interface{}, opt *SetGitLabCIServiceOptions, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/gitlab-ci", url.QueryEscape(project))
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, err
}
......@@ -79,14 +79,14 @@ func (s *ServicesService) SetGitLabCIService(pid interface{}, opt *SetGitLabCISe
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#delete-gitlab-ci-service
func (s *ServicesService) DeleteGitLabCIService(pid interface{}) (*Response, error) {
func (s *ServicesService) DeleteGitLabCIService(pid interface{}, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/gitlab-ci", url.QueryEscape(project))
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......@@ -108,14 +108,14 @@ type SetHipChatServiceOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#edit-hipchat-service
func (s *ServicesService) SetHipChatService(pid interface{}, opt *SetHipChatServiceOptions) (*Response, error) {
func (s *ServicesService) SetHipChatService(pid interface{}, opt *SetHipChatServiceOptions, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/hipchat", url.QueryEscape(project))
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, err
}
......@@ -127,14 +127,14 @@ func (s *ServicesService) SetHipChatService(pid interface{}, opt *SetHipChatServ
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#delete-hipchat-service
func (s *ServicesService) DeleteHipChatService(pid interface{}) (*Response, error) {
func (s *ServicesService) DeleteHipChatService(pid interface{}, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/hipchat", url.QueryEscape(project))
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......@@ -157,14 +157,14 @@ type SetDroneCIServiceOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#createedit-drone-ci-service
func (s *ServicesService) SetDroneCIService(pid interface{}, opt *SetDroneCIServiceOptions) (*Response, error) {
func (s *ServicesService) SetDroneCIService(pid interface{}, opt *SetDroneCIServiceOptions, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/drone-ci", url.QueryEscape(project))
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, err
}
......@@ -176,14 +176,14 @@ func (s *ServicesService) SetDroneCIService(pid interface{}, opt *SetDroneCIServ
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#delete-drone-ci-service
func (s *ServicesService) DeleteDroneCIService(pid interface{}) (*Response, error) {
func (s *ServicesService) DeleteDroneCIService(pid interface{}, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/drone-ci", url.QueryEscape(project))
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......@@ -208,14 +208,14 @@ type DroneCIService struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#get-drone-ci-service-settings
func (s *ServicesService) GetDroneCIService(pid interface{}) (*DroneCIService, *Response, error) {
func (s *ServicesService) GetDroneCIService(pid interface{}, sudoFunc ...SudoFunc) (*DroneCIService, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/services/drone-ci", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -244,14 +244,14 @@ type SetSlackServiceOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#edit-slack-service
func (s *ServicesService) SetSlackService(pid interface{}, opt *SetSlackServiceOptions) (*Response, error) {
func (s *ServicesService) SetSlackService(pid interface{}, opt *SetSlackServiceOptions, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/slack", url.QueryEscape(project))
req, err := s.client.NewRequest("PUT", u, opt)
req, err := s.client.NewRequest("PUT", u, opt, sudoFunc)
if err != nil {
return nil, err
}
......@@ -263,14 +263,14 @@ func (s *ServicesService) SetSlackService(pid interface{}, opt *SetSlackServiceO
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/services.html#delete-slack-service
func (s *ServicesService) DeleteSlackService(pid interface{}) (*Response, error) {
func (s *ServicesService) DeleteSlackService(pid interface{}, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/services/slack", url.QueryEscape(project))
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......
......@@ -62,8 +62,8 @@ type GetSessionOptions struct {
// GetSession logs in to get private token.
//
// GitLab API docs: https://docs.gitlab.com/ce/api/session.html#session
func (s *SessionService) GetSession(opt *GetSessionOptions) (*Session, *Response, error) {
req, err := s.client.NewRequest("POST", "session", opt)
func (s *SessionService) GetSession(opt *GetSessionOptions, sudoFunc ...SudoFunc) (*Session, *Response, error) {
req, err := s.client.NewRequest("POST", "session", opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -59,8 +59,8 @@ func (s Settings) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/settings.html#get-current-application.settings
func (s *SettingsService) GetSettings() (*Settings, *Response, error) {
req, err := s.client.NewRequest("GET", "application/settings", nil)
func (s *SettingsService) GetSettings(sudoFunc ...SudoFunc) (*Settings, *Response, error) {
req, err := s.client.NewRequest("GET", "application/settings", nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -101,8 +101,8 @@ type UpdateSettingsOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/settings.html#change-application.settings
func (s *SettingsService) UpdateSettings(opt *UpdateSettingsOptions) (*Settings, *Response, error) {
req, err := s.client.NewRequest("PUT", "application/settings", opt)
func (s *SettingsService) UpdateSettings(opt *UpdateSettingsOptions, sudoFunc ...SudoFunc) (*Settings, *Response, error) {
req, err := s.client.NewRequest("PUT", "application/settings", opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......
......@@ -46,8 +46,8 @@ func (h Hook) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/system_hooks.html#list-system-hooks
func (s *SystemHooksService) ListHooks() ([]*Hook, *Response, error) {
req, err := s.client.NewRequest("GET", "hooks", nil)
func (s *SystemHooksService) ListHooks(sudoFunc ...SudoFunc) ([]*Hook, *Response, error) {
req, err := s.client.NewRequest("GET", "hooks", nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -73,8 +73,8 @@ type AddHookOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/system_hooks.html#add-new-system-hook-hook
func (s *SystemHooksService) AddHook(opt *AddHookOptions) (*Hook, *Response, error) {
req, err := s.client.NewRequest("POST", "hooks", opt)
func (s *SystemHooksService) AddHook(opt *AddHookOptions, sudoFunc ...SudoFunc) (*Hook, *Response, error) {
req, err := s.client.NewRequest("POST", "hooks", opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -108,10 +108,10 @@ func (h HookEvent) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/system_hooks.html#test-system-hook
func (s *SystemHooksService) TestHook(hook int) (*HookEvent, *Response, error) {
func (s *SystemHooksService) TestHook(hook int, sudoFunc ...SudoFunc) (*HookEvent, *Response, error) {
u := fmt.Sprintf("hooks/%d", hook)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -131,10 +131,10 @@ func (s *SystemHooksService) TestHook(hook int) (*HookEvent, *Response, error) {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/system_hooks.html#delete-system-hook
func (s *SystemHooksService) DeleteHook(hook int) (*Response, error) {
func (s *SystemHooksService) DeleteHook(hook int, sudoFunc ...SudoFunc) (*Response, error) {
u := fmt.Sprintf("hooks/%d", hook)
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......
......@@ -47,14 +47,14 @@ func (r Tag) String() string {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/tags.html#list-project-repository-tags
func (s *TagsService) ListTags(pid interface{}) ([]*Tag, *Response, error) {
func (s *TagsService) ListTags(pid interface{}, sudoFunc ...SudoFunc) ([]*Tag, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/tags", url.QueryEscape(project))
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -73,14 +73,14 @@ func (s *TagsService) ListTags(pid interface{}) ([]*Tag, *Response, error) {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/tags.html#get-a-single-repository-tag
func (s *TagsService) GetTag(pid interface{}, tag string) (*Tag, *Response, error) {
func (s *TagsService) GetTag(pid interface{}, tag string, sudoFunc ...SudoFunc) (*Tag, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/tags/%s", url.QueryEscape(project), tag)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -108,14 +108,14 @@ type CreateTagOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/tags.html#create-a-new-tag
func (s *TagsService) CreateTag(pid interface{}, opt *CreateTagOptions) (*Tag, *Response, error) {
func (s *TagsService) CreateTag(pid interface{}, opt *CreateTagOptions, sudoFunc ...SudoFunc) (*Tag, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/repository/tags", url.QueryEscape(project))
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -133,14 +133,14 @@ func (s *TagsService) CreateTag(pid interface{}, opt *CreateTagOptions) (*Tag, *
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/tags.html#delete-a-tag
func (s *TagsService) DeleteTag(pid interface{}, tag string) (*Response, error) {
func (s *TagsService) DeleteTag(pid interface{}, tag string, sudoFunc ...SudoFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/repository/tags/%s", url.QueryEscape(project), tag)
req, err := s.client.NewRequest("DELETE", u, nil)
req, err := s.client.NewRequest("DELETE", u, nil, sudoFunc)
if err != nil {
return nil, err
}
......
......@@ -41,14 +41,14 @@ type SetTimeEstimateOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#set-a-time-estimate-for-an-issue
func (s *TimeStatsService) SetTimeEstimate(pid interface{}, issue int, opt *SetTimeEstimateOptions) (*TimeStats, *Response, error) {
func (s *TimeStatsService) SetTimeEstimate(pid interface{}, issue int, opt *SetTimeEstimateOptions, sudoFunc ...SudoFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/time_estimate", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -66,14 +66,14 @@ func (s *TimeStatsService) SetTimeEstimate(pid interface{}, issue int, opt *SetT
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#reset-the-time-estimate-for-an-issue
func (s *TimeStatsService) ResetTimeEstimate(pid interface{}, issue int) (*TimeStats, *Response, error) {
func (s *TimeStatsService) ResetTimeEstimate(pid interface{}, issue int, sudoFunc ...SudoFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/reset_time_estimate", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -99,14 +99,14 @@ type AddSpentTimeOptions struct {
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#add-spent-time-for-an-issue
func (s *TimeStatsService) AddSpentTime(pid interface{}, issue int, opt *AddSpentTimeOptions) (*TimeStats, *Response, error) {
func (s *TimeStatsService) AddSpentTime(pid interface{}, issue int, opt *AddSpentTimeOptions, sudoFunc ...SudoFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/add_spent_time", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("POST", u, opt)
req, err := s.client.NewRequest("POST", u, opt, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -124,14 +124,14 @@ func (s *TimeStatsService) AddSpentTime(pid interface{}, issue int, opt *AddSpen
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#reset-spent-time-for-an-issue
func (s *TimeStatsService) ResetSpentTime(pid interface{}, issue int) (*TimeStats, *Response, error) {
func (s *TimeStatsService) ResetSpentTime(pid interface{}, issue int, sudoFunc ...SudoFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/reset_spent_time", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("POST", u, nil)
req, err := s.client.NewRequest("POST", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......@@ -149,14 +149,14 @@ func (s *TimeStatsService) ResetSpentTime(pid interface{}, issue int) (*TimeStat
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/issues.html#get-time-tracking-stats
func (s *TimeStatsService) GetTimeSpent(pid interface{}, issue int) (*TimeStats, *Response, error) {
func (s *TimeStatsService) GetTimeSpent(pid interface{}, issue int, sudoFunc ...SudoFunc) (*TimeStats, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues/%d/time_stats", url.QueryEscape(project), issue)
req, err := s.client.NewRequest("GET", u, nil)
req, err := s.client.NewRequest("GET", u, nil, sudoFunc)
if err != nil {
return nil, nil, err
}
......
This diff is collapsed.
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