Commit dc25ceb5 authored by Sander van Harmelen's avatar Sander van Harmelen

First release v0.1.0

parent bf270563
go-github CHANGELOG
===================
0.1.0
-----
- Initial release
# go-gitlab
A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way
**Documentation:** [![GoDoc](https://godoc.org/github.com/xanzy/go-gitlab?status.svg)](https://godoc.org/github.com/xanzy/go-gitlab)
**Build Status:** [![Build Status](https://travis-ci.org/xanzy/go-gitlab.svg?branch=master)](https://travis-ci.org/xanzy/go-gitlab)
## Coverage
This API client package covers **100%** of the existing GitLab API calls! So this
includes all calls to the following services:
- [x] Users
- [x] Session
- [x] Projects (including setting Webhooks)
- [x] Project Snippets
- [x] Services
- [x] Repositories
- [x] Repository Files
- [x] Commits
- [x] Branches
- [x] Merge Requests
- [x] Issues
- [x] Labels
- [x] Milestones
- [x] Notes (comments)
- [x] Deploy Keys
- [x] System Hooks
- [x] Groups
- [x] Namespaces
- [x] Settings
## Usage
```go
import "github.com/xanzy/go-gitlab"
```
Construct a new GitLab client, then use the various services on the client to
access different parts of the GitLab API. For example, to list all
users:
```go
git := gitlab.NewClient(nil, "yourtokengoeshere")
users, _, err := git.Users.ListUsers()
```
Some API methods have optional parameters that can be passed. For example,
to list all projects for user "svanharmelen":
```go
client := github.NewClient(nil)
opt := &ListProjectsOptions{Search: "svanharmelen"})
projects, _, err := client.Projects.ListProjects(opt)
```
### Examples
The [examples](https://github.com/xanzy/go-gitlab/tree/master/examples) directory
contains a couple for clear examples, of which one is partially listed here as well:
```go
package main
import (
"log"
"github.com/xanzy/go-gitlab"
)
func main() {
git := gitlab.NewClient(nil, "yourtokengoeshere")
// Create new project
p := &gitlab.CreateProjectOptions{
Name: "My Project",
Description: "Just a test project to play with",
MergeRequestsEnabled: true,
SnippetsEnabled: true,
VisibilityLevel: gitlab.PublicVisibility,
}
project, _, err := git.Projects.CreateProject(p)
if err != nil {
log.Fatal(err)
}
// Add a new snippet
s := &gitlab.CreateSnippetOptions{
Title: "Dummy Snippet",
FileName: "snippet.go",
Code: "package main....",
VisibilityLevel: gitlab.PublicVisibility,
}
_, _, err = git.ProjectSnippets.CreateSnippet(project.ID, s)
if err != nil {
log.Fatal(err)
}
}
```
For complete usage of go-gitlab, see the full [package docs](https://godoc.org/github.com/xanzy/go-gitlab).
## ToDo
- The biggest thing this package still needs is tests :disappointed:
## Issues
- If you have an issue: report it on the [issue tracker](https://github.com/xanzy/go-gitlab/issues)
## Author
Sander van Harmelen (<sander@xanzy.io>)
## License
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"net/url"
)
// BranchesService handles communication with the branch related methods
// of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/branches.html
type BranchesService struct {
client *Client
}
// Branch represents a GitLab branch.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/branches.html
type Branch struct {
Commit *Commit `json:"commit"`
Name string `json:"name"`
Protected bool `json:"protected"`
}
func (b Branch) String() string {
return Stringify(b)
}
// ListBranches gets a list of repository branches from a project, sorted by
// name alphabetically.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/branches.html#list-repository-branches
func (s *BranchesService) ListBranches(pid interface{}) ([]*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)
if err != nil {
return nil, nil, err
}
var b []*Branch
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// GetBranch gets a single project repository branch.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/branches.html#get-single-repository-branch
func (s *BranchesService) GetBranch(pid interface{}, branch string) (*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)
if err != nil {
return nil, nil, err
}
b := new(Branch)
resp, err := s.client.Do(req, b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// ProtectBranch protects a single project repository branch. This is an
// idempotent function, protecting an already protected repository branch
// still returns a 200 OK status code.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/branches.html#protect-repository-branch
func (s *BranchesService) ProtectBranch(pid interface{}, branch string) (*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)
if err != nil {
return nil, nil, err
}
b := new(Branch)
resp, err := s.client.Do(req, b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// UnprotectBranch unprotects a single project repository branch. This is an
// idempotent function, unprotecting an already unprotected repository branch
// still returns a 200 OK status code.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/branches.html#unprotect-repository-branch
func (s *BranchesService) UnprotectBranch(
pid interface{},
branch string) (*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)
if err != nil {
return nil, nil, err
}
b := new(Branch)
resp, err := s.client.Do(req, b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// CreateBranchOptions represents the available CreateBranch() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/branches.html#create-repository-branch
type CreateBranchOptions struct {
BranchName string `url:"branch_name,omitempty"`
Ref string `url:"ref,omitempty"`
}
// CreateBranch creates branch from commit SHA or existing branch.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/branches.html#create-repository-branch
func (s *BranchesService) CreateBranch(
pid interface{},
opt *CreateBranchOptions) (*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)
if err != nil {
return nil, nil, err
}
b := new(Branch)
resp, err := s.client.Do(req, b)
if err != nil {
return nil, resp, err
}
return b, resp, err
}
// DeleteBranch deletes an existing branch.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/branches.html#delete-repository-branch
func (s *BranchesService) DeleteBranch(pid interface{}, branch string) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"net/url"
"time"
)
// CommitsService handles communication with the commit related methods
// of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/commits.html
type CommitsService struct {
client *Client
}
// Commit represents a GitLab commit.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/commits.html
type Commit struct {
ID string `json:"id"`
ShortID string `json:"short_id"`
Title string `json:"title"`
AuthorName string `json:"author_name"`
AuthorEmail string `json:"author_email"`
AuthoredDate time.Time `json:"authored_date"`
CommittedDate time.Time `json:"committed_date"`
CommitterName string `json:"committer_name"`
CommitterEmail string `json:"committer_email"`
CreatedAt time.Time `json:"created_at"`
Message string `json:"message"`
ParentsIds []string `json:"parents_ids"`
}
func (c Commit) String() string {
return Stringify(c)
}
// ListCommitsOptions represents the available ListCommits() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/commits.html#list-commits
type ListCommitsOptions struct {
RefName string `url:"ref_name,omitempty"`
}
// ListCommits gets a list of repository commits in a project.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/commits.html#list-commits
func (s *CommitsService) ListCommits(
pid interface{},
opt *ListCommitsOptions) ([]*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)
if err != nil {
return nil, nil, err
}
var c []*Commit
resp, err := s.client.Do(req, &c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// GetCommit gets a specific commit identified by the commit hash or name of a
// branch or tag.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/commits.html#get-a-single-commit
func (s *CommitsService) GetCommit(
pid interface{},
sha string) (*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)
if err != nil {
return nil, nil, err
}
c := new(Commit)
resp, err := s.client.Do(req, c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// Diff represents a GitLab diff.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/commits.html
type Diff struct {
Diff string `json:"diff"`
NewPath string `json:"new_path"`
OldPath string `json:"old_path"`
AMode string `json:"a_mode"`
BMode string `json:"b_mode"`
NewFile bool `json:"new_file"`
RenamedFile bool `json:"renamed_file"`
DeletedFile bool `json:"deleted_file"`
}
func (d Diff) String() string {
return Stringify(d)
}
// GetCommitDiff gets the diff of a commit in a project..
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/commits.html#get-the-diff-of-a-commit
func (s *CommitsService) GetCommitDiff(
pid interface{},
sha string) ([]*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)
if err != nil {
return nil, nil, err
}
var d []*Diff
resp, err := s.client.Do(req, &d)
if err != nil {
return nil, resp, err
}
return d, resp, err
}
// CommitComment represents a GitLab commit comment.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/commits.html
type CommitComment struct {
Note string `json:"note"`
Path string `json:"path"`
Line int `json:"line"`
LineType string `json:"line_type"`
Author struct {
ID int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Name string `json:"name"`
State string `json:"state"`
Blocked bool `json:"blocked"`
CreatedAt time.Time `json:"created_at"`
} `json:"author"`
}
func (c CommitComment) String() string {
return Stringify(c)
}
// GetCommitComments gets the comments of a commit in a project.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/commits.html#get-the-comments-of-a-commit
func (s *CommitsService) GetCommitComments(
pid interface{},
sha string) ([]*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)
if err != nil {
return nil, nil, err
}
var c []*CommitComment
resp, err := s.client.Do(req, &c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// PostCommitCommentOptions represents the available PostCommitComment()
// options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/commits.html#post-comment-to-commit
type PostCommitCommentOptions struct {
Note string `url:"note,omitempty"`
Path string `url:"path"`
Line int `url:"line"`
LineType string `url:"line_type"`
}
// PostCommitComment adds a comment to a commit. Optionally you can post
// comments on a specific line of a commit. Therefor both path, line_new and
// line_old are required.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/commits.html#post-comment-to-commit
func (s *CommitsService) PostCommitComment(
pid interface{},
sha string,
opt *PostCommitCommentOptions) (*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)
if err != nil {
return nil, nil, err
}
c := new(CommitComment)
resp, err := s.client.Do(req, c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"net/url"
"time"
)
// DeployKeysService handles communication with the keys related methods
// of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/deploy_keys.html
type DeployKeysService struct {
client *Client
}
// DeployKey represents a GitLab deploy key.
type DeployKey struct {
ID int `json:"id"`
Title string `json:"title"`
Key string `json:"key"`
CreatedAt time.Time `json:"created_at"`
}
func (k DeployKey) String() string {
return Stringify(k)
}
// ListDeployKeys gets a list of a project's deploy keys
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/deploy_keys.html#list-deploy-keys
func (s *DeployKeysService) ListDeployKeys(pid interface{}) ([]*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)
if err != nil {
return nil, nil, err
}
var k []*DeployKey
resp, err := s.client.Do(req, &k)
if err != nil {
return nil, resp, err
}
return k, resp, err
}
// GetDeployKey gets a single deploy key.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/deploy_keys.html#single-deploy-key
func (s *DeployKeysService) GetDeployKey(
pid interface{},
deployKey int) (*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)
if err != nil {
return nil, nil, err
}
k := new(DeployKey)
resp, err := s.client.Do(req, k)
if err != nil {
return nil, resp, err
}
return k, resp, err
}
// AddDeployKeyOptions represents the available ADDDeployKey() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/deploy_keys.html#add-deploy-key
type AddDeployKeyOptions struct {
Title string `url:"title,omitempty"`
Key string `url:"key,omitempty"`
}
// AddDeployKey creates a new deploy key for a project. If deploy key already
// exists in another project - it will be joined to project but only if
// original one was is accessible by same user.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/deploy_keys.html#add-deploy-key
func (s *DeployKeysService) AddDeployKey(
pid interface{},
opt *AddDeployKeyOptions) (*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)
if err != nil {
return nil, nil, err
}
k := new(DeployKey)
resp, err := s.client.Do(req, k)
if err != nil {
return nil, resp, err
}
return k, resp, err
}
// DeleteDeployKey deletes a deploy key from a project.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/deploy_keys.html#delete-deploy-key
func (s *DeployKeysService) DeleteDeployKey(pid interface{}, deployKey int) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
package main
import (
"log"
"github.com/xanzy/go-gitlab"
)
func main() {
git := gitlab.NewClient(nil, "yourtokengoeshere")
// Create new label
l := &gitlab.CreateLabelOptions{
Name: "My Label",
Color: "#11FF22",
}
label, _, err := git.Labels.CreateLabel("myname/myproject", l)
if err != nil {
log.Fatal(err)
}
log.Printf("Created label: %s\nWith color: %s\n", label.Name, label.Color)
// List all labels
labels, _, err := git.Labels.ListLabels("myname/myproject")
if err != nil {
log.Fatal(err)
}
for _, label := range labels {
log.Printf("Found label: %s", label.Name)
}
}
package main
import (
"log"
"github.com/xanzy/go-gitlab"
)
func main() {
git := gitlab.NewClient(nil, "yourtokengoeshere")
// Create new project
p := &gitlab.CreateProjectOptions{
Name: "My Project",
Description: "Just a test project to play with",
MergeRequestsEnabled: true,
SnippetsEnabled: true,
VisibilityLevel: gitlab.PublicVisibility,
}
project, _, err := git.Projects.CreateProject(p)
if err != nil {
log.Fatal(err)
}
// Add a new snippet
s := &gitlab.CreateSnippetOptions{
Title: "Dummy Snippet",
FileName: "snippet.go",
Code: "package main....",
VisibilityLevel: gitlab.PublicVisibility,
}
_, _, err = git.ProjectSnippets.CreateSnippet(project.ID, s)
if err != nil {
log.Fatal(err)
}
// List all project snippets
snippets, _, err := git.ProjectSnippets.ListSnippits(project.PathWithNamespace)
if err != nil {
log.Fatal(err)
}
for _, snippet := range snippets {
log.Printf("Found snippet: %s", snippet.Title)
}
}
package main
import (
"encoding/base64"
"log"
"github.com/xanzy/go-gitlab"
)
func main() {
git := gitlab.NewClient(nil, "yourtokengoeshere")
// Create a new repository file
cf := &gitlab.CreateFileOptions{
FilePath: "file.go",
BranchName: "master",
Encoding: "text",
Content: "My file contenxst",
CommitMessage: "Adding a test file",
}
file, _, err := git.RepositoryFiles.CreateFile("myname/myproject", cf)
if err != nil {
log.Fatal(err)
}
// Update a repository file
uf := &gitlab.UpdateFileOptions{
FilePath: file.FilePath,
BranchName: "master",
Encoding: "text",
Content: "My file content",
CommitMessage: "Fixing typo",
}
_, _, err = git.RepositoryFiles.UpdateFile("myname/myproject", uf)
if err != nil {
log.Fatal(err)
}
gf := &gitlab.GetFileOptions{
FilePath: file.FilePath,
Ref: "master",
}
f, _, err := git.RepositoryFiles.GetFile("myname/myproject", gf)
if err != nil {
log.Fatal(err)
}
if f.Encoding == "base64" {
content, err := base64.StdEncoding.DecodeString(f.Content)
if err != nil {
log.Fatal(err)
}
log.Printf("File contains: %s", string(content))
} else {
log.Printf("File contains: %s", f.Content)
}
}
This diff is collapsed.
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"time"
)
// GroupsService handles communication with the group related methods of
// the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/groups.html
type GroupsService struct {
client *Client
}
// Group represents a GitLab group.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/groups.html
type Group struct {
ID int `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Description string `json:"description"`
}
// ListGroups gets a list of groups. (As user: my groups, as admin: all groups)
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/groups.html#list-project-groups
func (s *GroupsService) ListGroups() ([]*Group, *Response, error) {
req, err := s.client.NewRequest("GET", "groups", nil)
if err != nil {
return nil, nil, err
}
var g []*Group
resp, err := s.client.Do(req, &g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// GetGroup gets all details of a group.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/groups.html#details-of-a-group
func (s *GroupsService) GetGroup(gid interface{}) (*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)
if err != nil {
return nil, nil, err
}
g := new(Group)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// CreateGroupOptions represents the available CreateGroup() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/groups.html#new-group
type CreateGroupOptions struct {
Name string `url:"name,omitempty"`
Path string `url:"path,omitempty"`
Description string `url:"description,omitempty"`
}
// CreateGroup creates a new project group. Available only for users who can
// create groups.
//
// GitLab API docs: http://doc.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)
if err != nil {
return nil, nil, err
}
g := new(Group)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// TransferGroup transfers a project to the Group namespace. Available only
// for admin.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/groups.html#transfer-project-to-group
func (s *GroupsService) TransferGroup(gid interface{}, project int) (*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)
if err != nil {
return nil, nil, err
}
g := new(Group)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// DeleteGroup removes group with all projects inside.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/groups.html#remove-group
func (s *GroupsService) DeleteGroup(gid interface{}) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
// SearchGroup get all groups that match your string in their name or path.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/groups.html#search-for-group
func (s *GroupsService) SearchGroup(query string) ([]*Group, *Response, error) {
var q struct {
Search string `url:"search,omitempty"`
}
q.Search = query
req, err := s.client.NewRequest("GET", "groups", &q)
if err != nil {
return nil, nil, err
}
var g []*Group
resp, err := s.client.Do(req, &g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// GroupMember represents a GitLab group member.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/groups.html
type GroupMember 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"`
AccessLevel int `json:"access_level"`
}
// ListGroupMembers get a list of group members viewable by the authenticated
// user.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/groups.html#list-group-members
func (s *GroupsService) ListGroupMembers(gid interface{}) ([]*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, nil)
if err != nil {
return nil, nil, err
}
var g []*GroupMember
resp, err := s.client.Do(req, &g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// AddGroupMemberOptions represents the available AddGroupMember() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/groups.html#add-group-member
type AddGroupMemberOptions struct {
UserID int `url:"user_id,omitempty"`
AccessLevel AccessLevel `url:"access_level,omitempty"`
}
// AddGroupMember adds a user to the list of group members.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/groups.html#list-group-members
func (s *GroupsService) AddGroupMember(
gid interface{},
opt *AddGroupMemberOptions) (*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)
if err != nil {
return nil, nil, err
}
g := new(GroupMember)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// UpdateGroupMemberOptions represents the available UpdateGroupMember()
// options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/groups.html#edit-group-team-member
type UpdateGroupMemberOptions struct {
AccessLevel AccessLevel `url:"access_level,omitempty"`
}
// UpdateGroupMember updates a group team member to a specified access level.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/groups.html#list-group-members
func (s *GroupsService) UpdateGroupMember(
gid interface{},
user int,
opt *UpdateGroupMemberOptions) (*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)
if err != nil {
return nil, nil, err
}
g := new(GroupMember)
resp, err := s.client.Do(req, g)
if err != nil {
return nil, resp, err
}
return g, resp, err
}
// RemoveGroupMember removes user from user team.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/groups.html#remove-user-from-user-team
func (s *GroupsService) RemoveGroupMember(gid interface{}, user int) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"log"
"net/url"
"strings"
"time"
)
// IssuesService handles communication with the issue related methods
// of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html
type IssuesService struct {
client *Client
}
// Issue represents a GitLab issue.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html
type Issue struct {
ID int `json:"id"`
IID int `json:"iid"`
ProjectID int `json:"project_id"`
Title string `json:"title"`
Description string `json:"description"`
Labels []string `json:"labels"`
Milestone struct {
ID int `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
DueDate string `json:"due_date"`
State string `json:"state"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
} `json:"milestone"`
Assignee 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:"assignee"`
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"`
State string `json:"state"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
}
func (i Issue) String() string {
return Stringify(i)
}
// ListIssuesOptions represents the available ListIssues() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#list-issues
type ListIssuesOptions struct {
State string `url:"state,omitempty"`
Labels []string `url:"labels,omitempty"`
OrderBy string `url:"order_by,omitempty"`
Sort string `url:"sort,omitempty"`
}
// ListIssues gets all issues created by authenticated user. This function
// takes pagination parameters page and per_page to restrict the list of issues.
//
// GitLab API docs: http://doc.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)
if err != nil {
return nil, nil, err
}
var i []*Issue
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// ListProjectIssuesOptions represents the available ListProjectIssues() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#list-issues
type ListProjectIssuesOptions struct {
IID int `url:"iid,omitempty"`
State string `url:"state,omitempty"`
Labels []string `url:"labels,omitempty"`
Milestone string `url:"milestone,omitempty"`
OrderBy string `url:"order_by,omitempty"`
Sort string `url:"sort,omitempty"`
}
// ListProjectIssues gets all issues created by authenticated user. This function
// takes pagination parameters page and per_page to restrict the list of issues.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#list-issues
func (s *IssuesService) ListProjectIssues(
pid interface{},
opt *ListProjectIssuesOptions) ([]*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)
if err != nil {
return nil, nil, err
}
var i []*Issue
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// GetIssue gets a single project issue.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#single-issues
func (s *IssuesService) GetIssue(pid interface{}, issue int) (*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)
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// CreateIssueOptions represents the available CreateIssue() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#new-issues
type CreateIssueOptions struct {
Title string `url:"title,omitempty"`
Description string `url:"description,omitempty"`
AssigneeID int `url:"assignee_id,omitempty"`
MilestoneID int `url:"milestone_id,omitempty"`
Labels []string `url:"labels,omitempty"`
}
// CreateIssue creates a new project issue.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#new-issues
func (s *IssuesService) CreateIssue(
pid interface{},
opt *CreateIssueOptions) (*Issue, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
}
u := fmt.Sprintf("projects/%s/issues", url.QueryEscape(project))
// This is needed to get a single, comma separated string
opt.Labels = []string{strings.Join(opt.Labels, ",")}
req, err := s.client.NewRequest("POST", u, opt)
if err != nil {
return nil, nil, err
}
log.Printf("req: %#+v\n", req.URL)
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
// UpdateIssueOptions represents the available UpdateIssue() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#edit-issues
type UpdateIssueOptions struct {
Title string `url:"title,omitempty"`
Description string `url:"description,omitempty"`
AssigneeID int `url:"assignee_id,omitempty"`
MilestoneID int `url:"milestone_id,omitempty"`
Labels []string `url:"labels,omitempty"`
StateEvent string `url:"state_event,omitempty"`
}
// UpdateIssue updates an existing project issue. This function is also used
// to mark an issue as closed.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/issues.html#edit-issues
func (s *IssuesService) UpdateIssue(
pid interface{},
issue int,
opt *UpdateIssueOptions) (*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)
// This is needed to get a single, comma separated string
opt.Labels = []string{strings.Join(opt.Labels, ",")}
req, err := s.client.NewRequest("PUT", u, opt)
if err != nil {
return nil, nil, err
}
i := new(Issue)
resp, err := s.client.Do(req, i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"net/url"
)
// LabelsService handles communication with the label related methods
// of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html
type LabelsService struct {
client *Client
}
// Label represents a GitLab label.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html
type Label struct {
Name string `json:"name"`
Color string `json:"color"`
}
func (l Label) String() string {
return Stringify(l)
}
// ListLabels gets all labels for given project.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#list-labels
func (s *LabelsService) ListLabels(pid interface{}) ([]*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)
if err != nil {
return nil, nil, err
}
var l []*Label
resp, err := s.client.Do(req, &l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// CreateLabelOptions represents the available CreateLabel() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#create-a-new-label
type CreateLabelOptions struct {
Name string `url:"name,omitempty"`
Color string `url:"color,omitempty"`
}
// CreateLabel creates a new label for given repository with given name and
// color.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#create-a-new-label
func (s *LabelsService) CreateLabel(
pid interface{},
opt *CreateLabelOptions) (*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)
if err != nil {
return nil, nil, err
}
l := new(Label)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
// DeleteLabelOptions represents the available DeleteLabel() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#delete-a-label
type DeleteLabelOptions struct {
Name string `url:"name,omitempty"`
}
// DeleteLabel deletes a label given by its name.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#delete-a-label
func (s *LabelsService) DeleteLabel(pid interface{}, opt *DeleteLabelOptions) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
// UpdateLabelOptions represents the available UpdateLabel() options.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#delete-a-label
type UpdateLabelOptions struct {
Name string `url:"name,omitempty"`
NewName string `url:"new_name,omitempty"`
Color string `url:"color,omitempty"`
}
// UpdateLabel updates an existing label with new name or now color. At least
// one parameter is required, to update the label.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/labels.html#edit-an-existing-label
func (s *LabelsService) UpdateLabel(
pid interface{},
opt *UpdateLabelOptions) (*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)
if err != nil {
return nil, nil, err
}
l := new(Label)
resp, err := s.client.Do(req, l)
if err != nil {
return nil, resp, err
}
return l, resp, err
}
This diff is collapsed.
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"net/url"
"time"
)
// MilestonesService handles communication with the milestone related methods
// of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/milestones.html
type MilestonesService struct {
client *Client
}
// Milestone represents a GitLab milestone.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/branches.html
type Milestone struct {
ID int `json:"id"`
Iid int `json:"iid"`
ProjectID int `json:"project_id"`
Title string `json:"title"`
Description string `json:"description"`
DueDate string `json:"due_date"`
State string `json:"state"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
}
func (m Milestone) String() string {
return Stringify(m)
}
// ListMilestonesOptions represents the available ListMilestones() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#list-project-milestones
type ListMilestonesOptions struct {
IID int `url:"iid,omitempty"`
}
// ListMilestones returns a list of project milestones.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#list-project-milestones
func (s *MilestonesService) ListMilestones(
pid interface{},
opt *ListMilestonesOptions) ([]*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)
if err != nil {
return nil, nil, err
}
var m []*Milestone
resp, err := s.client.Do(req, &m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// GetMilestone gets a single project milestone.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#get-single-milestone
func (s *MilestonesService) GetMilestone(
pid interface{},
milestone int) (*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)
if err != nil {
return nil, nil, err
}
m := new(Milestone)
resp, err := s.client.Do(req, m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// CreateMilestoneOptions represents the available CreateMilestone() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#create-new-milestone
type CreateMilestoneOptions struct {
Title string `url:"title,omitempty"`
Description string `url:"description,omitempty"`
DueDate string `url:"due_date,omitempty"`
}
// CreateMilestone creates a new project milestone.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#create-new-milestone
func (s *MilestonesService) CreateMilestone(
pid interface{},
opt *CreateMilestoneOptions) (*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)
if err != nil {
return nil, nil, err
}
m := new(Milestone)
resp, err := s.client.Do(req, m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// UpdateMilestoneOptions represents the available UpdateMilestone() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#edit-milestone
type UpdateMilestoneOptions struct {
Title string `url:"title,omitempty"`
Description string `url:"description,omitempty"`
DueDate string `url:"due_date,omitempty"`
StateEvent string `url:"state_event,omitempty"`
}
// UpdateMilestone updates an existing project milestone.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#edit-milestone
func (s *MilestonesService) UpdateMilestone(
pid interface{},
milestone int,
opt *UpdateMilestoneOptions) (*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)
if err != nil {
return nil, nil, err
}
m := new(Milestone)
resp, err := s.client.Do(req, m)
if err != nil {
return nil, resp, err
}
return m, resp, err
}
// GetMilestoneIssues gets all issues assigned to a single project milestone.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/milestones.html#get-all-issues-assigned-to-a-single-milestone
func (s *MilestonesService) GetMilestoneIssues(
pid interface{},
milestone int) ([]*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, nil)
if err != nil {
return nil, nil, err
}
var i []*Issue
resp, err := s.client.Do(req, &i)
if err != nil {
return nil, resp, err
}
return i, resp, err
}
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
// NamespacesService handles communication with the namespace related methods
// of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/namespaces.html
type NamespacesService struct {
client *Client
}
// Namespace represents a GitLab namespace.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/namespaces.html
type Namespace struct {
ID int `json:"id"`
Path string `json:"path"`
Kind string `json:"kind"`
}
func (n Namespace) String() string {
return Stringify(n)
}
// ListNamespaces gets a list of projects accessible by the authenticated user.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/namespaces.html#list-namespaces
func (s *NamespacesService) ListNamespaces() ([]*Namespace, *Response, error) {
req, err := s.client.NewRequest("GET", "namespaces", nil)
if err != nil {
return nil, nil, err
}
var n []*Namespace
resp, err := s.client.Do(req, &n)
if err != nil {
return nil, resp, err
}
return n, resp, err
}
// SearchNamespace gets all namespaces that match your string in their name
// or path.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/namespaces.html#search-for-namespace
func (s *NamespacesService) SearchNamespace(query string) ([]*Namespace, *Response, error) {
var q struct {
Search string `url:"search,omitempty"`
}
q.Search = query
req, err := s.client.NewRequest("GET", "namespaces", &q)
if err != nil {
return nil, nil, err
}
var n []*Namespace
resp, err := s.client.Do(req, &n)
if err != nil {
return nil, resp, err
}
return n, resp, err
}
This diff is collapsed.
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"bytes"
"fmt"
"net/url"
"time"
)
// ProjectSnippetsService handles communication with the project snippets
// related methods of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/project_snippets.html
type ProjectSnippetsService struct {
client *Client
}
// Snippet represents a GitLab project snippet.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/project_snippets.html
type Snippet struct {
ID int `json:"id"`
Title string `json:"title"`
FileName string `json:"file_name"`
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"`
ExpiresAt *time.Time `json:"expires_at"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
}
func (s Snippet) String() string {
return Stringify(s)
}
// ListSnippits gets a list of project snippets.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/project_snippets.html#list-snippets
func (s *ProjectSnippetsService) ListSnippits(pid interface{}) ([]*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, nil)
if err != nil {
return nil, nil, err
}
var ps []*Snippet
resp, err := s.client.Do(req, &ps)
if err != nil {
return nil, resp, err
}
return ps, resp, err
}
// GetSnippit gets a single project snippet
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/project_snippets.html#single-snippet
func (s *ProjectSnippetsService) GetSnippit(
pid interface{},
snippet int) (*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)
if err != nil {
return nil, nil, err
}
ps := new(Snippet)
resp, err := s.client.Do(req, ps)
if err != nil {
return nil, resp, err
}
return ps, resp, err
}
// CreateSnippetOptions represents the available CreateSnippet() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/project_snippets.html#create-new-snippet
type CreateSnippetOptions struct {
Title string `url:"title,omitempty"`
FileName string `url:"file_name,omitempty"`
Code string `url:"code,omitempty"`
VisibilityLevel VisibilityLevel `url:"visibility_level,omitempty"`
}
// CreateSnippet creates a new project snippet. The user must have permission
// to create new snippets.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/project_snippets.html#create-new-snippet
func (s *ProjectSnippetsService) CreateSnippet(
pid interface{},
opt *CreateSnippetOptions) (*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)
if err != nil {
return nil, nil, err
}
ps := new(Snippet)
resp, err := s.client.Do(req, ps)
if err != nil {
return nil, resp, err
}
return ps, resp, err
}
// UpdateSnippetOptions represents the available UpdateSnippet() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/project_snippets.html#update-snippet
type UpdateSnippetOptions struct {
Title string `url:"title,omitempty"`
FileName string `url:"file_name,omitempty"`
Code string `url:"code,omitempty"`
VisibilityLevel VisibilityLevel `url:"visibility_level,omitempty"`
}
// UpdateSnippet updates an existing project snippet. The user must have
// permission to change an existing snippet.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/project_snippets.html#update-snippet
func (s *ProjectSnippetsService) UpdateSnippet(
pid interface{},
snippet int,
opt *UpdateSnippetOptions) (*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)
if err != nil {
return nil, nil, err
}
ps := new(Snippet)
resp, err := s.client.Do(req, ps)
if err != nil {
return nil, resp, err
}
return ps, resp, err
}
// DeleteSnippet deletes an existing project snippet. This is an idempotent
// function and deleting a non-existent snippet still returns a 200 OK status
// code.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/project_snippets.html#delete-snippet
func (s *ProjectSnippetsService) DeleteSnippet(pid interface{}, snippet int) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
// SnippitContent returns the raw project snippet as plain text.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/project_snippets.html#snippet-content
func (s *ProjectSnippetsService) SnippitContent(
pid interface{},
snippet int) ([]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)
if err != nil {
return nil, nil, err
}
var b bytes.Buffer
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b.Bytes(), resp, err
}
This diff is collapsed.
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"bytes"
"fmt"
"net/url"
)
// RepositoriesService handles communication with the repositories related
// methods of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/repositories.html
type RepositoriesService struct {
client *Client
}
// Tag represents a GitLab repository tag.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-tags
type Tag struct {
Commit *Commit `json:"commit"`
Name string `json:"name"`
Message string `json:"message"`
}
func (r Tag) String() string {
return Stringify(r)
}
// ListTags gets a list of repository tags from a project, sorted by name in
// reverse alphabetical order.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-tags
func (s *RepositoriesService) ListTags(pid interface{}) ([]*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)
if err != nil {
return nil, nil, err
}
var t []*Tag
resp, err := s.client.Do(req, &t)
if err != nil {
return nil, resp, err
}
return t, resp, err
}
// CreateTagOptions represents the available CreateTag() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#create-a-new-tag
type CreateTagOptions struct {
TagName string `url:"tag_name,omitempty"`
Ref string `url:"ref,omitempty"`
Message string `url:"message,omitempty"`
}
// CreateTag creates a new tag in the repository that points to the supplied ref.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#create-a-new-tag
func (s *RepositoriesService) CreateTag(
pid interface{},
opt *CreateTagOptions) (*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)
if err != nil {
return nil, nil, err
}
t := new(Tag)
resp, err := s.client.Do(req, t)
if err != nil {
return nil, resp, err
}
return t, resp, err
}
// TreeNode represents a GitLab repository file or directory.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#list-repository-tree
type TreeNode struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Mode string `json:"mode"`
}
func (t TreeNode) String() string {
return Stringify(t)
}
// ListTreeOptions represents the available ListTree() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#list-repository-tree
type ListTreeOptions struct {
Path string `url:"path,omitempty"`
RefName string `url:"ref_name,omitempty"`
}
// ListTree gets a list of repository files and directories in a project.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#list-repository-tree
func (s *RepositoriesService) ListTree(
pid interface{},
opt *ListTreeOptions) ([]*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)
if err != nil {
return nil, nil, err
}
var t []*TreeNode
resp, err := s.client.Do(req, &t)
if err != nil {
return nil, resp, err
}
return t, resp, err
}
// RawFileContentOptions represents the available RawFileContent() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#raw-file-content
type RawFileContentOptions struct {
FilePath string `url:"filepath,omitempty"`
}
// RawFileContent gets the raw file contents for a file by commit SHA and path
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#raw-file-content
func (s *RepositoriesService) RawFileContent(
pid interface{},
sha string,
opt *RawFileContentOptions) ([]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)
if err != nil {
return nil, nil, err
}
var b bytes.Buffer
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b.Bytes(), resp, err
}
// RawBlobContent gets the raw file contents for a blob by blob SHA.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#raw-blob-content
func (s *RepositoriesService) RawBlobContent(
pid interface{},
sha string) ([]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)
if err != nil {
return nil, nil, err
}
var b bytes.Buffer
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b.Bytes(), resp, err
}
// ArchiveOptions represents the available Archive() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#get-file-archive
type ArchiveOptions struct {
SHA string `url:"sha,omitempty"`
}
// Archive gets an archive of the repository.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#get-file-archive
func (s *RepositoriesService) Archive(
pid interface{},
opt *ArchiveOptions) ([]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)
if err != nil {
return nil, nil, err
}
var b bytes.Buffer
resp, err := s.client.Do(req, &b)
if err != nil {
return nil, resp, err
}
return b.Bytes(), resp, err
}
// Compare represents the result of a comparison of branches, tags or commits.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#compare-branches-tags-or-commits
type Compare struct {
Commit *Commit `json:"commit"`
Commits []*Commit `json:"commits"`
Diffs []*Diff `json:"diffs"`
CompareTimeout bool `json:"compare_timeout"`
CompareSameRef bool `json:"compare_same_ref"`
}
func (c Compare) String() string {
return Stringify(c)
}
// CompareOptions represents the available Compare() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#compare-branches-tags-or-commits
type CompareOptions struct {
From string `url:"from,omitempty"`
To string `url:"to,omitempty"`
}
// Compare compares branches, tags or commits.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repositories.html#compare-branches-tags-or-commits
func (s *RepositoriesService) Compare(
pid interface{},
opt *CompareOptions) (*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)
if err != nil {
return nil, nil, err
}
c := new(Compare)
resp, err := s.client.Do(req, c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
// Contributor represents a GitLap contributor.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/repositories.html#contributer
type Contributor struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Commits int `json:"commits,omitempty"`
Additions int `json:"additions,omitempty"`
Deletions int `json:"deletions,omitempty"`
}
func (c Contributor) String() string {
return Stringify(c)
}
// Contributors gets the repository contributors list.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/repositories.html#contributer
func (s *RepositoriesService) Contributors(pid interface{}) ([]*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)
if err != nil {
return nil, nil, err
}
var c []*Contributor
resp, err := s.client.Do(req, &c)
if err != nil {
return nil, resp, err
}
return c, resp, err
}
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"net/url"
)
// RepositoryFilesService handles communication with the repository files
// related methods of the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/repository_files.html
type RepositoryFilesService struct {
client *Client
}
// File represents a GitLab repository file.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/repository_files.html
type File struct {
FileName string `json:"file_name"`
FilePath string `json:"file_path"`
Size int `json:"size"`
Encoding string `json:"encoding"`
Content string `json:"content"`
Ref string `json:"ref"`
BlobID string `json:"blob_id"`
CommitID string `json:"commit_id"`
}
func (r File) String() string {
return Stringify(r)
}
// GetFileOptions represents the available GetFile() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repository_files.html#get-file-from-respository
type GetFileOptions struct {
FilePath string `url:"file_path,omitempty"`
Ref string `url:"ref,omitempty"`
}
// GetFile allows you to receive information about a file in repository like
// name, size, content. Note that file content is Base64 encoded.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repository_files.html#get-file-from-respository
func (s *RepositoryFilesService) GetFile(
pid interface{},
opt *GetFileOptions) (*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)
if err != nil {
return nil, nil, err
}
f := new(File)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
// FileInfo represents file details of a GitLab repository file.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/repository_files.html
type FileInfo struct {
FilePath string `json:"file_path"`
BranchName string `json:"branch_name"`
}
func (r FileInfo) String() string {
return Stringify(r)
}
// CreateFileOptions represents the available CreateFile() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repository_files.html#create-new-file-in-repository
type CreateFileOptions struct {
FilePath string `url:"file_path,omitempty"`
BranchName string `url:"branch_name,omitempty"`
Encoding string `url:"encoding,omitempty"`
Content string `url:"content,omitempty"`
CommitMessage string `url:"commit_message,omitempty"`
}
// CreateFile creates a new file in a repository.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repository_files.html#create-new-file-in-repository
func (s *RepositoryFilesService) CreateFile(
pid interface{},
opt *CreateFileOptions) (*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)
if err != nil {
return nil, nil, err
}
f := new(FileInfo)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
// UpdateFileOptions represents the available UpdateFile() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repository_files.html#update-existing-file-in-repository
type UpdateFileOptions struct {
FilePath string `url:"file_path,omitempty"`
BranchName string `url:"branch_name,omitempty"`
Encoding string `url:"encoding,omitempty"`
Content string `url:"content,omitempty"`
CommitMessage string `url:"commit_message,omitempty"`
}
// UpdateFile updates an existing file in a repository
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repository_files.html#update-existing-file-in-repository
func (s *RepositoryFilesService) UpdateFile(
pid interface{},
opt *UpdateFileOptions) (*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)
if err != nil {
return nil, nil, err
}
f := new(FileInfo)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
// DeleteFileOptions represents the available DeleteFile() options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repository_files.html#delete-existing-file-in-repository
type DeleteFileOptions struct {
FilePath string `url:"file_path,omitempty"`
BranchName string `url:"branch_name,omitempty"`
CommitMessage string `url:"commit_message,omitempty"`
}
// DeleteFile deletes an existing file in a repository
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/repository_files.html#delete-existing-file-in-repository
func (s *RepositoryFilesService) DeleteFile(
pid interface{},
opt *DeleteFileOptions) (*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)
if err != nil {
return nil, nil, err
}
f := new(FileInfo)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
//
// Copyright 2015, Sander van Harmelen
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package gitlab
import (
"fmt"
"net/url"
)
// ServicesService handles communication with the services related methods of
// the GitLab API.
//
// GitLab API docs: http://doc.gitlab.com/ce/api/services.html
type ServicesService struct {
client *Client
}
// SetGitLabCIServiceOptions represents the available SetGitLabCIService()
// options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#edit-gitlab-ci-service
type SetGitLabCIServiceOptions struct {
Token string `url:"token,omitempty"`
ProjectURL string `url:"project_url,omitempty"`
}
// SetGitLabCIService sets GitLab CI service for a project.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#edit-gitlab-ci-service
func (s *ServicesService) SetGitLabCIService(
pid interface{},
opt *SetGitLabCIServiceOptions) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
// DeleteGitLabCIService deletes GitLab CI service settings for a project.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#delete-gitlab-ci-service
func (s *ServicesService) DeleteGitLabCIService(pid interface{}) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
// SetHipChatServiceOptions represents the available SetHipChatService()
// options.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#edit-hipchat-service
type SetHipChatServiceOptions struct {
Token string `url:"token,omitempty"`
Room string `url:"room,omitempty"`
}
// SetHipChatService sets HipChat service for a project
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#edit-hipchat-service
func (s *ServicesService) SetHipChatService(
pid interface{},
opt *SetHipChatServiceOptions) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
// DeleteHipChatService deletes HipChat service for project.
//
// GitLab API docs:
// http://doc.gitlab.com/ce/api/services.html#delete-hipchat-service
func (s *ServicesService) DeleteHipChatService(pid interface{}) (*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)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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