Go · 1967 bytes Raw Blame History
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 }
62
63 type metaResponse struct {
64 Version string `json:"version"`
65 Commit string `json:"commit"`
66 BuiltAt string `json:"built_at"`
67 Capabilities []string `json:"capabilities"`
68 }
69
70 // mountMeta registers the capability-discovery endpoint. /api/v1/meta is
71 // unauthenticated by design — clients use it to negotiate capabilities
72 // before they have credentials.
73 func (h *Handlers) mountMeta(r chi.Router) {
74 r.Get("/api/v1/meta", h.metaGet)
75 }
76
77 func (h *Handlers) metaGet(w http.ResponseWriter, _ *http.Request) {
78 caps := make([]string, len(APICapabilities))
79 copy(caps, APICapabilities)
80 writeJSON(w, http.StatusOK, metaResponse{
81 Version: version.Version,
82 Commit: version.Commit,
83 BuiltAt: version.BuiltAt,
84 Capabilities: caps,
85 })
86 }
87