Skip to content
@deckyard/gitlab

gitlab cheatsheet

Every export of @deckyard/gitlab. Guides are listed in the introduction.

jennifer
import "@deckyard/gitlab/" as gitlab;

Every function that sends a request throws a GitlabError (kind "gitlab", with the HTTP status) when it fails; a list past MAX_PAGES pages or a reply over its size cap is kind "limit", a deadline "timeout", and a network failure is a net.NetError (kind "net", with reason, sent and replied), passed on unchanged. A project is a numeric id ("42") or a full path ("group/sub/name"); an iid is an issue's or merge request's number in its project. An iid or id below 1 is refused before anything is sent (status 0).

Constants

ConstantValueMeaning
ERROR_KIND"gitlab"The kind of every error of the deck's own
PAGE_SIZE100The entries getAll and the list verbs ask for per page, GitLab's most
MAX_PAGES1000The most pages a list follows before it refuses: 100000 entries
ACCESS_GUEST10Access level of a guest
ACCESS_PLANNER15Access level of a planner
ACCESS_REPORTER20Access level of a reporter
ACCESS_DEVELOPER30Access level of a developer
ACCESS_MAINTAINER40Access level of a maintainer
ACCESS_OWNER50Access level of an owner
HOOK_EVENTS["push", "tag_push", "issues", "confidential_issues", "note", "confidential_note", "merge_requests", "job", "pipeline", "wiki_page", "deployment", "releases"]The events a project hook can fire on, as createHook takes them
STATUS_STATES["pending", "running", "success", "failed", "canceled", "skipped"]The states setCommitStatus can set

Types

GitlabError

A failed request or a refused value.

FieldMeaning
kind as stringalways "gitlab" (ERROR_KIND)
message as stringgitlab: and what failed; for a refused request gitlab: <verb> <path>: HTTP <status>: <reason>
status as intthe HTTP status the instance answered (400, 401, 403, 404, 409, 422, ...); 0 when no answer was read or for a local check

Client

A connection to one GitLab instance.

FieldMeaning
url as stringhttps://host or https://host/path, without /api/v4
token as stringthe token; "" for anonymous reads
authHeader as stringthe header that carries it: PRIVATE-TOKEN, Authorization (OAuth, as Bearer) or JOB-TOKEN
tls as http.TlsOptionscertificate checking
timeoutMs as intthe idle timeout of each request; 0 for 30 s
retries as intretries of a GET answered 429 or 5xx

User

An account.

FieldMeaning
id as intthe user id
username as stringthe user name
name as stringthe display name
email as stringthe e-mail address, as far as the token may see it
isAdmin as boolwhether it administers the instance, as far as the token may see it
state as stringe.g. active or blocked
webUrl as stringits page

Project

A project.

FieldMeaning
id as intthe project id
name as stringthe name
path as stringthe last segment of its path
fullPath as stringgroup/sub/name
namespace as stringthe full path of its group or user
description as stringthe description
visibility as stringprivate, internal or public
isArchived as boolwhether it is archived
defaultBranch as stringe.g. main, also in an empty repository (the branch a first push creates); "" when GitLab reports none
webUrl as stringits page
httpUrl as stringthe HTTPS clone URL
sshUrl as stringthe SSH clone URL
stars as intthe star count
forks as intthe fork count
openIssues as intopen issues; 0 when issues are off
lastActivity as stringRFC 3339
forkedFrom as stringthe full path of the project it is a fork of; "" otherwise

Group

A group or subgroup.

FieldMeaning
id as intthe group id
name as stringthe name
path as stringthe last segment of its path
fullPath as stringgroup/sub
description as stringthe description
visibility as stringprivate, internal or public
parentId as intthe parent group's id; 0 for a top-level group
webUrl as stringits page

Issue

An issue.

