A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way
Clone or download
Permalink
Failed to load latest commit information.
examples Add a `Variables` field to CreatePipelineOptions` (#472) Sep 21, 2018
.gitignore listtagopts added params (#436) Jul 25, 2018
.travis.yml Some small fixes (#401) May 17, 2018
CHANGELOG.md Update API docs links to the current docs Aug 25, 2017
LICENSE Initial commit Mar 29, 2015
README.md Implemented license templates API (#466) Sep 11, 2018
access_requests.go Implemented access requests API (#465) Sep 10, 2018
award_emojis.go fix: create Emoji API uses "name" parameter to specify emoji (#423) Jun 21, 2018
boards.go Fix typo in BoardList struct Labels field (#344) Feb 19, 2018
branches.go Add missing list options and make using them consistent (#341) Feb 19, 2018
broadcast_messages.go fix filename typo boardcast => broadcast (#357) Mar 18, 2018
broadcast_messages_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
build_variables.go Add missing list options and make using them consistent (#341) Feb 19, 2018
build_variables_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
ci_yml_templates.go Implemented Gitlab CI YML templates API (#467) Sep 11, 2018
commits.go Adding support for 'list-merge-requests-associated-with-a-commit' (re… Aug 3, 2018
commits_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
custom_attributes.go added custom attributes (#451) Sep 6, 2018
custom_attributes_test.go added custom attributes (#451) Sep 6, 2018
deploy_keys.go Add missing list options and make using them consistent (#341) Feb 19, 2018
deployments.go Remove the OrderByValue type (#429) Jun 29, 2018
environments.go Add missing list options and make using them consistent (#341) Feb 19, 2018
event_types.go add oldrev field to Merge Request Event type. (#458) Aug 30, 2018
event_types_test.go Fix type for commit.duration in BuildEvent (#361) Mar 22, 2018
events.go Fix ListProjectContributionEvents fails with 404 error (#449) (#450) Aug 14, 2018
feature_flags.go Update documentation links Aug 25, 2017
feature_flags_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
gitignore_templates.go Add gitignore template service (#349) Feb 26, 2018
gitlab.go Implemented license templates API (#466) Sep 11, 2018
gitlab_test.go Supplement Slack service (#438) Aug 23, 2018
group_boards.go Adding support for group issue boards (#441) Aug 3, 2018
group_members.go Change ListGroupMembersOptions to be its own struct (#412) Jun 1, 2018
group_milestones.go Add group milestones methods (#371) Apr 4, 2018
group_variables.go Adding Group Variables support (#443) Aug 3, 2018
groups.go Fix issue 414 for TransferGroup. Add tests for Groups (#415) Jun 5, 2018
groups_test.go Fix issue 414 for TransferGroup. Add tests for Groups (#415) Jun 5, 2018
issue_links.go Followed go style guide recommendations to clear lint warnings (#324) Feb 10, 2018
issues.go Add weight field to UpdateIssueOptions struct (#456) Aug 24, 2018
jobs.go Implement DownloadSingleArtifactsFile (#459) Aug 30, 2018
jobs_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
keys.go Adding Keys Support (#444) Aug 3, 2018
labels.go Add missing ListOptions to ListLabels (#337) Feb 20, 2018
license_templates.go Implemented license templates API (#466) Sep 11, 2018
merge_request_approvals.go merge_request_approvals.go: Adding approvals_before_merge to MergeReq… Aug 30, 2018
merge_requests.go Add List Group Merge Requests (#462) Sep 3, 2018
milestones.go Rename to Apr 16, 2018
namespaces.go Fix Namespace struct (#325) Feb 13, 2018
notes.go Adds OrderBy/Sort to ListIssuesNotesOptions (#469) Sep 11, 2018
notifications.go Fix some typos in comments Oct 4, 2017
pages_domains.go fix typo (#358) Mar 19, 2018
pipeline_schedules.go Add a `Variables` field to CreatePipelineOptions` (#472) Sep 21, 2018
pipeline_triggers.go Add missing list options and make using them consistent (#341) Feb 19, 2018
pipeline_triggers_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
pipelines.go Add a `Variables` field to CreatePipelineOptions` (#472) Sep 21, 2018
pipelines_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
project_badges.go Implemented project badges api (#463) Sep 4, 2018
project_members.go Fix some typos in comments Oct 4, 2017
project_snippets.go Add missing list options and make using them consistent (#341) Feb 19, 2018
project_variables.go Fixing ListVariables and GetVariable function names (#445) Aug 3, 2018
projects.go add min access level to list options (#471) Sep 18, 2018
projects_test.go Add merge method constants (#410) May 30, 2018
protected_branches.go Add missing list options and make using them consistent (#341) Feb 19, 2018
repositories.go Adding missing straight option in repositories compare api (#448) Aug 3, 2018
repository_files.go Make sure GetRawFile returns []byte Dec 12, 2017
runners.go Update runners (#454) Aug 24, 2018
runners_test.go Update runners (#454) Aug 24, 2018
search.go Add search API (#335) Mar 5, 2018
services.go Supplement Slack service (#438) Aug 23, 2018
services_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
session.go Update API docs links to the current docs Aug 25, 2017
settings.go Followed go style guide recommendations to clear lint warnings (#324) Feb 10, 2018
sidekiq_metrics.go Add Sidekiq API (#331) Feb 15, 2018
snippets.go Add missing list options and make using them consistent (#341) Feb 19, 2018
strings.go Update/change a few more V3 to V4 changes (#196) Aug 25, 2017
system_hooks.go Followed go style guide recommendations to clear lint warnings (#324) Feb 10, 2018
tags.go listtagopts added params (#436) Jul 25, 2018
tags_test.go listtagopts added params (#436) Jul 25, 2018
time_stats.go Pull in the great work of @antony360 and @nicolaszordan (#198) Aug 25, 2017
todos.go Adding Todos API resource (#165) Aug 25, 2017
todos_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
users.go Add SkipReconfirmation field for ModifyUserOptions (#417) Jun 6, 2018
validate.go fix typo (#358) Mar 19, 2018
validate_test.go Allow users to pass the base URL without the API info (#404) May 22, 2018
version.go Added Version API support (#172) Aug 25, 2017
wikis.go Update some comments Oct 4, 2017

README.md

go-gitlab

A GitLab API client enabling Go programs to interact with GitLab in a simple and uniform way

Build Status GitHub license Sourcegraph GoDoc Go Report Card GitHub issues

NOTE

Release v0.6.0 (released on 25-08-2017) no longer supports the older V3 Gitlab API. If you need V3 support, please use the f-api-v3 branch. This release contains some backwards incompatible changes that were needed to fully support the V4 Gitlab API.

Coverage

This API client package covers most of the existing Gitlab API calls and is updated regularly to add new and/or missing endpoints. Currently the following services are supported:

  • Award Emojis
  • Branches
  • Broadcast Messages
  • Project-level Variables
  • Group-level Variables
  • Commits
  • Custom Attributes
  • Deployments
  • Deploy Keys
  • Environments
  • Epics
  • Epic Issues
  • Events
  • Feature flags
  • Geo Nodes
  • Gitignores templates
  • GitLab CI Config templates
  • Groups
  • Group Access Requests
  • Group Members
  • Issues
  • Issue Boards
  • Group Issue Boards
  • Jobs
  • Keys
  • Labels
  • License
  • Merge Requests
  • Merge Request Approvals
  • Project Milestones
  • Group Milestones
  • Namespaces
  • Notes (comments)
  • Discussions (threaded comments)
  • Notification settings
  • Open source license templates
  • Pages Domains
  • Pipelines
  • Pipeline Triggers
  • Pipeline Schedules
  • Projects (including setting Webhooks)
  • Project Access Requests
  • Project badges
  • Project import/export
  • Project Members
  • Project Snippets
  • Protected Branches
  • Repositories
  • Repository Files
  • Runners
  • Search
  • Services
  • Settings
  • Sidekiq metrics
  • Session
  • System Hooks
  • Tags
  • Todos
  • Users
  • Validate CI configuration
  • Version
  • Wikis

Usage

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:

git := gitlab.NewClient(nil, "yourtokengoeshere")
//git.SetBaseURL("https://git.mydomain.com/api/v3")
users, _, err := git.Users.ListUsers()

Some API methods have optional parameters that can be passed. For example, to list all projects for user "svanharmelen":

git := gitlab.NewClient(nil)
opt := &ListProjectsOptions{Search: gitlab.String("svanharmelen")}
projects, _, err := git.Projects.ListProjects(opt)

Examples

The examples directory contains a couple for clear examples, of which one is partially listed here as well:

package main

import (
	"log"

	"github.com/xanzy/go-gitlab"
)

func main() {
	git := gitlab.NewClient(nil, "yourtokengoeshere")

	// Create new project
	p := &gitlab.CreateProjectOptions{
		Name:                 gitlab.String("My Project"),
		Description:          gitlab.String("Just a test project to play with"),
		MergeRequestsEnabled: gitlab.Bool(true),
		SnippetsEnabled:      gitlab.Bool(true),
		Visibility:           gitlab.Visibility(gitlab.PublicVisibility),
	}
	project, _, err := git.Projects.CreateProject(p)
	if err != nil {
		log.Fatal(err)
	}

	// Add a new snippet
	s := &gitlab.CreateProjectSnippetOptions{
		Title:           gitlab.String("Dummy Snippet"),
		FileName:        gitlab.String("snippet.go"),
		Code:            gitlab.String("package main...."),
		Visibility:      gitlab.Visibility(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.

ToDo

  • The biggest thing this package still needs is tests 😞

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