# codehost cheatsheet
Every export of @deckyard/codehost. Guides are listed in the introduction .
jennifer import "@deckyard/codehost/" as codehost;
Every verb takes a Forge first and throws a CodehostError (kind "codehost", with the HTTP status and the backend) when it fails; the generic kinds "limit", "timeout", "closed", "cancelled" and "net" (a network failure, a net.NetError) pass through as the backend threw them. A repo is owner/name, or on GitLab a full path with subgroups (group/sub/name) or a numeric id; a number is an issue's or change request's number in its repository (GitLab's iid).
# Constants
Constant Value Meaning ERROR_KIND"codehost"The kind of every error of the deck's own BACKENDS["github", "gitlab", "forgejo"]The backends a Forge can hold; Gitea goes through forgejo MERGE_STYLES["merge", "squash", "rebase"]The styles mergeChangeRequest takes; GitLab refuses rebase STATUS_STATES["pending", "success", "failure", "error"]The normalised commit-status states LABEL_COLOR"#ededed"The colour of a label the deck creates on Forgejo for setIssueLabels / addIssueLabels
# Types
# Forge
A code forge: the backend's name and its client. Only the field of its backend is set; the client there is the escape hatch for everything this deck does not cover.
Field Meaning backend as stringgithub, gitlab or forgejogithub as github.Clientthe GitHub client gitlab as gitlab.Clientthe GitLab client forgejo as forgejo.Clientthe Forgejo (or Gitea) client
# CodehostError
A failed request or a refused value.
Field Meaning kind as stringalways "codehost" (ERROR_KIND) message as stringwhat failed, starting with who reported it: github: , gitlab: , forgejo: or codehost: status as intthe HTTP status the forge answered; 0 when no answer was read and for a local check backend as stringthe backend of the Forge; "" for a Forge built without a constructor
# Repository
Field Meaning fullName as stringowner/name; GitLab's full pathowner as stringthe user, organization or (GitLab) group path name as stringthe last segment of the path description as stringthe description isPrivate as boolwhether it is not public (GitLab's internal counts as 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; on GitHub pull requests included updated as stringlast update or activity, RFC 3339
# Issue
Field Meaning number as intthe number within the repository (GitLab's iid) title as stringthe title body as stringthe text, Markdown state as stringopen or closedauthor as stringwho opened it labels as list of stringlabel names assignees as list of stringassigned user names comments as intthe comment count, without GitLab's system notes isChangeRequest as boolwhether the number is a pull request's (GitHub, Forgejo) created as stringRFC 3339 updated as stringRFC 3339 closed as stringRFC 3339; "" while open htmlUrl as stringits page
Field Meaning id as intthe comment (GitLab: note) id author as stringwho wrote it body as stringthe text, Markdown created as stringRFC 3339
# Label
Field Meaning name as stringthe name color as stringthe colour, #rrggbb description as stringthe description
# ChangeRequest
A GitHub or Forgejo pull request, a GitLab merge request.
Field Meaning number as intthe number within the repository (GitLab's iid) title as stringthe title, without a draft prefix body as stringthe text, Markdown state as stringopen, closed (without merging) or mergedauthor 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 the forge would merge it now; false unless open and not a draft, while it is computing that, and in a GitHub listing mergeSha as stringthe commit the merge left on the base branch; "" until merged htmlUrl as stringits page
# Asset
A file attached to a release; on GitLab a release link.
Field Meaning id as intthe asset (GitLab: link) id name as stringthe file name contentType as stringthe media type; "" on GitLab and Forgejo size as intbytes; 0 on GitLab downloads as intthe download count; 0 on GitLab downloadUrl as stringthe link a browser follows apiUrl as stringthe URL downloadAsset reads
# Release
Field Meaning id as intthe release id; 0 on GitLab tag as stringthe tag it is for name as stringthe title body as stringthe notes, Markdown isDraft as boolwhether it is a draft; false on GitLab isPrerelease as boolwhether it is a pre-release; false on GitLab created as stringRFC 3339 published as stringRFC 3339 (GitLab's release date); "" for a draft htmlUrl as stringits page assets as list of Assetthe attached files
# Branch
Field Meaning name as stringthe name sha as stringthe commit it points at isProtected as boolwhether a protection rule covers it
# Tag
Field Meaning name as stringthe name sha as stringthe commit it points at message as stringthe annotation; "" for a lightweight tag and in a GitHub listing; on Forgejo and Gitea a lightweight tag's is its commit's message
# Entry
Field Meaning name as stringthe name path as stringthe path from the repository root type as stringfile, dir, symlink or submodulesize as intbytes; 0 for a directory and on GitLab sha as stringthe blob or tree SHA
# CommitStatus
Field Meaning context as stringwhich check it is, e.g. ci/build state as stringone of STATUS_STATES forgeState as stringthe state as the forge reported it description as stringa short text targetUrl as stringwhere the details are creator as stringwho set it created as stringRFC 3339
# Forges
Function Returns Does codehost.connect(backend, host, token)Forgea forge by backend name (github, gitlab, forgejo), host and token ("" for anonymous); no backend import needed codehost.fromGithub(c)Forgea forge on github.com or a GitHub Enterprise Server codehost.fromGitlab(c)Forgea forge on gitlab.com or a self-managed GitLab codehost.fromForgejo(c)Forgea forge on Codeberg, a Forgejo or a Gitea
# Repositories
Function Returns Does codehost.repository(f, repo)Repositoryone repository codehost.myRepositories(f)list of Repositorythe repositories the token may reach
# Issues
Function Returns Does codehost.issues(f, repo, state)list of Issuethe issues (open, closed, all), newest first, without change requests codehost.issue(f, repo, number)Issueone issue codehost.createIssue(f, repo, title, body)Issueopen an issue codehost.closeIssue(f, repo, number)Issueclose an issue codehost.reopenIssue(f, repo, number)Issuereopen an issue codehost.comments(f, repo, number)list of Commentan issue's comments, oldest first, without GitLab's system notes codehost.comment(f, repo, number, body)Commentcomment on an issue codehost.labels(f, repo)list of Labelthe labels of a repository codehost.createLabel(f, repo, name, color, description)Labelcreate a label codehost.setIssueLabels(f, repo, number, names)list of stringreplace an issue's labels, creating missing ones codehost.addIssueLabels(f, repo, number, names)list of stringadd labels to an issue, creating missing ones codehost.removeIssueLabel(f, repo, number, name)take a label off an issue
# Change requests
Function Returns Does codehost.changeRequests(f, repo, state)list of ChangeRequestthe change requests (open, closed, merged, all), newest first codehost.changeRequest(f, repo, number)ChangeRequestone change request codehost.createChangeRequest(f, repo, head, base, title, body, isDraft)ChangeRequestopen a pull or merge request, as a draft or not; a title the forge reads as a draft needs isDraft true codehost.closeChangeRequest(f, repo, number)ChangeRequestclose it without merging codehost.reopenChangeRequest(f, repo, number)ChangeRequestreopen a closed one codehost.mergeChangeRequest(f, repo, number, style, deleteBranch)merge it (merge, squash, rebase), deleting a same-repository head branch on request codehost.changeRequestComments(f, repo, number)list of Commentits conversation, oldest first codehost.commentChangeRequest(f, repo, number, body)Commentcomment on it
# Releases
Function Returns Does codehost.releases(f, repo)list of Releasethe releases, newest first codehost.release(f, repo, tag)Releasethe release of a tag codehost.latestRelease(f, repo)Releasethe latest release codehost.createRelease(f, repo, tag, target, name, body, isPrerelease)Releasepublish a release, creating the tag when needed codehost.uploadAsset(f, repo, release, name, data)Assetattach a file (GitLab: generic package plus a release link) codehost.downloadAsset(f, asset, maxBytes)bytesdownload an asset stored on the forge, with the token
Function Returns Does codehost.branches(f, repo)list of Branchthe branches codehost.createBranch(f, repo, name, from)Branchcreate a branch; from "" for the default branch codehost.deleteBranch(f, repo, name)delete a branch codehost.tags(f, repo)list of Tagthe tags codehost.createTag(f, repo, name, target, message)Tagcreate a lightweight or annotated tag codehost.deleteTag(f, repo, name)delete a tag
# Files
Function Returns Does codehost.readFile(f, repo, path, ref, maxBytes)bytesa file's content, up to maxBytes (0 for 64 MiB, negative for no limit) codehost.writeFile(f, repo, path, data, message, branch)stringcreate or replace a file with a commit; the commit SHA codehost.deleteFile(f, repo, path, message, branch)stringdelete a file with a commit; the commit SHA codehost.listDirectory(f, repo, path, ref)list of Entrythe entries of a directory
# Commit statuses
Function Returns Does codehost.setCommitStatus(f, repo, sha, state, context, description, targetUrl)CommitStatusset a status on a commit codehost.commitStatuses(f, repo, sha)list of CommitStatusevery status set on a commit, newest first