FieldMeaning
iid as intthe number within the project
id as intthe instance-wide id
title as stringthe title
description as stringthe text, Markdown
state as stringopened or closed
author as stringwho opened it
labels as list of stringlabel names
assignees as list of stringassigned user names
milestone as stringthe milestone's title; "" for none
notes as intthe count of notes by users
isConfidential as boolwhether it is confidential
created as stringRFC 3339
updated as stringRFC 3339
closed as stringRFC 3339; "" while open
webUrl as stringits page

Note

A note (comment) on an issue or merge request.

FieldMeaning
id as intthe note id
author as stringwho wrote it
body as stringthe text, Markdown
isSystem as boolwhether GitLab wrote it for an event, such as a label change
created as stringRFC 3339
updated as stringRFC 3339

MergeRequest

A merge request.

FieldMeaning
iid as intthe number within the project
id as intthe instance-wide id
title as stringthe title
description as stringthe text, Markdown
state as stringopened, closed, locked or merged
author as stringwho opened it
sourceBranch as stringthe branch with the changes
targetBranch as stringthe branch it merges into
sha as stringthe commit at the head of the source branch
isDraft as boolwhether it is a draft
mergeStatus as stringGitLab's detailed_merge_status, e.g. mergeable, checking, conflict, not_approved, not_open
mergeable as boolwhether mergeStatus is mergeable
merged as boolwhether it is merged
mergeSha as stringthe merge commit; "" until merged or for a fast-forward merge
squashSha as stringthe squash commit; "" without one
webUrl as stringits page
created as stringRFC 3339
mergedAt as stringRFC 3339; "" until merged
sourceProjectId as intthe project the source branch is in; another than targetProjectId for a merge request from a fork
targetProjectId as intthe project it merges into

Approvals

The approval state of a merge request.

FieldMeaning
approved as boolwhether it counts as approved
approvedBy as list of stringthe user names that approved it
required as intapprovals its rules require; 0 on GitLab Free
left as intapprovals still missing; 0 on GitLab Free

ChangedFile

A file a merge request changes.

FieldMeaning
oldPath as stringthe path before
newPath as stringthe path after
isNew as boolwhether it adds the file
isRenamed as boolwhether it renames the file
isDeleted as boolwhether it deletes the file
diff as stringthe unified diff of the file; "" when GitLab left it out as too large

Release

A release.

FieldMeaning
tag as stringthe tag it is for; also its key
name as stringthe title
description as stringthe notes, Markdown
author as stringwho created it
commitSha as stringthe tagged commit
created as stringRFC 3339
released as stringRFC 3339; may lie in the future
isUpcoming as boolwhether released is in the future
webUrl as stringits page
links as list of ReleaseLinkthe attached links
sources as list of stringthe URLs of the source archives

A link attached to a release, GitLab's release asset.

FieldMeaning
id as intthe link id
name as stringthe name
url as stringwhere it points
directAssetUrl as stringits permanent URL under the release page
linkType as stringother, runbook, image or package

Branch

A branch.

FieldMeaning
name as stringthe name
sha as stringthe commit it points at
isProtected as boolwhether a protection rule covers it
isDefault as boolwhether it is the default branch
isMerged as boolwhether it is merged into the default branch

Tag

A tag.

FieldMeaning
name as stringthe name
sha as stringthe commit it points at
message as stringthe annotation; "" for a lightweight tag
isProtected as boolwhether a protection rule covers it

Commit

A commit.

FieldMeaning
sha as stringthe commit SHA
title as stringthe first line of the message
message as stringthe commit message
author as stringthe author's name, as Git records it
authorEmail as stringthe author's e-mail address
date as stringthe author date, RFC 3339
parents as list of stringthe parent SHAs
webUrl as stringits page

CommitStatus

A status set on a commit, by a pipeline job or an outside CI system.

FieldMeaning
id as intthe status id
name as stringwhich check it is, e.g. ci/build
status as stringpending, running, success, failed, canceled, skipped, or another state a pipeline job has
description as stringa short text
targetUrl as stringwhere the details are
author as stringwho set it
ref as stringthe branch or tag it was set for
created as stringRFC 3339

