forge
Explore
Log in

Don't you dare go Hollow

forge

Clone
★ 0

0 watching0 forksRustAGPL-3.08.8 MiB264395dTahinli1 month ago26 commits

api.md10.8 KiBHistoryRawDownload

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 either way:

Authorization: Bearer forge_...
Authorization: token forge_...
  • A token needs the repo scope. It is the only scope the token form offers. A token without it gets 403.
  • 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 gets 404.
  • Failed authentication counts against the client IP. It shares the budget git authentication uses, so after too many failures the API answers 429 with Retry-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 failure or error gives failure;
  • otherwise any pending gives pending;
  • 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.

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": "01J...",
  "tag": "v1.2.0",
  "target": "0123...",
  "title": "v1.2.0",
  "body": "Built by CI",
  "draft": false,
  "prerelease": false,
  "author": "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": "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"
    }
  ]
}

published_at is null for a draft. download_url is the web download route, so it works with the same visibility rules as the release page.

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".