| 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 | "issues", |
| 30 | "labels", |
| 31 | "milestones", |
| 32 | "assignees", |
| 33 | "pulls", |
| 34 | "pr-reviews", |
| 35 | "search", |
| 36 | "orgs", |
| 37 | "webhooks", |
| 38 | "branches", |
| 39 | "tags", |
| 40 | "collaborators", |
| 41 | "commits", |
| 42 | "contents", |
| 43 | "forks", |
| 44 | "notifications", |
| 45 | "watching", |
| 46 | "events", |
| 47 | "followers", |
| 48 | "actions-runs", |
| 49 | "stargazers", |
| 50 | "issue-events", |
| 51 | "device-code", |
| 52 | "actions-workflows", |
| 53 | "actions-artifacts", |
| 54 | "actions-job-logs", |
| 55 | "actions-secrets", |
| 56 | "actions-variables", |
| 57 | "actions-caches", |
| 58 | "readme", |
| 59 | "topics", |
| 60 | "merge-upstream", |
| 61 | "gpg-keys", |
| 62 | } |
| 63 | |
| 64 | type metaResponse struct { |
| 65 | Version string `json:"version"` |
| 66 | Commit string `json:"commit"` |
| 67 | BuiltAt string `json:"built_at"` |
| 68 | Capabilities []string `json:"capabilities"` |
| 69 | } |
| 70 | |
| 71 | // mountMeta registers the capability-discovery endpoint. /api/v1/meta is |
| 72 | // unauthenticated by design — clients use it to negotiate capabilities |
| 73 | // before they have credentials. |
| 74 | func (h *Handlers) mountMeta(r chi.Router) { |
| 75 | r.Get("/api/v1/meta", h.metaGet) |
| 76 | } |
| 77 | |
| 78 | func (h *Handlers) metaGet(w http.ResponseWriter, _ *http.Request) { |
| 79 | caps := make([]string, len(APICapabilities)) |
| 80 | copy(caps, APICapabilities) |
| 81 | writeJSON(w, http.StatusOK, metaResponse{ |
| 82 | Version: version.Version, |
| 83 | Commit: version.Commit, |
| 84 | BuiltAt: version.BuiltAt, |
| 85 | Capabilities: caps, |
| 86 | }) |
| 87 | } |
| 88 |