CombinedStatus

The statuses of a commit, combined.

FieldMeaning
status as stringthe worst state of the latest status per name; "" when there is none
statuses as list of CommitStatusthe latest status per name

Label

A label of a project.

FieldMeaning
id as intthe label id
name as stringthe name, e.g. bug or scope::ui
color as stringthe colour, e.g. #ee0701
description as stringthe description

Milestone

A milestone of a project.

FieldMeaning
id as intthe milestone id, which setMilestone takes
iid as intthe number within the project
title as stringthe title
description as stringthe description
state as stringactive or closed
dueDate as stringYYYY-MM-DD; "" without one
startDate as stringYYYY-MM-DD; "" without one
webUrl as stringits page

Hook

A hook of a project.

FieldMeaning
id as intthe hook id
url as stringwhere it posts to
events as list of stringthe events it fires on, from HOOK_EVENTS
sslVerification as boolwhether it checks the receiver's certificate

Entry

An entry of a directory in a repository.

FieldMeaning
name as stringthe name
path as stringthe path from the repository root
type as stringblob (a file), tree (a directory) or commit (a submodule)
mode as stringthe Git file mode, e.g. 100644
sha as stringthe blob or tree SHA

Pipeline

A CI/CD pipeline.

FieldMeaning
id as intthe pipeline id
iid as intthe number within the project
ref as stringthe branch or tag it ran for
sha as stringthe commit
status as stringe.g. created, pending, running, success, failed, canceled, skipped, manual
source as stringwhat started it, e.g. push, web, api, trigger, schedule
webUrl as stringits page
created as stringRFC 3339
updated as stringRFC 3339

Member

A member of a project.

FieldMeaning
id as intthe user id
username as stringthe user name
name as stringthe display name
accessLevel as intone of the ACCESS_* levels
expiresAt as stringYYYY-MM-DD; "" when it does not expire

Connecting

FunctionReturnsDoes
gitlab.client(address)Clienta client for an instance, without a token
gitlab.withToken(c, token)Clientauthenticate with a personal, project or group access token, sent as PRIVATE-TOKEN
gitlab.withBearer(c, token)Clientauthenticate with an OAuth 2 access token, sent as Authorization: Bearer
gitlab.withJobToken(c, token)Clientauthenticate with a CI/CD job token (CI_JOB_TOKEN), sent as JOB-TOKEN
gitlab.withCaCert(c, pem)Clienttrust a certificate (PEM)
gitlab.withInsecure(c)Clientaccept any certificate
gitlab.withTimeout(c, ms)Clientset the idle timeout of each request
gitlab.withRetries(c, n)Clientretry GETs answered 429 or 5xx, honouring Retry-After
gitlab.call(c, method, path, body)json.Valueany endpoint; body is JSON text
gitlab.getAll(c, path)list of json.Valueevery page of a list endpoint
gitlab.graphql(c, query, variables)json.Valuea GraphQL query or mutation at /api/graphql
gitlab.version(c)stringthe version of the instance
gitlab.currentUser(c)Userthe account the token belongs to
gitlab.user(c, username)Useran account by its user name

Projects and groups

