One API over GitHub™, GitLab™ and Forgejo

Jennifer

One Jennifer script that releases a project on every forge it is mirrored to: notes, a CI gate, assets, and a check of what landed.

November 2026, by @mplx.
Based on Jennifer 0.27.0

Powered by Jennifer's Cantrip - Markdown into slide decks, https://github.com/jennifer-language/cantrip
1 / 21

Why one API

CI on all of them: One CI pipeline for GitHub, Gitea and Forgejo

2 / 21

Four decks, one import

DeckVersionTalks toIts error
@deckyard/codehost0.3.0the three belowCodehostError
@deckyard/github0.3.0github.com, Enterprise ServerGithubError
@deckyard/gitlab0.4.0gitlab.com, self-managedGitlabError
@deckyard/forgejo0.4.0Forgejo, Codeberg™, GiteaForgejoError
@deckyard/git0.2.0the local git programError{kind: "git"}
jvc add @deckyard/codehost && jvc add @deckyard/git && jvc install
3 / 21

A Forge from configuration

[[forge]]
backend = "forgejo"
host = "http://127.0.0.1:13300"
repo = "relbot/tempo"
token = "FORGEJO_TOKEN"       # the variable, never the token
def f as codehost.Forge init codehost.connect(
    toml.asString($doc, $p + "/backend"),
    toml.asString($doc, $p + "/host"),
    os.getEnv(toml.asString($doc, $p + "/token")));
4 / 21

One loop, three forges

for (def s in forges.load()) {
    def f as codehost.Forge init $s.forge;
    def r as codehost.Repository init codehost.repository($f, $s.repo);
    ...
    for (def i in codehost.issues($f, $s.repo, "open")) {
        ...
    }
}
github: relbot/tempo, default branch main
  #7 Duration parser drops seconds [bug]
forgejo: relbot/tempo, default branch main
  #1 Duration parser drops seconds []
5 / 21

What codehost normalises

GitHubGitLabForgejocodehost
issue stateopenopenedopenopen, closed
change requestpull requestmerge request, iidpull requestChangeRequest
draftflagDraft: prefixWIP: prefixisDraft
CI states46 to set, more read5pending success failure error
release assetassetlink to a packageattachmentAsset
6 / 21

Change requests

def c as codehost.ChangeRequest init codehost.createChangeRequest(
    $f, $s.repo, $fix, "main", "Print 0s for zero", "Fixes #1.", true);
...
codehost.mergeChangeRequest($f, $s.repo, $c.number, "rebase", true);
forgejo: !3 Print 0s for zero, open, draft true, mergeable false
forgejo: forgejo: POST /repos/relbot/tempo/pulls/3/merge: HTTP 405:
  Work in progress PRs cannot be merged
gitlab: !1 Print 0s for zero, open, draft true, mergeable false
gitlab: codehost: GitLab merges with the project's merge method;
  rebase is a project setting there, not a merge style
7 / 21

Releases with assets

VerbDoes
createRelease(f, repo, tag, target, name, body, pre)the tag too, at target
uploadAsset(f, repo, release, name, data)GitLab: package + link
release(f, repo, tag) / latestRelease(f, repo)read one
downloadAsset(f, asset, maxBytes)with the token, own host only
github: id 101, 2 assets
forgejo: id 2, 2 assets
gitlab: id 0, 2 assets
  SHA256SUMS, size 0
  tempo-1.3.0.tar.gz, size 0
8 / 21

The release script

jennifer run release.j work/tempo 1.3.0 \
    work/dist/tempo-1.3.0.tar.gz work/dist/SHA256SUMS
  1. Notes from the local history, with @deckyard/git
  2. Gate: refuse unless CI passed on the tagged commit, everywhere
  3. Release and upload the files, forge by forge
  4. Read back every file and compare its SHA-256

Nothing is created until every forge is green.

9 / 21

Notes from git, not from memory

    def prev as string init git.describe($r, $newTag + "~1");
    $prev = regex.replace('-[0-9]+-g[0-9a-f]+$', $prev, "");
    def text as string init "Changes since " + $prev + ":\n\n";
    for (def c in git.log($r, $prev + ".." + $newTag, "", 0)) {
        $text = $text + "- " + $c.subject + "\n";
    }
Changes since 1.2.0:

