forge
Clone
0 watching0 forksRustAGPL-3.09.3 MiB458e219Tahinli2 hours ago353 commits
forge JSON API
A small JSON API under /api/v1. It is forge's own; it does not copy another forge's API.
The examples use the base URL from config/forge.toml, http://127.0.0.1:7660.
Authentication
Requests authenticate with a personal access token. Create one at Settings → Tokens
(/settings/tokens). Send it any of these ways:
Authorization: Bearer forge_...
Authorization: token forge_...
Authorization: Basic base64(any-name:forge_...)
The Basic form takes the token as the password and ignores the user name.
- A token needs the
reposcope. It is the only scope the token form offers. A token without it gets403. - Session cookies are never read by this API. A browser that is logged in cannot call these
routes by itself, so CSRF does not apply. Without a token, a write gets
401. - Anonymous reads of public repos need no token. Anonymous calls that cannot read a repo get
401, as git does, so a private repo looks the same as a missing one to an anonymous caller. A signed-in user with no access to a repo gets404. - Failed authentication counts against the client IP. It shares the budget git authentication
uses, so after too many failures the API answers
429withRetry-After.
Errors are JSON: {"error": "message"}.
| Status | Meaning |
|---|---|
| 400 | The body is not valid JSON. |
| 401 | No token, an unknown or expired token, or an anonymous caller who cannot use the repo. |
| 403 | The token lacks the repo scope, or the user has read-only access and tried to write. |
| 404 | The repo or the commit does not exist, or the signed-in user cannot see the repo. |
| 413 | The request body is too large: over 16 KiB for statuses, over 64 KiB for release JSON, or an asset over releases.max_asset_mb. |
| 422 | A field has an invalid value, or sha is not a full commit id. |
| 429 | Too many failed authentication attempts from this IP. |
Commit statuses
A status reports the result of one check (for example a CI job) on one commit. Each commit can have one status per context. Reporting again for the same context replaces the earlier report, so the latest report wins.
A status has these fields:
| Field | Notes |
|---|---|
state |
pending, success, failure or error. |
context |
Name of the check, 1 to 255 characters. Defaults to default. |
description |
Optional, at most 1024 characters. |
target_url |
Optional, http or https only, at most 2048 bytes. Shown as a link. |
The combined state of a commit is worked out from every context:
- any
failureorerrorgivesfailure; - otherwise any
pendinggivespending; - otherwise
success; - a commit with no statuses has
state: null.
Report a status
POST /api/v1/repos/{owner}/{repo}/statuses/{sha} needs a token with write access to the repo.
sha is the full 40-character (or 64-character, SHA-256) commit id. Upper-case hex is accepted.
curl -X POST http://127.0.0.1:7660/api/v1/repos/tahinli/demo/statuses/$SHA \
-H "Authorization: Bearer $FORGE_TOKEN" \
-H "Content-Type: application/json" \
-d '{"state": "success", "context": "ci/build", "description": "Passed in 42s",
"target_url": "https://ci.example.com/runs/7"}'
Response, 201 Created:
{
"id": "01J...",
"sha": "0123...",
"context": "ci/build",
"state": "success",
"description": "Passed in 42s",
"target_url": "https://ci.example.com/runs/7",
"created_at": "2026-10-15T10:00:00Z",
"updated_at": "2026-10-15T10:00:00Z"
}
Only state is required. A commit that is not in the repo gets 404.
Read the statuses of a commit
GET /api/v1/repos/{owner}/{repo}/commits/{sha}/statuses needs no token for a public repo. A
token is needed for a private one.
curl http://127.0.0.1:7660/api/v1/repos/tahinli/demo/commits/$SHA/statuses \
-H "Authorization: Bearer $FORGE_TOKEN"
Response, 200 OK:
{
"state": "failure",
"statuses": [
{
"id": "01J...",
"sha": "0123...",
"context": "ci/build",
"state": "failure",
"description": "2 tests failed",
"target_url": "https://ci.example.com/runs/8",
"created_at": "2026-10-15T10:05:00Z",
"updated_at": "2026-10-15T10:05:00Z"
},
{
"id": "01J...",
"sha": "0123...",
"context": "lint",
"state": "success",
"description": null,
"target_url": null,
"created_at": "2026-10-15T10:01:00Z",
"updated_at": "2026-10-15T10:01:00Z"
}
]
}
statuses is ordered by context. The list is empty and state is null when nothing has
reported on the commit.
Releases
A release names a git tag and carries notes and files. Scripts and CI jobs can manage releases
with a token. The same release can instead be published from a tag run with no script: see the
declarative [release] table in docs/ci.md.
| Method | Path | Access | Answers |
|---|---|---|---|
GET |
/api/v1/repos/{owner}/{repo}/releases |
public, or a token with read access | 200, the list, newest first |
GET |
/api/v1/repos/{owner}/{repo}/releases/tags/{tag} |
public, or a token with read access | 200, one release |
POST |
/api/v1/repos/{owner}/{repo}/releases |
write | 201, the new release |
PATCH |
/api/v1/repos/{owner}/{repo}/releases/{id} |
write | 200, the release |
DELETE |
/api/v1/repos/{owner}/{repo}/releases/{id} |
write | 204 |
PUT |
/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset} |
write | 201 when new, 200 when it replaces a file of that name |
DELETE |
/api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset} |
write | 204 |
In the asset routes {asset} is the file name for PUT and the asset id (from the release JSON)
for DELETE. GET /api/v1/repos/{owner}/{repo}/releases/{id}/assets/{asset} answers one asset, with the asset id as {asset}.
A release {id} and an asset id are the integers in the JSON; the ULID in uid works too. The list takes page and limit and always
sends X-Total-Count and Link; without them it returns everything.
Drafts are visible only to callers with write access: they are left out of the list, and fetching
one by tag gets 404 for anyone else. A release {id} must belong to the repo in the path;
another repo's id gets 404.
A release has these fields:
| Field | Notes |
|---|---|
tag |
A git tag name: letters, digits and . _ - +. |
target |
The commit the tag names. Set when the release is made. |
title |
1 to 200 characters. Defaults to the tag on create. |
body |
Notes, at most 64 KiB of text. Defaults to empty. |
draft |
A draft is hidden from readers until it is published. Defaults to false. |
prerelease |
Defaults to false. |
Release JSON
{
"id": 281474976710,
"uid": "01J...",
"tag": "v1.2.0",
"tag_name": "v1.2.0",
"target": "0123...",
"target_commitish": "0123...",
"title": "v1.2.0",
"name": "v1.2.0",
"body": "Built by CI",
"draft": false,
"prerelease": false,
"author": {"id": 5120043, "login": "tahinli", "username": "tahinli", "...": "..."},
"author_name": "tahinli",
"created_at": "2026-10-19T10:00:00Z",
"published_at": "2026-10-19T10:00:00Z",
"html_url": "http://127.0.0.1:7660/tahinli/demo/releases/tag/v1.2.0",
"assets": [
{
"id": 1099511627,
"uid": "01J...",
"name": "forge-linux-x86_64.tar.gz",
"size": 1048576,
"sha256": "9f86...",
"content_type": "application/gzip",
"download_count": 3,
"created_at": "2026-10-19T10:01:00Z",
"download_url": "http://127.0.0.1:7660/tahinli/demo/releases/download/v1.2.0/forge-linux-x86_64.tar.gz",
"browser_download_url": "http://127.0.0.1:7660/tahinli/demo/releases/download/v1.2.0/forge-linux-x86_64.tar.gz"
}
]
}
published_at is null for a draft. download_url (also sent as browser_download_url) is the
web download route, so it works with the same visibility rules as the release page, and it
accepts a token (Authorization: token, Bearer or Basic) for private repos. id is an integer and author is a user object. uid and author_name keep the forge values.
Create a release
POST /api/v1/repos/{owner}/{repo}/releases takes JSON. Only tag is required. target is a
branch name or a full commit id; it is used only when the tag does not exist yet, and it defaults
to the default branch. An existing tag is adopted as it is. A second release for the same tag
gets 409.
curl -X POST http://127.0.0.1:7660/api/v1/repos/tahinli/demo/releases \
-H "Authorization: Bearer $FORGE_TOKEN" \
-H "Content-Type: application/json" \
-d '{"tag": "v1.2.0", "target": "main", "title": "Version 1.2", "body": "Fixes.", "draft": true}'
Edit a release
PATCH .../releases/{id} changes only the fields it sends. Omitted fields keep their values.
tag renames the release. A published release keeps its tag, so it must pick a new one; a draft
can also move its tag with target.
curl -X PATCH http://127.0.0.1:7660/api/v1/repos/tahinli/demo/releases/$ID \
-H "Authorization: Bearer $FORGE_TOKEN" \
-H "Content-Type: application/json" \
-d '{"draft": false}'
Get releases
curl http://127.0.0.1:7660/api/v1/repos/tahinli/demo/releases/tags/v1.2.0
Upload an asset
PUT .../releases/{id}/assets/{asset} sends the file as the raw request body. The body is
streamed to storage, so large files are not held in memory. Content-Type is stored as the
asset's content type; a missing one is stored as application/octet-stream. The name may use
letters, digits and . _ - +. An upload over releases.max_asset_mb gets 413. Uploading the
same name again replaces the file and keeps its download count.
curl -X PUT http://127.0.0.1:7660/api/v1/repos/tahinli/demo/releases/$ID/assets/forge-linux-x86_64.tar.gz \
-H "Authorization: Bearer $FORGE_TOKEN" \
-H "Content-Type: application/gzip" \
--data-binary @dist/forge-linux-x86_64.tar.gz
Delete an asset or a release
curl -X DELETE http://127.0.0.1:7660/api/v1/repos/tahinli/demo/releases/$ID/assets/$ASSET_ID \
-H "Authorization: Bearer $FORGE_TOKEN"
curl -X DELETE http://127.0.0.1:7660/api/v1/repos/tahinli/demo/releases/$ID \
-H "Authorization: Bearer $FORGE_TOKEN"
Deleting a release removes its files. The git tag is kept.
CI job script
A job that builds artifacts and publishes them as a release. The token is a repo secret named
FORGE_TOKEN with the repo scope, and the job exposes it as an environment variable. The
release is created as a draft, the files are uploaded, and only then is it published, so readers
never see a half-filled release. The script needs curl and jq.
#!/bin/sh
set -eu
BASE="http://127.0.0.1:7660/api/v1/repos/tahinli/demo"
AUTH="Authorization: Bearer $FORGE_TOKEN"
TAG="v1.2.0"
SHA="$(git rev-parse HEAD)"
cargo build --release
mkdir -p dist
cp target/release/forge dist/forge-linux-x86_64
tar -C dist -czf dist/forge-linux-x86_64.tar.gz forge-linux-x86_64
# 1. Create the release as a draft on this commit.
ID="$(curl -fsS -X POST "$BASE/releases" -H "$AUTH" -H "Content-Type: application/json" \
-d "{\"tag\": \"$TAG\", \"target\": \"$SHA\", \"draft\": true}" | jq -r .id)"
# 2. Upload each file. A re-run replaces files of the same name.
for file in dist/forge-linux-x86_64.tar.gz; do
curl -fsS -X PUT "$BASE/releases/$ID/assets/$(basename "$file")" -H "$AUTH" \
-H "Content-Type: application/octet-stream" --data-binary "@$file" > /dev/null
done
# 3. Publish.
curl -fsS -X PATCH "$BASE/releases/$ID" -H "$AUTH" -H "Content-Type: application/json" \
-d '{"draft": false}' > /dev/null
echo "published $TAG"
If the job runs on the tag itself, the tag already exists and target is ignored. A simpler
alternative needs no script at all: a [release] table in ci.toml publishes the release from
a tag run and attaches the selected artifacts. See docs/ci.md, "Releases".
Tags
POST /api/v1/repos/{owner}/{repo}/tags {"tag_name": "v0.5.0", "target": "main"}
GET /api/v1/repos/{owner}/{repo}/tags?limit=<n>
Creating needs write access: a token with repo scope from a user who can push. target is a
branch name or a full commit sha and defaults to the default branch. The tag is lightweight. The
answer is 201 {"name": "v0.5.0", "sha": "<commit>"}, 409 when the tag exists, 422 for a bad
name or target. A tag made here runs the same post-update path as a git push of the tag, so CI
[on] tags, [release], webhooks and push mirrors all fire.
The list needs read access, is newest commit first, and gives [{"name", "sha"}]. limit
defaults to 30, at most 100.
CI runs
Read-only. The same read access as the run page: anonymous on a public repository, a token with
repo scope otherwise.
GET /api/v1/repos/{owner}/{repo}/ci/runs?ref=<ref>&limit=<n>
GET /api/v1/repos/{owner}/{repo}/ci/runs/{run_number}
GET /api/v1/repos/{owner}/{repo}/ci/runs/{run_number}/events
The list is newest first. ref is optional and matches a full ref (refs/tags/v1.2.0) or a short
branch or tag name (v1.2.0). limit defaults to 20, at most 100.
A run:
{
"number": 42,
"ref": "refs/tags/v1.2.0",
"sha": "4f1c…",
"trigger": "push",
"state": "running",
"created_at": "2026-12-01T19:00:00Z",
"started_at": "2026-12-01T19:00:04Z",
"finished_at": null,
"jobs": [
{
"id": "01k…",
"name": "build (x86_64-v3-linux)",
"state": "running",
"started_at": "2026-12-01T19:00:04Z",
"finished_at": null,
"exit_code": null,
"steps": [
{ "name": "fetch", "state": "success", "started_at": "…", "finished_at": "…" },
{ "name": "build", "state": "running", "started_at": "…", "finished_at": null }
]
}
]
}
Run states: waiting_approval, queued, running, success, failure, cancelled, error.
Job states: blocked (waiting on needs), queued, running, success, failure, cancelled,
error, skipped. Step states: running, success, failure, cancelled. Steps come from ::group::
markers in the job log. started_at of the run is its first job's start.
events is a server-sent event stream. It sends event: run with the whole run JSON on connect and
again whenever it changes, and ends after the run reaches a finished state. Close it then: a
browser EventSource would otherwise reconnect and get the final state again.
A job's log streams from GET /{owner}/{repo}/ci/jobs/{job_id}/events?plain=1, with the same access
rules. event: log carries whole lines of plain text (ANSI codes stripped); its id is the byte
offset after the chunk, so reconnecting with Last-Event-ID (or ?from=<offset>) resumes without
gaps or repeats. event: changed tells a browser to re-render the page and can be ignored by an API
client: job state comes from the run stream. The stream stays open after the job ends; close it
when the run JSON shows the job finished. GET /{owner}/{repo}/ci/jobs/{job_id}/log.txt returns the
whole log at once.