FunctionReturnsDoes
gitlab.project(c, project)Projectone project
gitlab.userProjects(c, username)list of Projectthe projects a user owns, as far as the token may see them
gitlab.groupProjects(c, group, includeSubgroups)list of Projectthe projects of a group, as far as the token may see them
gitlab.myProjects(c)list of Projectthe projects the token's account is a member of
gitlab.searchProjects(c, query)list of Projectsearch the projects the token may see by name, path and description
gitlab.search(c, project, scope, query)list of json.Valuesearch with GitLab's search API, in one project or the whole instance
gitlab.createProject(c, namespace, name, description, visibility)Projectcreate an empty project
gitlab.deleteProject(c, project)delete a project, with its issues, merge requests and releases
gitlab.editProject(c, project, name, description)Projectchange a project's name or description
gitlab.setArchived(c, project, archived)Projectarchive a project, or bring it back
gitlab.setDefaultBranch(c, project, branch)Projectchange a project's default branch
gitlab.forkProject(c, project, namespace, name)Projectfork a project
gitlab.forks(c, project)list of Projectthe forks of a project the token may see
gitlab.group(c, group)Groupone group or subgroup
gitlab.subgroups(c, group)list of Groupthe direct subgroups of a group
gitlab.myGroups(c)list of Groupthe groups the token's account is a member of
gitlab.members(c, project)list of Memberthe direct members of a project, without those it inherits from groups
gitlab.addMember(c, project, username, accessLevel)Memberadd a member to a project, or change the access level of one
gitlab.removeMember(c, project, username)remove a member from a project
gitlab.hooks(c, project)list of Hookthe hooks of a project
gitlab.createHook(c, project, url, secret, events)Hookadd a hook that posts JSON to a URL, with certificate checking on
gitlab.deleteHook(c, project, id)delete a hook

Issues

FunctionReturnsDoes
gitlab.issues(c, project, state)list of Issuethe issues of a project, newest first
gitlab.issue(c, project, iid)Issueone issue
gitlab.createIssue(c, project, title, description)Issueopen an issue
gitlab.editIssue(c, project, iid, title, description)Issuechange an issue's title or text
gitlab.closeIssue(c, project, iid)Issueclose an issue
gitlab.reopenIssue(c, project, iid)Issuereopen an issue
gitlab.setAssignees(c, project, iid, names)Issueset who is assigned to an issue
gitlab.setMilestone(c, project, iid, milestoneId)Issueput an issue in a milestone
gitlab.setIssueLabels(c, project, iid, names)Issuereplace the labels of an issue
gitlab.addIssueLabels(c, project, iid, names)Issueadd labels to an issue
gitlab.removeIssueLabel(c, project, iid, name)Issuetake a label off an issue
gitlab.notes(c, project, iid)list of Notethe notes on an issue, oldest first, system notes included
gitlab.addNote(c, project, iid, body)Notecomment on an issue
gitlab.editNote(c, project, iid, noteId, body)Notechange the text of a note on an issue
gitlab.deleteNote(c, project, iid, noteId)delete a note on an issue
gitlab.labels(c, project)list of Labelthe labels of a project, those of its groups included
gitlab.createLabel(c, project, name, color, description)Labelcreate a label
gitlab.deleteLabel(c, project, id)delete a label, from the project and every issue and merge request
gitlab.milestones(c, project, state)list of Milestonethe milestones of a project
gitlab.createMilestone(c, project, title, description, dueDate)Milestonecreate a milestone
gitlab.setMilestoneClosed(c, project, id, closed)Milestoneclose a milestone, or make it active again
gitlab.deleteMilestone(c, project, id)delete a milestone

Merge requests

FunctionReturnsDoes
gitlab.mergeRequests(c, project, state)list of MergeRequestthe merge requests of a project, newest first
gitlab.mergeRequest(c, project, iid)MergeRequestone merge request
gitlab.createMergeRequest(c, project, sourceBranch, targetBranch, title, description)MergeRequestopen a merge request within a project
gitlab.editMergeRequest(c, project, iid, title, description)MergeRequestchange a merge request's title or text
gitlab.closeMergeRequest(c, project, iid)MergeRequestclose a merge request without merging it
gitlab.reopenMergeRequest(c, project, iid)MergeRequestreopen a closed merge request
gitlab.mergeMergeRequest(c, project, iid, sha, squash, removeSourceBranch)MergeRequestmerge a merge request now, with the project's merge method
gitlab.setReviewers(c, project, iid, names)MergeRequestset who reviews a merge request
gitlab.approvals(c, project, iid)Approvalsthe approval state of a merge request
gitlab.approveMergeRequest(c, project, iid, sha)Approvalsapprove a merge request as the token's account
gitlab.unapproveMergeRequest(c, project, iid)take back the token account's approval of a merge request
gitlab.mergeRequestChanges(c, project, iid)list of ChangedFilethe files a merge request changes, with their diffs
gitlab.mergeRequestCommits(c, project, iid)list of Committhe commits of a merge request, newest first
gitlab.mergeRequestNotes(c, project, iid)list of Notethe notes on a merge request, oldest first, system notes included
gitlab.addMergeRequestNote(c, project, iid, body)Notecomment on a merge request

