Skip to main content

Module api

Module api 

Source
Expand description

The JSON API read surface and repo metadata edit.

Dispatches the /api/repos, /api/repos/<owner>, /api/repos/<owner>/<repo> and /api/repos/<owner>/<repo>/{tree,blob,commits,commit} routes. Shapes follow the JSS forge JSON API (apiRepoList, apiRepoMeta, apiTree, apiBlob, apiCommits, apiCommit, apiRepoPatch), cited by name only. Strings are raw (JSON is the escape); the one exception is readme.html, which is the already-escaped output of crate::markdown.

Every ref and path is validated with crate::guard before it reaches a git argv, and git is only ever run through crate::gitrun.

Structs§

RefRow
A parsed git ref listing row.
RepoSummary
Repository summary used by the list endpoints and the HTML index.
TreeRow
One ls-tree -l row.

Constants§

DESCRIPTION_CAP
Repo description cap (JSS DESCRIPTION_CAP).
JSON_BODY_CAP
Body cap for JSON writes (JSS ISSUE_BODY_CAP + 8192).
PER_PAGE
Commits per page (JSS PER_PAGE).
RENDER_CAP
Blobs and READMEs above this are “view raw” (JSS RENDER_CAP).

Functions§

api_err
A JSON { "error": msg } response (JSS apiErr).
is_read
Is the method a read (GET / HEAD)?
is_readme_name
^readme(\.(md|markdown|txt))?$, case-insensitive.
json_resp
A JSON response with the JSS sendJson headers.
last_commit
Last commit touching path (or the ref tip when empty).
list_refs
for-each-ref over refs/heads or refs/tags, newest first.
looks_binary
Does s contain a NUL in its first 8000 bytes (git’s binary heuristic)?
ls_tree
ls-tree -z -l <ref>[:path], directories first.
read_json_body
Parse the request body as a JSON object (JSS readJsonBody): None when empty, oversized, unparseable or not an object.
repo_description
Description: git’s description file when customised, else the README first line.
split_ref_path
Longest ref-name match wins (JSS splitRefPath): ["feature","x","src"] becomes ("feature/x", ["src"]) when feature/x is a branch or tag.
unauthorised
401 with the JSS WWW-Authenticate: Bearer challenge.