gogitlab

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2014 License: Apache-2.0 Imports: 11 Imported by: 0

README

go-gitlab-client

go-gitlab-client is a simple client written in golang to consume gitlab API.

Build Status

##features

  • ###Projects gitlab api doc

    • list projects
    • get single project
  • ###Repositories gitlab api doc

    • list repository branches
    • get single repository branch
    • list project repository tags
    • list repository commits
    • list project hooks
    • add/get/edit/rm project hook
  • ###Users gitlab api doc

    • get single user
    • manage user keys
  • ###Deploy Keys gitlab api doc

    • list project deploy keys
    • add/get/rm project deploy key

##Installation

To install go-gitlab-client, use go get:

go get github.com/plouc/go-gitlab-client

Import the go-gitlab-client package into your code:

package whatever

import (
    "github.com/plouc/go-gitlab-client"
)

##Update

To update go-gitlab-client, use go get -u:

go get -u github.com/plouc/go-gitlab-client

##Documentation

Visit the docs at http://godoc.org/github.com/plouc/go-gitlab-client

Examples

You can play with the examples located in the examples directory

Documentation

Overview

Package github implements a simple client to consume gitlab API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivityFeed

type ActivityFeed struct {
	Title   string        `xml:"title"json:"title"`
	Id      string        `xml:"id"json:"id"`
	Link    []Link        `xml:"link"json:"link"`
	Updated time.Time     `xml:"updated,attr"json:"updated"`
	Entries []*FeedCommit `xml:"entry"json:"entries"`
}

type Branch

type Branch struct {
	Name      string        `json:"name,omitempty"`
	Protected bool          `json:"protected,omitempty"`
	Commit    *BranchCommit `json:"commit,omitempty"`
}

type BranchCommit

type BranchCommit struct {
	Id               string  `json:"id,omitempty"`
	Tree             string  `json:"tree,omitempty"`
	AuthoredDateRaw  string  `json:"authored_date,omitempty"`
	CommittedDateRaw string  `json:"committed_date,omitempty"`
	Message          string  `json:"message,omitempty"`
	Author           *Person `json:"author,omitempty"`
	Committer        *Person `json:"committer,omitempty"`
}

type Commit

type Commit struct {
	Id           string
	Short_Id     string
	Title        string
	Author_Name  string
	Author_Email string
	Created_At   string
	CreatedAt    time.Time
}

type FeedCommit

type FeedCommit struct {
	Id      string    `xml:"id"json:"id"`
	Title   string    `xml:"title"json:"title"`
	Link    []Link    `xml:"link"json:"link"`
	Updated time.Time `xml:"updated"json:"updated"`
	Author  Person    `xml:"author"json:"author"`
	Summary string    `xml:"summary"json:"summary"`
}

type Gitlab

type Gitlab struct {
	BaseUrl      string
	ApiPath      string
	RepoFeedPath string
	Token        string
	Client       *http.Client
}

func NewGitlab

func NewGitlab(baseUrl, apiPath, token string) *Gitlab

func (*Gitlab) Activity

func (g *Gitlab) Activity() (ActivityFeed, error)

func (*Gitlab) AddKey

func (g *Gitlab) AddKey(title, key string) error

func (*Gitlab) AddProjectDeployKey

func (g *Gitlab) AddProjectDeployKey(id, title, key string) error

Add deploy key to project.

POST /projects/:id/keys

Parameters:

id    The ID of a project
title The key title
key   The key value

func (*Gitlab) AddProjectHook

func (g *Gitlab) AddProjectHook(id, hook_url string, push_events, issues_events, merge_requests_events bool) error

Add new project hook.

POST /projects/:id/hooks

Parameters:

id                    The ID or NAMESPACE/PROJECT_NAME of a project
hook_url              The hook URL
push_events           Trigger hook on push events
issues_events         Trigger hook on issues events
merge_requests_events Trigger hook on merge_requests events

func (*Gitlab) AddUserKey

func (g *Gitlab) AddUserKey(id, title, key string) error

func (*Gitlab) CurrentUser

func (g *Gitlab) CurrentUser() (User, error)

func (*Gitlab) DeleteKey

func (g *Gitlab) DeleteKey(id string) error

func (*Gitlab) DeleteUser

func (g *Gitlab) DeleteUser(id string) error

func (*Gitlab) EditProjectHook

func (g *Gitlab) EditProjectHook(id, hook_id, hook_url string, push_events, issues_events, merge_requests_events bool) error

Edit existing project hook.

PUT /projects/:id/hooks/:hook_id

Parameters:

id                    The ID or NAMESPACE/PROJECT_NAME of a project
hook_id               The ID of a project hook
hook_url              The hook URL
push_events           Trigger hook on push events
issues_events         Trigger hook on issues events
merge_requests_events Trigger hook on merge_requests events

func (*Gitlab) Project

func (g *Gitlab) Project(id string) (*Project, error)

Get a specific project, identified by project ID or NAME, which is owned by the authentication user. Namespaced project may be retrieved by specifying the namespace and its project name like this:

`namespace%2Fproject-name`

func (*Gitlab) ProjectBranches

