diff --git a/CHANGELOG.md b/CHANGELOG.md index 991bbd46..17630b10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ### Added - **`kit health` now covers all three git hosts: GitLab CI and Bitbucket Pipelines sensors (GitHub was already there).** Both probe the platform REST API via a new `httpGet` on `HealthDeps` (the HTTP-probe path the sentinel design anticipated): GitLab `GET /api/v4/projects/:path/pipelines` with `GITLAB_TOKEN`, Bitbucket `GET /2.0/repositories/:ws/:repo/pipelines/` with `BITBUCKET_TOKEN` (or `BITBUCKET_USERNAME` + `BITBUCKET_APP_PASSWORD`). Each flags the most recent terminal pipeline as red when it failed, records the `host/path` it checked, and reports `unknown` (never a false `green`) on a missing token, a non-OK response, or no git remote. Sensors are selected by CI-file presence (`.gitlab-ci.yml` / `bitbucket-pipelines.yml`). Also: `analyze`'s CI-file detection now recognizes `bitbucket-pipelines.yml` (it knew `.github/workflows` + `.gitlab-ci.yml` but missed Bitbucket). Live API smoke is pending a real GitLab/Bitbucket project + tokens; the parsers + auth + remote-parsing are fixture-tested against the documented schemas. +- **Context-lock now covers GitLab and Bitbucket, not just GitHub.** `[context.gitlab]` (`group`, `remote`) and `[context.bitbucket]` (`workspace`, `remote`) join `[context.github]`: `kit context check` parses the live `origin` remote per host and verifies it matches the declared values, so a repo pushed to the wrong GitLab group or Bitbucket workspace is a mismatch, not a silent pass (same cross-account guard as GitHub). The brownfield `kit init` offer (`suggestContextToml` / `hasLockableContext`) now also surfaces a detected GitLab/Bitbucket binding. One `(tool, field)` row each — the lock table stays data-driven. - **Two services in the registry: Keycloak and Atlassian (acli).** Keycloak is detected from its clients (`keycloak-js`, `keycloak-connect`, `keycloak-admin-client`, `keycloak-angular`, `python-keycloak`, Go `gocloak`) and declares its realm/admin secrets (`KEYCLOAK_URL`, `KEYCLOAK_REALM`, `KEYCLOAK_CLIENT_ID/SECRET`, `KEYCLOAK_ADMIN/_PASSWORD`); it carries no mise tool because it is a self-hosted server (run via Docker), with admin through the server's own `kcadm.sh`. Atlassian is detected from `bitbucket-pipelines.yml` / `.bitbucket`, provisions the Atlassian CLI via mise (`tool: acli` → `aqua:atlassian.com/acli`), and tracks `ATLASSIAN_API_TOKEN` / `ATLASSIAN_SITE_URL`; its auth is left as an informational note rather than a guessed login command. Adding each was a single registry data row (no detector/generator edits), per the unified-registry design. ### Fixed diff --git a/src/config.ts b/src/config.ts index 569a5ee9..8f3b38e1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -260,6 +260,8 @@ export interface ContextConfig { gcloud?: { account?: string; project?: string; config?: string; region?: string }; vercel?: { team?: string; project?: string }; github?: { org?: string; remote?: string }; + gitlab?: { group?: string; remote?: string }; + bitbucket?: { workspace?: string; remote?: string }; git?: { email?: string }; npm?: { registry?: string }; } @@ -502,6 +504,14 @@ const kitConfigSchema = z .object({ org: z.string().optional(), remote: z.string().optional() }) .passthrough() .optional(), + gitlab: z + .object({ group: z.string().optional(), remote: z.string().optional() }) + .passthrough() + .optional(), + bitbucket: z + .object({ workspace: z.string().optional(), remote: z.string().optional() }) + .passthrough() + .optional(), git: z.object({ email: z.string().optional() }).passthrough().optional(), npm: z.object({ registry: z.string().optional() }).passthrough().optional(), }) diff --git a/src/context-lock.test.ts b/src/context-lock.test.ts index 7d7e813f..e9ddb16e 100644 --- a/src/context-lock.test.ts +++ b/src/context-lock.test.ts @@ -3,6 +3,8 @@ import assert from "node:assert/strict"; import { compareContext, parseGithubRemote, + parseGitlabRemote, + parseBitbucketRemote, planContext, parseGcloudProject, suggestContextToml, @@ -67,6 +69,43 @@ describe("context lock", () => { assert.deepEqual(parseGithubRemote("https://gitlab.com/x/y"), { org: null, remote: null }); }); + it("parses gitlab group + remote (incl. subgroups), and ignores non-gitlab hosts", () => { + assert.deepEqual(parseGitlabRemote("git@gitlab.com:acme/team/web.git"), { + group: "acme", + remote: "gitlab.com/acme/team/web", + }); + assert.deepEqual(parseGitlabRemote("https://gitlab.com/acme/web"), { + group: "acme", + remote: "gitlab.com/acme/web", + }); + assert.deepEqual(parseGitlabRemote("git@github.com:acme/web.git"), { group: null, remote: null }); + }); + + it("parses bitbucket workspace + remote, and ignores non-bitbucket hosts", () => { + assert.deepEqual(parseBitbucketRemote("git@bitbucket.org:acme/web.git"), { + workspace: "acme", + remote: "bitbucket.org/acme/web", + }); + assert.deepEqual(parseBitbucketRemote("https://x@bitbucket.org/acme/web"), { + workspace: "acme", + remote: "bitbucket.org/acme/web", + }); + assert.deepEqual(parseBitbucketRemote("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/acme/web"), { workspace: null, remote: null }); + }); + + it("locks a gitlab group: only the declared group passes (wrong group = mismatch)", () => { + const declared = { gitlab: { group: "acme" } }; + assert.equal(compareContext(declared, { gitlab: { group: "acme", remote: null } })[0]?.status, "ok"); + assert.equal(compareContext(declared, { gitlab: { group: "evil", remote: null } })[0]?.status, "mismatch"); + assert.equal(compareContext(declared, { gitlab: { group: null, remote: null } })[0]?.status, "unknown"); + }); + + it("locks a bitbucket workspace: only the declared workspace passes", () => { + const declared = { bitbucket: { workspace: "acme" } }; + assert.equal(compareContext(declared, { bitbucket: { workspace: "acme", remote: null } })[0]?.status, "ok"); + assert.equal(compareContext(declared, { bitbucket: { workspace: "other", remote: null } })[0]?.status, "mismatch"); + }); + it("plans gcloud + git activation from the declared context (local config only)", () => { const steps = planContext({ gcloud: { config: "prod-cfg", account: "ops@example.com", project: "prod-project", region: "europe-west4" }, diff --git a/src/context-lock.ts b/src/context-lock.ts index 05d99894..58be7c0a 100644 --- a/src/context-lock.ts +++ b/src/context-lock.ts @@ -32,6 +32,8 @@ export interface LiveContext { gcloud?: { account: string | null; project: string | null }; git?: { email: string | null }; github?: { org: string | null; remote: string | null }; + gitlab?: { group: string | null; remote: string | null }; + bitbucket?: { workspace: string | null; remote: string | null }; npm?: { registry: string | null }; vercel?: { orgId: string | null; projectId: string | null }; } @@ -62,6 +64,10 @@ const FIELD_SPECS: { { tool: "git", field: "email", declared: (d) => d.git?.email, live: (l) => l.git?.email ?? null }, { tool: "github", field: "org", declared: (d) => d.github?.org, live: (l) => l.github?.org ?? null }, { tool: "github", field: "remote", declared: (d) => d.github?.remote, live: (l) => l.github?.remote ?? null }, + { tool: "gitlab", field: "group", declared: (d) => d.gitlab?.group, live: (l) => l.gitlab?.group ?? null }, + { tool: "gitlab", field: "remote", declared: (d) => d.gitlab?.remote, live: (l) => l.gitlab?.remote ?? null }, + { tool: "bitbucket", field: "workspace", declared: (d) => d.bitbucket?.workspace, live: (l) => l.bitbucket?.workspace ?? null }, + { tool: "bitbucket", field: "remote", declared: (d) => d.bitbucket?.remote, live: (l) => l.bitbucket?.remote ?? null }, { tool: "npm", field: "registry", declared: (d) => d.npm?.registry, live: (l) => l.npm?.registry ?? null }, { tool: "vercel", field: "team(orgId)", declared: (d) => d.vercel?.team, live: (l) => l.vercel?.orgId ?? null }, { tool: "vercel", field: "project(projectId)", declared: (d) => d.vercel?.project, live: (l) => l.vercel?.projectId ?? null }, @@ -102,6 +108,14 @@ export function suggestContextToml(live: LiveContext): string { ["org", live.github?.org, "from origin remote — authoritative"], ["remote", live.github?.remote, ""], ]); + emit("[context.gitlab]", [ + ["group", live.gitlab?.group, "from origin remote — authoritative"], + ["remote", live.gitlab?.remote, ""], + ]); + emit("[context.bitbucket]", [ + ["workspace", live.bitbucket?.workspace, "from origin remote — authoritative"], + ["remote", live.bitbucket?.remote, ""], + ]); emit("[context.vercel]", [ ["team", live.vercel?.orgId, "orgId from .vercel/project.json — authoritative"], ["project", live.vercel?.projectId, "projectId"], @@ -122,7 +136,13 @@ export function suggestContextToml(live: LiveContext): string { * those. PURE so it's unit-testable. */ export function hasLockableContext(live: LiveContext): boolean { - return Boolean(live.gcloud?.account || live.vercel?.projectId || live.github?.org); + return Boolean( + live.gcloud?.account || + live.vercel?.projectId || + live.github?.org || + live.gitlab?.group || + live.bitbucket?.workspace, + ); } async function run(cmd: string, args: string[]): Promise { @@ -142,6 +162,24 @@ export function parseGithubRemote(url: string | null): { org: string | null; rem return { org: m[1], remote: `github.com/${m[1]}/${m[2]}` }; } +/** gitlab.com[:/]group(/subgroups)/repo(.git) -> { group (top-level), "gitlab.com/" }. */ +export function parseGitlabRemote(url: string | null): { group: string | null; remote: string | null } { + if (!url) return { group: null, remote: null }; + const m = url.match(/gitlab\.com[:/](.+?)(?:\.git)?$/); + if (!m) return { group: null, remote: null }; + const path = m[1].replace(/\/+$/, ""); + const group = path.split("/")[0] || null; + return { group, remote: `gitlab.com/${path}` }; +} + +/** bitbucket.org[:/]workspace/repo(.git) -> { workspace, "bitbucket.org/workspace/repo" }. */ +export function parseBitbucketRemote(url: string | null): { workspace: string | null; remote: string | null } { + if (!url) return { workspace: null, remote: null }; + const m = url.match(/bitbucket\.org[:/]([^/]+)\/(.+?)(?:\.git)?$/); + if (!m) return { workspace: null, remote: null }; + return { workspace: m[1], remote: `bitbucket.org/${m[1]}/${m[2]}` }; +} + /** Read the live context from each tool. Every read fails soft to null. */ export async function gatherLive(cwd: string = process.cwd()): Promise { const live: LiveContext = {}; @@ -161,7 +199,10 @@ export async function gatherLive(cwd: string = process.cwd()): Promise