| 1 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 2 | |
| 3 | package api |
| 4 | |
| 5 | import ( |
| 6 | "net/http" |
| 7 | |
| 8 | "github.com/go-chi/chi/v5" |
| 9 | |
| 10 | "github.com/tenseleyFlow/shithub/internal/version" |
| 11 | ) |
| 12 | |
| 13 | // APICapabilities is the canonical list of feature capabilities exposed |
| 14 | // by this server. Each S50 batch (§1 user, §2 repos, §3 issues, …) |
| 15 | // appends its capability name here so the CLI can gate behavior. The |
| 16 | // values are short kebab-case identifiers, GitHub-flavored when an |
| 17 | // obvious mapping exists. |
| 18 | // |
| 19 | // Append-only is a soft contract: removing an entry is a breaking |
| 20 | // change for clients that read this list. |
| 21 | var APICapabilities = []string{ |
| 22 | "pat-auth", |
| 23 | "check-runs", |
| 24 | "stars", |
| 25 | "actions-lifecycle", |
| 26 | "user-emails", |
| 27 | "ssh-keys", |
| 28 | "repos", |
| 29 | } |
| 30 | |
| 31 | type metaResponse struct { |
| 32 | Version string `json:"version"` |
| 33 | Commit string `json:"commit"` |
| 34 | BuiltAt string `json:"built_at"` |
| 35 | Capabilities []string `json:"capabilities"` |
| 36 | } |
| 37 | |
| 38 | // mountMeta registers the capability-discovery endpoint. /api/v1/meta is |
| 39 | // unauthenticated by design — clients use it to negotiate capabilities |
| 40 | // before they have credentials. |
| 41 | func (h *Handlers) mountMeta(r chi.Router) { |
| 42 | r.Get("/api/v1/meta", h.metaGet) |
| 43 | } |
| 44 | |
| 45 | func (h *Handlers) metaGet(w http.ResponseWriter, _ *http.Request) { |
| 46 | caps := make([]string, len(APICapabilities)) |
| 47 | copy(caps, APICapabilities) |
| 48 | writeJSON(w, http.StatusOK, metaResponse{ |
| 49 | Version: version.Version, |
| 50 | Commit: version.Commit, |
| 51 | BuiltAt: version.BuiltAt, |
| 52 | Capabilities: caps, |
| 53 | }) |
| 54 | } |
| 55 |