func (g *Gitlab) ProjectBranches(id string) ([]*Branch, error)

Lists all branches of a project.

func (*Gitlab) ProjectDeployKey

func (g *Gitlab) ProjectDeployKey(id, key_id string) (*PublicKey, error)

Get single project deploy key.

GET /projects/:id/keys/:key_id

Parameters:

id     The ID of a project
key_id The ID of a key

func (*Gitlab) ProjectDeployKeys

func (g *Gitlab) ProjectDeployKeys(id string) ([]*PublicKey, error)

Get list of project deploy keys.

GET /projects/:id/keys

Parameters:

id The ID of a project

func (*Gitlab) ProjectHook

func (g *Gitlab) ProjectHook(id, hook_id string) (*Hook, error)

Get single project hook.

GET /projects/:id/hooks/:hook_id

Parameters:

id      The ID of a project
hook_id The ID of a hook

func (*Gitlab) ProjectHooks

func (g *Gitlab) ProjectHooks(id string) ([]*Hook, error)

Get list of project hooks.

GET /projects/:id/hooks

Parameters:

id The ID of a project

func (*Gitlab) ProjectMembers

func (g *Gitlab) ProjectMembers(id string) ([]*Member, error)

func (*Gitlab) Projects

func (g *Gitlab) Projects() ([]*Project, error)

Get a list of projects owned by the authenticated user.

func (*Gitlab) RemoveProjectDeployKey

func (g *Gitlab) RemoveProjectDeployKey(id, key_id string) error

Remove deploy key from project

DELETE /projects/:id/keys/:key_id

Parameters:

id     The ID of a project
key_id The ID of a key

func (*Gitlab) RemoveProjectHook

func (g *Gitlab) RemoveProjectHook(id, hook_id string) error

Remove hook from project.

DELETE /projects/:id/hooks/:hook_id

Parameters:

id      The ID or NAMESPACE/PROJECT_NAME of a project
hook_id The ID of hook to delete

func (*Gitlab) RepoActivityFeed

func (g *Gitlab) RepoActivityFeed(feedPath string) ActivityFeed

func (*Gitlab) RepoBranch

func (g *Gitlab) RepoBranch(id, refName string) (*Branch, error)

Get a single project repository branch.

GET /projects/:id/repository/branches/:branch

Parameters:

id     The ID of a project
branch The name of the branch

func (*Gitlab) RepoBranches

func (g *Gitlab) RepoBranches(id string) ([]*Branch, error)

Get a list of repository branches from a project, sorted by name alphabetically.

GET /projects/:id/repository/branches

Parameters:

id The ID of a project

Usage:

branches, err := gitlab.RepoBranches("your_projet_id")
if err != nil {
	fmt.Println(err.Error())
}
for _, branch := range branches {
	fmt.Printf("%+v\n", branch)
}

func (*Gitlab) RepoCommits

func (g *Gitlab) RepoCommits(id string) ([]*Commit, error)

Get a list of repository commits in a project.

GET /projects/:id/repository/commits

Parameters:

    id      The ID of a project
	refName The name of a repository branch or tag or if not given the default branch

Usage:

commits, err := gitlab.RepoCommits("your_projet_id")
if err != nil {
	fmt.Println(err.Error())
}
for _, commit := range commits {
	fmt.Printf("%+v\n", commit)
}

func (*Gitlab) RepoRawFile

func (g *Gitlab) RepoRawFile(id, sha, filepath string) ([]byte, error)

Get Raw file content

func (*Gitlab) RepoTags

func (g *Gitlab) RepoTags(id string) ([]*Tag, error)

Get a list of repository tags from a project, sorted by name in reverse alphabetical order.

GET /projects/:id/repository/tags

Parameters:

id The ID of a project

Usage:

tags, err := gitlab.RepoTags("your_projet_id")
if err != nil {
	fmt.Println(err.Error())
}
for _, tag := range tags {
	fmt.Printf("%+v\n", tag)
}

func (*Gitlab) ResourceUrl

func (g *Gitlab) ResourceUrl(url string, params map[string]string) string

func (*Gitlab) ResourceUrlRaw

func (g *Gitlab) ResourceUrlRaw(u string, params map[string]string) (string, string)

func (*Gitlab) User

func (g *Gitlab) User(id string) (*User, error)

Get a single user.

GET /users/:id

Parameters:

id The ID of a user

Usage:

user, err := gitlab.User("your_user_id")
if err != nil {
	fmt.Println(err.Error())
}
fmt.Printf("%+v\n", user)

func (*Gitlab) UserKey

func (g *Gitlab) UserKey(id string) (*PublicKey, error)

func (*Gitlab) UserKeys

func (g *Gitlab) UserKeys() ([]*PublicKey, error)

func (*Gitlab) Users

func (g *Gitlab) Users() ([]*User, error)

type Hook

type Hook struct {
	Id           int    `json:"id,omitempty"`
	Url          string `json:"url,omitempty"`
	CreatedAtRaw string `json:"created_at,omitempty"`
}

type HookObjAttr

