gitlab

package module
v0.0.0-...-5431f13 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2016 License: MIT Imports: 9 Imported by: 2

README

gitlab

Build Status

GitLab API client for golang

Tests

To run tests, you will need a working GitLab server.

The test code needs several info of that GitLab server, passing via environment variables:

# personal access token
export PERSONAL_TOKEN="supersecret"
# server address
export SERVER_URL="http://127.0.0.1:3333"
# api path, should be /api/v3
export API_PATH="/api/v3"
# repository name, the repository must be a mirror of
#   https://gitlab.com/Ronmi/test-project.git
# The easiest way to obtain one is importing it into
# your GitLab server.
export REPO_PATH="root/test"
# repository id, you can find it at "Trggers" page in your project settings
export REPO_ID=2

go test ./...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseTime

func ParseTime(t string) (time.Time, error)

ParseTime parses time formats in api response

Types

type APIError

type APIError int
const (
	ErrMissingAttr   APIError = 400 // at least one required attribute is missing
	ErrUnauthorized  APIError = 401 // need authorization
	ErrForbidden     APIError = 403 // action is not allowed for current user
	ErrNotFound      APIError = 404 // resource cannot be accessed
	ErrNotSupported  APIError = 405 // action is not supported
	ErrConflict      APIError = 409 // resource confliction
	ErrUnprocessable APIError = 422 // entity cannot be processed
	ErrServerError   APIError = 500 // internal server error
)

func (APIError) Error

func (e APIError) Error() string

type APIOption

type APIOption interface {
	// accepts an url.Values so we can combine multiple APIOptions by
	//   opt1.Encode(opt2.Encode(nil))
	// or even
	//   var val url.Values
	//   for _, o := range options {
	//       val = o.Encode(val)
	//   }
	Encode(v url.Values) url.Values
}

APIOption abstracts all options, so we're easier to construct requests

type Branch

type Branch struct {
	Name               string `json:"name"`
	Protected          bool   `json:"protected,omitempty"`
	DevelopersCanPush  bool   `json:"developers_can_push,omitempty"`
	DevelopersCanMerge bool   `json:"developers_can_merge,omitempty"`
	Commit             Commit `json:"commit"`
}

Branch represents info of a branch

type Commit

type Commit struct {
	// These fields are listed at
	// http://docs.gitlab.com/ce/api/commits.html#list-repository-commits
	ID           string `json:"id"`
	ShortID      string `json:"short_id,omitempty"`
	Title        string `json:"title,omitempty"`
	AuthorName   string `json:"author_name,omitempty"`
	AuthorEmail  string `json:"author_email,omitempty"`
	CreatedAt    string `json:"created_at,omitempty"`
	Message      string `json:"message,omitempty"`
	AllowFailure string `json:"allow_failure,omitempty"`

	// These fields are listed at
	// http://docs.gitlab.com/ce/api/commits.html#get-a-single-commit
	CommittedDate string      `json:"committed_date,omitempty"`
	AuthoredDate  string      `json:"authored_date,omitempty"`
	ParentIDs     []string    `json:"parent_ids,omitempty"`
	Stats         CommitStats `json:"stats,omitempty"`
	Status        string      `json:"status,omitempty"`
}

Commit represents a commit in a repository

type CommitStats

type CommitStats struct {
	Additions int `json:"additions,omitempty"`
	Deletions int `json:"deletions,omitempty"`
	Total     int `json:"total,omitempty"`
}

CommitStats represents states of a commit

type GitLab

type GitLab struct {
	// contains filtered or unexported fields
}

GitLab maps all gitlab apis to method calls

func FromOAuth

func FromOAuth(base, path string, source oauth2.TokenSource, client *http.Client) *GitLab

FromOAuth creates GitLab API client which authorized by oauth access token

func FromPAT

func FromPAT(base, path, token string, client *http.Client) *GitLab

FromPAT creates GitLab API client which authorizes by personal access token

func RawClient

func RawClient(base, path string, client *http.Client) *GitLab

RawClient creates non-wrapped GitLab API client. Since most apis need authorization, use this with caution.

Note: passing client from oauth2.Config.Client to this will make api calls authorized by oauth token.

func (*GitLab) AddProjectHook

func (g *GitLab) AddProjectHook(pid, url string, opts *ProjectHookOption) (ret Webhook, err error)

AddProjectHook add a webhook to project

func (*GitLab) CreateBranch

func (g *GitLab) CreateBranch(pid string, name, ref string) (ret Branch, err error)

CreateBranch creates new branch in a project

See http://docs.gitlab.com/ce/api/branches.html#create-repository-branch

func (*GitLab) DeleteBranch

func (g *GitLab) DeleteBranch(pid string, name string) (err error)

DeleteBranch deletes a branch from project

See http://docs.gitlab.com/ce/api/branches.html#delete-repository-branch

func (*GitLab) DeleteProjectHook

func (g *GitLab) DeleteProjectHook(pid string, hid int) (err error)

DeleteProjectHook deletes specified project webhook

func (*GitLab) EditProjectHook

func (g *GitLab) EditProjectHook(pid string, hid int, url string, opts *ProjectHookOption) (ret Webhook, err error)

EditProjectHook updates project hook info

func (*GitLab) ListBranches

func (g *GitLab) ListBranches(pid string, opts *ListOption) (ret []Branch, page *Pagination, err error)

ListBranches retrieves all branches in a project

See http://docs.gitlab.com/ce/api/branches.html#list-repository-branches

func (*GitLab) Me

