krz/hutch-stats

Server-side utility for calculating contributions for sourcehut users. contributions server sourcehut stats

Commit aebe493dcd

aebe493dcd2b46bf3ae46543f2c0e81625d93ae5

parent: e2a9508577

Verified · cmc

cmc <hello@cleberg.net> · 2026-04-11 19:36 UTC

chore: update API.md documentation

Layout: unified · split

API.md +33 −3
@@ -1,6 +1,6 @@
11# API Reference
22
3`srht-contrib` exposes a small HTTP JSON API for health checks, contribution calendar reads, manual polling, and tracked repository management.
3`srht-contrib` exposes a small HTTP JSON API for health checks, contribution calendar reads, manual polling, and optional tracked repository management.
44
55Base URL examples:
66
@@ -45,13 +45,21 @@ Contribution ranges:
4545- Contribution read endpoints return zero-filled days, so clients do not need to patch missing dates.
4646- Public contribution reads also register the actor for background indexing. A first lookup may therefore return an empty graph while the scheduler catches up.
4747
48Background polling:
49
50- When `ENABLE_SCHEDULER=true`, the service runs one poll immediately at startup and then continues polling on `POLL_INTERVAL_SECONDS`.
51- The scheduler always seeds `DEFAULT_ACTOR` as a known actor.
52- Public contribution reads register additional actors for later background polling.
53- Manual polling remains available through `POST /api/contributions/poll`.
54
4855Repository names:
4956
5057- Repository create/update accepts either:
5158 - shorthand `repo-name`
5259 - canonical `~owner/repo-name`
5360- Stored repository names are normalized to canonical `~owner/repo-name` form.
54- Tracked repositories are optional force-includes for git polling; owned repositories are auto-discovered per actor.
61- Git polling auto-discovers repositories owned by the actor through SourceHut.
62- Tracked repositories are optional force-includes for git polling; they are not required for normal owned-repository discovery.
5563
5664## Health
5765
@@ -97,6 +105,12 @@ Rules:
97105- Or provide both `from` and `to`
98106- Do not combine `year` with `from`/`to`
99107
108Behavior notes:
109
110- This endpoint resolves aliases to a canonical actor before querying data.
111- This endpoint also registers the actor for background indexing and updates the actor's `last_requested_at` timestamp.
112- The response is always immediate; it does not wait for SourceHut polling to finish.
113
100114Example by year:
101115
102116```bash
@@ -139,6 +153,12 @@ Response fields:
139153 - `count` integer contribution count for the day
140154 - `score` float weighted score for the day
141155
156Indexing state semantics:
157
158- `pending`: the actor is known but has not completed a successful poll yet
159- `indexed`: at least one successful poll has completed for the actor
160- `error`: the most recent poll attempt for the actor failed
161
142162Possible errors:
143163
144164- `400 Bad Request` for invalid or conflicting date input
@@ -169,6 +189,11 @@ Query parameters:
169189- `from` string `YYYY-MM-DD`, optional
170190- `to` string `YYYY-MM-DD`, optional
171191
192Behavior notes:
193
194- This endpoint has the same actor-registration and alias-resolution behavior as the calendar endpoint.
195- This endpoint returns immediately and does not block on SourceHut polling.
196
172197Example:
173198
174199```bash
@@ -247,6 +272,11 @@ Response fields:
247272- `inserted_events` integer: number of newly inserted normalized events
248273- `services` array of strings: currently `["todo", "git"]`
249274
275Behavior notes:
276
277- Manual polling also updates the actor's indexing metadata.
278- Git polling auto-discovers the actor's owned repositories and unions in any configured tracked repositories.
279
250280Possible errors:
251281
252282- `401 Unauthorized` if the API key is missing or invalid
@@ -272,7 +302,7 @@ Example `502`:
272302
273303All repository endpoints are protected and require `X-API-Key`.
274304
275Tracked repositories are used by git polling. Each repository is associated with an actor and stored in canonical `~owner/repo` form.
305Tracked repositories are optional force-includes for git polling. Each repository is associated with an actor and stored in canonical `~owner/repo` form.
276306
277307### `GET /api/repositories`
278308