forge
Clone
0 watching0 forksRustAGPL-3.010.5 MiBc3c44bbTahinli3 hours ago330 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. The Gitea routes below
also take ?access_token=forge_....
- 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
(Gitea's route), 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 and author
have Gitea's shapes (an integer and a user object) so Gitea clients can read them; 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".
Moving to Forgejo or Gitea
Forgejo and Gitea can pull a repo out of forge with its issues, comments, pull requests, reviews,
labels, milestones and releases (with their files). They do it through their own "Gitea"
migration, which talks to a read-only subset of the Gitea API that forge serves under
/api/v1.
- In forge, open Settings → Tokens and create a token for the account that can read the repo. A token sees exactly what its user sees, so for a private repo use an account with access.
- In Forgejo or Gitea, choose New migration, then Gitea.
- Set Migrate / Clone from URL to the repo's address on forge, for example
https://forge.example.com/tahinli/demo. It must start with thebase_urlofconfig/forge.toml. - Paste the token into Access token. Leave user name and password empty.
- Tick what to bring: Issues, Pull requests, Labels, Milestones, Releases. Choose the owner and name on the new server, then start.
The target server must be allowed to reach forge. Forgejo and Gitea refuse local and private
addresses by default; when forge runs on one, add ALLOW_LOCALNETWORKS = true under
[migrations] in the target's app.ini.
What the routes answer (all GET, paged with page and limit, at most 50 per page, with
X-Total-Count and Link headers):
| Path | Notes |
|---|---|
/api/v1/version |
{"version": "1.22.0"}, high enough for the downloader to ask for reactions, reviews and pull request head commits. |
/api/v1/settings/api |
max_response_items 50. |
/api/v1/repos/{owner}/{repo} |
Name, description, privacy, default branch, clone_url. For a private repo read with a token, clone_url carries the token as the password (user oauth2) so the target can clone. |
.../topics |
Always empty. |
.../labels, .../milestones |
state=all works for milestones. |
.../releases, .../releases/{id}/assets/{asset} |
Assets download from browser_download_url; a token is accepted there. |
.../issues |
type=issues or type=pulls, state=open, closed or all. Labels, milestone and assignees included. |
.../issues/{index}/comments |
Pull request comments too. |
.../issues/{index}/reactions, .../issues/comments/{id}/reactions |
Forge keeps the first ten users per emoji, so a busy emoji is cut short. |
.../pulls |
Head and base refs and commits, merge state. |
.../pulls/{index}/reviews, .../pulls/{index}/reviews/{id}/comments |
Approvals, requested changes, line comments. Pending reviews are never shown. |
Git over HTTP accepts the same token as the Basic password, with your user name, oauth2 or
x-access-token as the name.
Not carried over: topics, wiki and LFS objects (the clone brings the code only), user emails and avatars (people arrive as plain user names, so the target creates placeholders you can re-map), team reviews, discussions, snippets, CI runs and secrets.