func (g *GitLab) Me() (ret User, err error)

Me retrieve current user info

See http://docs.gitlab.com/ce/api/users.html#current-user

func (*GitLab) ProjectHooks

func (g *GitLab) ProjectHooks(pid string, opts *ListOption) (ret []Webhook, page *Pagination, err error)

ProjectHooks retrieves all webhooks of a project

func (*GitLab) WithOAuth

func (g *GitLab) WithOAuth(source oauth2.TokenSource) *GitLab

WithOAuth creates a new GitLab client using current http.Client and OAuth token

func (*GitLab) WithPAT

func (g *GitLab) WithPAT(token string) *GitLab

WithPAT creates a new GitLab client using current http.Client and PAT authorization

func (*GitLab) WithRaw

func (g *GitLab) WithRaw(c *http.Client) *GitLab

WithRaw creates a new non-wrapped GitLab client. See FromRaw() for caveats.

type ListOption

type ListOption struct {
	Page    int
	PerPage int
}

ListOption represents pagination related options

func (*ListOption) Encode

func (o *ListOption) Encode(v url.Values) url.Values

type Pagination

type Pagination struct {
	Total      int    // the total number of items
	TotalPages int    // the total number of pages
	PerPage    int    // the number of items per page
	Page       int    // the index of current page, started from 1
	NextPage   int    // the index of next page
	PrevPage   int    // the index of previous page
	LinkHeader string // raw Link header
}

Pagination represents pagination info from header

func ParsePagination

func ParsePagination(h http.Header) *Pagination

ParsePagination extracts pagination info from http headers

func (p *Pagination) Links() map[string]string

Links parses LinkHeader and returns a map[rel]url

This method does not test against comma and colon, since they are not expected to exist in reply of gitlab. The malformed input is also ignored. You should be aware of this.

type ProjectHookOption

type ProjectHookOption struct {
	PushEvents            bool
	IssuesEvents          bool
	MergeRequestsEvents   bool
	TagPushEvents         bool
	NoteEvents            bool
	BuildEvents           bool
	PipelineEvents        bool
	WikiPageEvents        bool
	EnableSSLVerification bool
	// contains filtered or unexported fields
}

ProjectHookOption represents optional parameters needed for AddProjectHook

func (*ProjectHookOption) Encode

func (p *ProjectHookOption) Encode(v url.Values) url.Values

type User

type User struct {
	// These fields are listed as
	// http://docs.gitlab.com/ce/api/users.html#for-normal-users
	ID        int    `json:"id"`
	Username  string `json:"username"`
	Name      string `json:"name"`
	State     string `json:"state"`
	AvatarURL string `json:"avatar_url"`
	WebURL    string `json:"web_url"`

	// These fields are listed as
	// http://docs.gitlab.com/ce/api/users.html#for-admins
	Email            string         `json:"email,omitempty"`
	CreatedAt        string         `json:"created_at,omitempty"`
	IsAdmin          bool           `json:"is_admin,omitempty"`
	Bio              string         `json:"bio,omitempty"`
	Location         string         `json:"location,omitempty"`
	Skype            string         `json:"skype,omitempty"`
	Linkedin         string         `json:"linkedin,omitempty"`
	Twitter          string         `json:"twitter,omitempty"`
	WebsiteURL       string         `json:"website_url,omitempty"`
	LastSignInAt     string         `json:"last_sign_in_at,omitempty"`
	ConfirmedAt      string         `json:"confirmed_at,omitempty"`
	ThemeID          int            `json:"theme_id,omitempty"`
	ColorThemeID     int            `json:"color_theme_id,omitempty"`
	ProjectLimit     int            `json:"project_limit,omitempty"`
	CurrentSignInAt  string         `json:"current_sign_in_at,omitempty"`
	Identities       []UserIdentity `json:"identities,omitempty"`
	CanCreateGroup   bool           `json:"can_create_group,omitempty"`
	CanCreateProject bool           `json:"can_create_project,omitempty"`
	TwoFactorEnabled bool           `json:"two_factor_enabled,omitempty"`
	External         bool           `json:"external,omitempty"`
}

User represents info of a user

type UserIdentity

type UserIdentity struct {
	Provider  string `json:"provider"`
	ExternUID string `json:"extern_uid,omitempty"`
}

UserIdentity represents an external identity of a user

type Webhook

type Webhook struct {
	// These fields are listed at
	// http://docs.gitlab.com/ce/api/projects.html#list-project-hooks
	ID                    int    `json:"id"`
	URL                   string `json:"url"`
	ProjectID             int    `json:"project_id"`
	PushEvents            bool   `json:"push_events"`
	IssuesEvents          bool   `json:"issues_events"`
	MergeRequestsEvents   bool   `json:"merge_requests_events"`
	TagPushEvents         bool   `json:"tag_push_events"`
	NoteEvents            bool   `json:"note_events"`
	BuildEvents           bool   `json:"build_events"`
	PipelineEvents        bool   `json:"pipeline_events"`
	WikiPageEvents        bool   `json:"wiki_page_events"`
	EnableSSLVerification bool   `json:"enable_ssl_verification"`
	CreatedAt             string `json:"created_at"`
}

Webhook represents a project hook

Directories

Path Synopsis
Package webhook defines payload format of GitLab webhook It also provides a simple wrapper for you to easily create applications handle webhooks.
Package webhook defines payload format of GitLab webhook It also provides a simple wrapper for you to easily create applications handle webhooks.

Jump to

Keyboard shortcuts

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