type HookObjAttr struct {
	Id              int       `json:"id,omitempty"`
	Title           string    `json:"title,omitempty"`
	AssigneeId      int       `json:"assignee_id,omitempty"`
	AuthorId        int       `json:"author_id,omitempty"`
	ProjectId       int       `json:"project_id,omitempty"`
	CreatedAt       time.Time `json:"created_at,omitempty"`
	UpdatedAt       time.Time `json:"updated_at,omitempty"`
	Position        int       `json:"position,omitempty"`
	BranchName      string    `json:"branch_name,omitempty"`
	Description     string    `json:"description,omitempty"`
	MilestoneId     int       `json:"milestone_id,omitempty"`
	State           string    `json:"state,omitempty"`
	IId             int       `json:"iid,omitempty"`
	TargetBranch    string    `json:"target_branch,omitempty"`
	SourceBranch    string    `json:"source_branch,omitempty"`
	SourceProjectId int       `json:"source_project_id,omitempty"`
	StCommits       string    `json:"st_commits,omitempty"`
	StDiffs         string    `json:"st_diffs,omitempty"`
	MergeStatus     string    `json:"merge_status,omitempty"`
	TargetProjectId int       `json:"target_project_id,omitempty"`
}

type HookPayload

type HookPayload struct {
	Before            string       `json:"before,omitempty"`
	After             string       `json:"after,omitempty"`
	Ref               string       `json:"ref,omitempty"`
	UserId            int          `json:"user_id,omitempty"`
	UserName          string       `json:"user_name,omitempty"`
	ProjectId         int          `json:"project_id,omitempty"`
	Repository        *hRepository `json:"repository,omitempty"`
	Commits           []hCommit    `json:"commits,omitempty"`
	TotalCommitsCount int          `json:"total_commits_count,omitempty"`
	ObjectKind        string       `json:"object_kind,omitempty"`
	ObjectAttributes  *HookObjAttr `json:"object_attributes,omitempty"`
}

func ParseHook

func ParseHook(payload []byte) (*HookPayload, error)

ParseHook parses hook payload from GitLab

func (*HookPayload) Branch

func (h *HookPayload) Branch() string

Branch returns current branch for push event hook payload This function returns empty string for any other events

func (*HookPayload) Head

func (h *HookPayload) Head() hCommit

Head returns the latest changeset for push event hook payload

type Link struct {
	Rel  string `xml:"rel,attr,omitempty"json:"rel"`
	Href string `xml:"href,attr"json:"href"`
}

type Member

type Member struct {
	Id        int
	Username  string
	Email     string
	Name      string
	State     string
	CreatedAt string `json:"created_at,omitempty"`
}

type Namespace

type Namespace struct {
	Id          int
	Name        string
	Path        string
	Description string
	Owner_Id    int
	Created_At  string
	Updated_At  string
}

type Person

type Person struct {
	Name  string `xml:"name"json:"name"`
	Email string `xml:"email"json:"email"`
}

type Project

type Project struct {
	Id                   int        `json:"id,omitempty"`
	Name                 string     `json:"name,omitempty"`
	Description          string     `json:"description,omitempty"`
	DefaultBranch        string     `json:"default_branch,omitempty"`
	Owner                *Member    `json:"owner,omitempty"`
	Public               bool       `json:"public,omitempty"`
	Path                 string     `json:"path,omitempty"`
	PathWithNamespace    string     `json:"path_with_namespace,omitempty"`
	IssuesEnabled        bool       `json:"issues_enabled,omitempty"`
	MergeRequestsEnabled bool       `json:"merge_requests_enabled,omitempty"`
	WallEnabled          bool       `json:"wall_enabled,omitempty"`
	WikiEnabled          bool       `json:"wiki_enabled,omitempty"`
	CreatedAtRaw         string     `json:"created_at,omitempty"`
	Namespace            *Namespace `json:"namespace,omitempty"`
	SshRepoUrl           string     `json:"ssh_url_to_repo"`
	HttpRepoUrl          string     `json:"http_url_to_repo"`
}

A gitlab project

type PublicKey

type PublicKey struct {
	Id           int    `json:"id,omitempty"`
	Title        string `json:"title,omitempty"`
	Key          string `json:"key,omitempty"`
	CreatedAtRaw string `json:"created_at,omitempty"`
}

type Tag

type Tag struct {
	Name      string        `json:"name,omitempty"`
	Protected bool          `json:"protected,omitempty"`
	Commit    *BranchCommit `json:"commit,omitempty"`
}

type User

type User struct {
	Id            int    `json:"id,omitempty"`
	Username      string `json:"username,omitempty"`
	Email         string `json:"email,omitempty"`
	Name          string `json:"name,omitempty"`
	State         string `json:"state,omitempty"`
	CreatedAt     string `json:"created_at,omitempty"`
	Bio           string `json:"bio,omitempty"`
	Skype         string `json:"skype,omitempty"`
	LinkedIn      string `json:"linkedin,omitempty"`
	Twitter       string `json:"twitter,omitempty"`
	ExternUid     string `json:"extern_uid,omitempty"`
	Provider      string `json:"provider,omitempty"`
	ThemeId       int    `json:"theme_id,omitempty"`
	ColorSchemeId int    `json:"color_scheme_id,color_scheme_id"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL