Skip to content
@deckyard/github

github cheatsheet

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

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

Every function that sends a request throws a GithubError (kind "github", with the HTTP status) when it fails; a list past MAX_PAGES pages, a reply over its size cap or past the JSON decoder's caps is kind "limit", a deadline kind "timeout", a connection closed under a request kind "closed", and a network failure is a net.NetError (kind "net", with reason, sent and replied), passed on unchanged. A repo is owner/name; a number is an issue or pull request number.

Constants

ConstantValueMeaning
ERROR_KIND"github"the kind of every error the deck throws
API_VERSION"2022-11-28"the REST API version every request asks for
PAGE_SIZE100entries asked for per page
MAX_PAGES1000pages a list follows before it refuses
MAX_RETRY_WAIT_MS60000the longest wait a retried GET sleeps through
MAX_SECRET_BYTES49152the longest Actions secret value, GitHub's 48 KB
USER_AGENT"jennifer-deckyard-github"the default User-Agent
MERGE_STYLES["merge", "squash", "rebase"]the ways to merge a pull request
MAX_FILE_BYTES104857600the largest maxBytes of readFile, GitHub's 100 MB raw limit
MAX_WORKFLOW_INPUTS25the most inputs dispatchWorkflow sends

Types

Client

A connection to github.com or a GitHub Enterprise Server.

FieldMeaning
url as stringthe REST base, https://api.github.com or https://host/api/v3
uploadUrl as stringwhere release assets go, https://uploads.github.com or https://host/api/uploads
graphqlUrl as stringthe GraphQL endpoint
token as stringthe token; "" for anonymous reads
userAgent as stringthe User-Agent header
tls as http.TlsOptionscertificate checking
timeoutMs as intthe idle timeout of each request; 0 for 30 s
retries as intretries of a GET answered 5xx or rate limited
allowPlainHttp as boolwhether plain http to another machine is allowed (the token then crosses the network in clear)

User

An account.

FieldMeaning
id as intthe account id
login as stringthe user name
name as stringthe display name
email as stringthe public e-mail address
isAdmin as boolwhether it administers the server (site_admin)

Repository

A repository.

FieldMeaning
id as intthe repository id
owner as stringthe owning user or organization
name as stringthe name
fullName as stringowner/name
description as stringthe description
isPrivate as boolwhether it is private
isFork as boolwhether it is a fork
isArchived as boolwhether it is archived
defaultBranch as stringe.g. main
htmlUrl as stringits page
cloneUrl as stringthe HTTPS clone URL
sshUrl as stringthe SSH clone URL
stars as intthe star count
openIssues as intopen issues and pull requests
updated as stringlast update, RFC 3339

Issue

An issue.

FieldMeaning
number as intthe number within the repository
title as stringthe title
body as stringthe text, Markdown
state as stringopen or closed
author as stringwho opened it
labels as list of stringlabel names
assignees as list of stringassigned user names
comments as intthe comment count
isPull as boolwhether it is a pull request
created as stringRFC 3339
updated as stringRFC 3339
closed as stringRFC 3339; "" while open
htmlUrl as stringits page

Comment

A comment on an issue or pull request.

FieldMeaning
id as intthe comment id
author as stringwho wrote it
body as stringthe text, Markdown
created as stringRFC 3339
htmlUrl as stringits place on the page

PullRequest

A pull request.

FieldMeaning
number as intthe number within the repository
title as stringthe title
body as stringthe text, Markdown
state as stringopen or closed
author as stringwho opened it
head as stringthe branch with the changes
base as stringthe branch it merges into
headSha as stringthe commit at the head
isDraft as boolwhether it is a draft
mergeable as boolwhether GitHub can merge it; false while GitHub is still computing it, and in a listing
merged as boolwhether it is merged
mergeSha as stringthe merge commit, or the test merge commit of an open one; "" when there is none
htmlUrl as stringits page

Asset

A file attached to a release.

FieldMeaning
id as intthe asset id
name as stringthe file name
contentType as stringthe media type it was uploaded with
size as intbytes
downloads as intthe download count
downloadUrl as stringthe browser download link
apiUrl as stringthe asset's API URL, which downloadAsset reads

Release

A release.

FieldMeaning
id as intthe release id
tag as stringthe tag it is for
name as stringthe title
body as stringthe notes, Markdown
isDraft as boolwhether it is a draft
isPrerelease as boolwhether it is a pre-release
created as stringRFC 3339
published as stringRFC 3339; "" for a draft
htmlUrl as stringits page
assets as list of Assetthe attached files

Branch

A branch.

FieldMeaning
name as stringthe name
sha as stringthe commit it points at
isProtected as boolwhether a protection rule covers it

Tag

A tag.

FieldMeaning
name as stringthe name
sha as stringthe commit it points at
message as stringthe annotation createTag wrote; "" in a listing, which does not carry it

CommitStatus

The status a CI system set on a commit.

FieldMeaning
context as stringwhich check it is, e.g. ci/build
state as stringpending, success, error or failure
description as stringa short text
targetUrl as stringwhere the details are
creator as stringwho set it
created as stringRFC 3339

CombinedStatus

The statuses of a commit, combined.

FieldMeaning
state as stringfailure, pending or success; pending when there are none
statuses as list of CommitStatusthe latest status per context

CheckRun

A check run on a commit, as GitHub Actions and other apps report them.

FieldMeaning
id as intthe check run id
name as stringe.g. build
status as stringqueued, in_progress, completed, waiting, requested or pending
conclusion as stringsuccess, failure, neutral, cancelled, skipped, timed_out or action_required; "" until completed
htmlUrl as stringits page
started as stringRFC 3339
completed as stringRFC 3339; "" until completed

WorkflowRun

A run of an Actions workflow.

FieldMeaning
id as intthe run id
name as stringthe workflow's name
event as stringwhat started it, e.g. push, workflow_dispatch
status as stringe.g. queued, in_progress, completed
conclusion as stringe.g. success, failure; "" until completed
headBranch as stringthe branch it ran on
headSha as stringthe commit it ran on
htmlUrl as stringits page
created as stringRFC 3339

Commit

A commit.

FieldMeaning
sha as stringthe commit SHA
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
htmlUrl as stringits page

Label

A label of a repository.

FieldMeaning
id as intthe label id
name as stringthe name, e.g. bug
color as stringthe colour, e.g. #d73a4a
description as stringthe description
isDefault as boolwhether GitHub created it with the repository

Milestone

A milestone of a repository. GitHub addresses it by its number.

FieldMeaning
number as intthe number within the repository
title as stringthe title
description as stringthe description
state as stringopen or closed
dueOn as stringRFC 3339; "" without a due date
openIssues as intopen issues in it
closedIssues as intclosed issues in it

Review

A review of a pull request.

FieldMeaning
id as intthe review id
author as stringwho reviewed
state as stringAPPROVED, CHANGES_REQUESTED, COMMENTED, DISMISSED or PENDING
body as stringthe text, Markdown
commitId as stringthe commit it reviewed
submitted as stringRFC 3339

ChangedFile

A file a pull request changes.

FieldMeaning
filename as stringthe path
status as stringadded, removed, modified, renamed, copied, changed or unchanged
additions as intlines added
deletions as intlines deleted
previousFilename as stringthe old path of a renamed file; "" otherwise

Hook

A webhook of a repository.

FieldMeaning
id as intthe hook id
name as stringweb for a webhook
url as stringwhere it posts to
events as list of stringthe events it fires on, e.g. push
active as boolwhether it fires

Entry

An entry of a directory in a repository.

FieldMeaning
name as stringthe name
path as stringthe path from the repository root
type as stringfile, dir, symlink or submodule
size as intbytes; 0 for a directory
sha as stringthe blob or tree SHA

RateLimit

The REST rate limit of the client's token, or of its address without one.

FieldMeaning
limit as intrequests allowed per hour
remaining as intrequests left in this hour
used as intrequests made in this hour
reset as intwhen it starts over, Unix seconds

GithubError

A failed request or a refused value. Every error of kind "github" is one, so its fields are safe to read once the kind matches.

FieldMeaning
kind as stringalways "github" (ERROR_KIND)
message as stringgithub: and what failed, for a refused request <verb> <path>: HTTP <status>: <reason>
status as intthe HTTP status GitHub answered (401, 403, 404, 409, 422, 429, ...; 200 for a GraphQL error); 0 when the failure is a local check or no usable answer was read

Connecting

FunctionReturnsDoes
github.client(address)Clientgithub.com or an Enterprise Server, without a token; requests refuse plain http to another machine
github.withPlainHttp(c)Clientallow plain http to another machine (an Enterprise Server on the LAN)
github.withToken(c, token)Clientauthenticate with a token
github.withUserAgent(c, agent)Clientsend another User-Agent
github.withCaCert(c, pem)Clienttrust a certificate
github.withInsecure(c)Clientaccept any certificate
github.withTimeout(c, ms)Clientset the idle timeout
github.withRetries(c, n)Clientretry GETs answered 5xx or rate limited with a stated wait
github.call(c, method, path, body)json.Valueany REST endpoint; body is JSON text
github.getAll(c, path)list of json.Valueevery page of a list endpoint
github.graphql(c, query, variables)json.Valuea GraphQL document; the reply's data
github.currentUser(c)Userthe token's account
github.rateLimit(c)RateLimitthe REST rate limit left

Repositories

FunctionReturnsDoes
github.repository(c, repo)Repositoryone repository
github.repositories(c, owner)list of Repositorya user's or organization's public repositories
github.myRepositories(c)list of Repositorythe token's own and shared repositories
github.createRepository(c, owner, name, description, isPrivate)Repositoryan empty repository; owner "" for the token's account
github.deleteRepository(c, repo)delete it, with no undo
github.editRepository(c, repo, description, homepage)Repositorychange them; "" keeps
github.setArchived(c, repo, archived)Repositoryarchive it or bring it back
github.setDefaultBranch(c, repo, branch)Repositorychange the default branch
github.forkRepository(c, repo, organization, name)Repositoryfork it; "" for your account, the same name
github.searchRepositories(c, query)list of RepositoryGitHub's repository search, at most 1000
github.collaborators(c, repo)list of Userthe collaborators
github.addCollaborator(c, repo, name, permission)pull, triage, push, maintain or admin
github.removeCollaborator(c, repo, name)remove one
github.hooks(c, repo)list of Hookthe webhooks
github.createHook(c, repo, url, secret, events)Hooka webhook posting JSON
github.deleteHook(c, repo, id)delete one
github.branches(c, repo)list of Branchthe branches
github.tags(c, repo)list of Tagthe tags, without annotations
github.createBranch(c, repo, name, from)Branchbranch off a ref; "" for the default branch
github.deleteBranch(c, repo, name)delete a branch
github.createTag(c, repo, name, target, message)Tagtag a ref; "" message for a lightweight tag
github.deleteTag(c, repo, name)delete a tag
github.readFile(c, repo, path, ref, maxBytes)bytesa file at a ref; "" for the default branch; maxBytes at most MAX_FILE_BYTES, 0 for 64 MiB, negative for no limit
github.writeFile(c, repo, path, data, message, branch)stringcommit a file; the commit SHA
github.deleteFile(c, repo, path, message, branch)stringdelete a file; the commit SHA
github.listDirectory(c, repo, path, ref)list of Entrya directory's entries; "" for the root

Issues and pull requests

FunctionReturnsDoes
github.issues(c, repo, state)list of Issueissues, without pull requests
github.searchIssues(c, query)list of IssueGitHub's issue search, at most 1000
github.issue(c, repo, number)Issueone issue
github.createIssue(c, repo, title, body)Issueopen an issue
github.closeIssue(c, repo, number)Issueclose an issue or pull request
github.reopenIssue(c, repo, number)Issuereopen one
github.editIssue(c, repo, number, title, body)Issuechange title or text; "" keeps
github.setAssignees(c, repo, number, names)Issueset who is assigned
github.setMilestone(c, repo, number, milestone)Issueput it in a milestone by number; 0 for none
github.comments(c, repo, number)list of Commentits comments, oldest first
github.comment(c, repo, number, body)Commentadd a comment
github.editComment(c, repo, id, body)Commentchange a comment
github.deleteComment(c, repo, id)delete a comment
github.labels(c, repo)list of Labelthe repository's labels
github.createLabel(c, repo, name, color, description)Labelcreate a label
github.deleteLabel(c, repo, name)delete a label by name
github.setIssueLabels(c, repo, number, names)list of Labelreplace its labels
github.addIssueLabels(c, repo, number, names)list of Labeladd labels
github.removeIssueLabel(c, repo, number, name)take a label off
github.milestones(c, repo, state)list of Milestonethe milestones
github.createMilestone(c, repo, title, description, dueOn)Milestonecreate one
github.setMilestoneClosed(c, repo, number, closed)Milestoneclose or reopen one
github.deleteMilestone(c, repo, number)delete one
github.pullRequests(c, repo, state)list of PullRequestpull requests
github.pullRequest(c, repo, number)PullRequestone pull request
github.createPullRequest(c, repo, head, base, title, body, isDraft)PullRequestopen a pull request, a draft with isDraft
github.mergePullRequest(c, repo, number, style, deleteBranch)merge it
github.editPullRequest(c, repo, number, title, body)PullRequestchange title or text; "" keeps
github.reviewPullRequest(c, repo, number, event, body)ReviewAPPROVE, REQUEST_CHANGES or COMMENT
github.reviews(c, repo, number)list of Reviewits reviews
github.requestReviewers(c, repo, number, names)ask users to review
github.pullRequestFiles(c, repo, number)list of ChangedFilethe files it changes

Releases

FunctionReturnsDoes
github.releases(c, repo)list of Releasethe releases, newest first
github.release(c, repo, tag)Releasethe release of a tag
github.latestRelease(c, repo)Releasethe one GitHub marks as the latest
github.createRelease(c, repo, tag, target, name, body, isPrerelease)Releasepublish a release
github.editRelease(c, repo, id, name, body)Releasechange title or notes; "" keeps
github.deleteRelease(c, repo, id)delete it; the tag stays
github.uploadAsset(c, repo, releaseId, name, contentType, data)Assetattach a file; contentType "" for application/octet-stream
github.downloadAsset(c, asset, maxBytes)bytesdownload a file; the token stays on the API host
github.deleteAsset(c, repo, assetId)delete an attached file

Commits and CI

FunctionReturnsDoes
github.commits(c, repo, ref, path)list of Commitcommits from a ref; path narrows them
github.commit(c, repo, sha)Commitone commit
github.setCommitStatus(c, repo, sha, state, context, description, targetUrl)CommitStatusreport a check on a commit
github.commitStatuses(c, repo, ref)list of CommitStatusevery status set on it, newest first
github.combinedStatus(c, repo, ref)CombinedStatusthe latest per check, and the worst
github.checkRuns(c, repo, ref)list of CheckRunthe check runs, Actions jobs among them
github.dispatchWorkflow(c, repo, workflow, ref, inputs)intrun a workflow with at most MAX_WORKFLOW_INPUTS inputs; the run id, or 0
github.workflowRun(c, repo, id)WorkflowRunone workflow run
github.secrets(c, repo)list of stringthe Actions secrets' names
github.setSecret(c, repo, name, value)seal and create or replace one
github.deleteSecret(c, repo, name)delete one
github.variables(c, repo)map of string to stringthe Actions variables
github.setVariable(c, repo, name, value)create or replace one
github.deleteVariable(c, repo, name)delete one