- docs: the --sum flag (#9)
- format: print 0s for zero
- parse: keep seconds (#7)
10 / 21

The gate: every check, every forge

func notGreen(s as forges.Site, commit as string) {
    def seen as list of string init [];
    def all as list of codehost.CommitStatus init
        codehost.commitStatuses($s.forge, $s.repo, $commit);
    for (def st in $all) {
        if (not lists.contains($seen, $st.context)) {
            $seen[] = $st.context;
            if ($st.state != "success") {
                return $st.context + " is " + $st.state;
            }
        }
    }
11 / 21

A red gate

$ jennifer run ci.j 9bc7e6f9efe8469c4600e486b26659d49922249b \
    ci/check pending
github: ci/check pending (pending)
forgejo: ci/check pending (pending)
gitlab: ci/check pending (pending)
$ jennifer run release.j work/tempo 1.3.0 work/dist/...
github: ci/check is pending at 9bc7e6f
forgejo: ci/check is pending at 9bc7e6f
gitlab: ci/check is pending at 9bc7e6f
not released
12 / 21

Release, upload, read back

def r as codehost.Release init codehost.createRelease(
    $f, $s.repo, $tag, $sha, $tag, $notes, false);
for (def file in $files) {
    def data as bytes init fs.readBytes($file);
    codehost.uploadAsset($f, $s.repo, $r, path.base($file), $data);
}
...
for (def a in $r.assets) {
    def got as bytes init codehost.downloadAsset($f, $a, 0);
    if (sha256($got) != $want[$a.name]) {
        stop($f.backend + ": " + $a.name + " differs");
    }
13 / 21

A green run

$ jennifer run ci.j 9bc7e6f9efe8469c4600e486b26659d49922249b \
    ci/check success
$ jennifer run release.j work/tempo 1.3.0 work/dist/...
github: released http://127.0.0.1:18080/relbot/tempo/releases/tag/1.3.0
forgejo: released http://127.0.0.1:13300/relbot/tempo/releases/tag/1.3.0
gitlab: released http://127.0.0.1:18929/relbot/tempo/-/releases/1.3.0
github: tempo-1.3.0.tar.gz ok, 330 bytes
forgejo: tempo-1.3.0.tar.gz ok, 330 bytes
gitlab: tempo-1.3.0.tar.gz ok, 330 bytes
14 / 21

Sync labels, then label issues

for (def l in $wanted) {
    if (not lists.contains($have, $l.name)) {
        codehost.createLabel(
            $f, $s.repo, $l.name, $l.color, $l.description);
        io.printf("%s: created %s\n", $f.backend, $l.name);
    }
}
forgejo: created bug              gitlab: created bug
forgejo: created release-blocker  gitlab: created release-blocker
forgejo: created docs             gitlab: created docs
forgejo: #2 docs                  gitlab: #2 docs
forgejo: #1 bug                   gitlab: #1 bug
15 / 21

Errors: one struct per deck

} catch (e) {
    if ($e.kind != codehost.ERROR_KIND) {
        throw $e;
    }
    def ce as codehost.CodehostError init $e;
    io.printf("%s %d: %s\n", $ce.backend, $ce.status, $ce.message);
}
github 422: github: POST /repos/relbot/tempo/releases: HTTP 422:
  Validation Failed (tag_name already_exists)
forgejo 409: forgejo: POST /repos/relbot/tempo/releases: HTTP 409:
  Release has no Tag
gitlab 409: gitlab: POST /projects/relbot%2Ftempo/releases: HTTP 409:
  Release already exists
16 / 21

Tokens and scopes

NeedsGitHub, fine-grainedGitLabForgejo, Gitea
readContents readread_apiread:repository
issues, labelsIssuesapiwrite:issue
releases, filesContents writeapiwrite:repository
statusesCommit statusesapiwrite:repository
forgejo 403: ... HTTP 403: token does not have at least one of
  required scope(s): [write:repository]
gitlab 403: ... HTTP 403: insufficient_scope: The request requires
  higher privileges than provided by the access token.
17 / 21

Paging and rate limits differ

GitHubGitLabForgejo
page100, Link100, X-Next-Page50, X-Total-Count
budget60 / h anonymous, 5000 with a tokenthe instance'sthe instance's
withRetriesGETs: 5xx, waits up to 60 sGETs: 429, 5xx, up to 30 sGETs: 429, 5xx

Every deck stops after 1000 pages with kind "limit".

$ jennifer run ratelimit.j
52 of 60 left
18 / 21

Plain http is an opt-in

forgejo: codehost: forgejo: plain http to "git.lan" would send
  the token in clear: use https, or withPlainHttp
github: codehost: github: plain http to "ghes.lan" would send
  the token in clear: use https, or withPlainHttp
gitlab: net: net.connect: git.lan:8929: dial tcp: lookup git.lan
  on 127.0.0.53:53: no such host
forgejo: net: net.connect: git.lan:3000: dial tcp: lookup ...
def c as forgejo.Client init forgejo.withToken(forgejo.client($lan), "TOKEN");
attempt(codehost.fromForgejo(forgejo.withPlainHttp($c)));
19 / 21

Beyond the common verbs

match ($f.backend) {
    when "github" {
        github.dispatchWorkflow($f.github, $repo, "release.yml",
            "main", {});
    }
    when "gitlab" {
        gitlab.runPipeline($f.gitlab, $repo, "main", {});
    }
    when "forgejo" {
        forgejo.dispatchWorkflow($f.forgejo, $repo, "release.yml",
            "main", {});
    }
}
20 / 21

Checklist and read more

Decks: codehost, git; talks: forge CI, your first deck

21 / 21