Releases and packages

FunctionReturnsDoes
gitlab.releases(c, project)list of Releasethe releases of a project, newest release date first
gitlab.release(c, project, tag)Releasethe release of a tag
gitlab.latestRelease(c, project)Releasethe release with the latest release date that is not upcoming
gitlab.createRelease(c, project, tag, ref, name, description)Releasepublish a release; ref creates a missing tag
gitlab.editRelease(c, project, tag, name, description)Releasechange a release's title or notes
gitlab.deleteRelease(c, project, tag)delete a release
gitlab.addReleaseLink(c, project, tag, name, url, linkType)ReleaseLinkattach a link to a release: GitLab's release asset
gitlab.deleteReleaseLink(c, project, tag, linkId)delete a link of a release
gitlab.uploadPackageFile(c, project, packageName, version, fileName, data)stringupload to the generic package registry; the download URL
gitlab.uploadAsset(c, project, tag, packageName, fileName, data)ReleaseLinkupload a file and link it to a release
gitlab.downloadAsset(c, link, maxBytes)bytesdownload a link's target on the instance

Repository

FunctionReturnsDoes
gitlab.branches(c, project)list of Branchthe branches of a project
gitlab.createBranch(c, project, name, from)Branchcreate a branch
gitlab.deleteBranch(c, project, name)delete a branch
gitlab.tags(c, project)list of Tagthe tags of a project, newest first
gitlab.createTag(c, project, name, target, message)Tagcreate a tag
gitlab.deleteTag(c, project, name)delete a tag
gitlab.readFile(c, project, path, ref, maxBytes)bytesread a file from a repository
gitlab.writeFile(c, project, path, data, message, branch)stringcreate or replace a file with a commit of its own
gitlab.deleteFile(c, project, path, message, branch)stringdelete a file with a commit of its own
gitlab.listDirectory(c, project, path, ref)list of Entrythe entries of a directory in a repository
gitlab.listTree(c, project, path, ref)list of Entryevery file and directory below a path, at any depth
gitlab.commits(c, project, ref, path)list of Committhe commits reachable from a ref, newest first
gitlab.commit(c, project, sha)Commitone commit

CI/CD

FunctionReturnsDoes
gitlab.setCommitStatus(c, project, sha, state, name, description, targetUrl)CommitStatusset a status on a commit, as an outside CI system reports a check
gitlab.commitStatuses(c, project, sha)list of CommitStatusevery status set on a commit, newest first
gitlab.combinedStatus(c, project, sha)CombinedStatusthe latest status per name, and the worst
gitlab.pipelines(c, project, ref)list of Pipelinethe pipelines of a project, newest first
gitlab.pipeline(c, project, id)Pipelineone pipeline, with its current status
gitlab.latestPipeline(c, project, ref)Pipelinethe newest pipeline of a branch or tag
gitlab.runPipeline(c, project, ref, variables)Pipelinerun a pipeline for a branch or tag, as the token's account
gitlab.triggerPipeline(c, project, triggerToken, ref, variables)Pipelinerun a pipeline with a trigger token
gitlab.cancelPipeline(c, project, id)Pipelinecancel the running jobs of a pipeline
gitlab.retryPipeline(c, project, id)Pipelineretry the failed and canceled jobs of a pipeline
gitlab.variables(c, project)map of string to stringthe CI/CD variables of a project that apply to every environment (*)
gitlab.setVariable(c, project, name, value, masked)create or replace a CI/CD variable of a project, for every environment
gitlab.deleteVariable(c, project, name)delete the every-environment (*) CI/CD variable of a project