Files
AgentHub/server/lib/ci-status.js
T
nntrivi2001 17d56d0e01 refactor!: rebrand CCAM to AgentHub
Clean break, no compatibility alias. Renames the product name, the CLI
binary (`ccam` -> `agenthub`), the env var prefix (`CCAM_` ->
`AGENTHUB_`), the Prometheus metric namespace (`ccam_*` ->
`agenthub_*`), the tmux session prefix (`ccam-lane-<id>` ->
`agenthub-lane-<id>`), the per-repo runtime profile directory
(`.ccam/profile` -> `.agenthub/profile`), the lanes state root
(`~/.claude/ccam-lanes` -> `~/.claude/agenthub-lanes`), the bundled
plugins (`plugins/ccam*` -> `plugins/agenthub*`) and their slash
commands (`/ccam-doctor` -> `/agenthub-doctor`, `/ccam:*` ->
`/agenthub:*`).

Because there is no alias, an existing install has to be updated by
hand: rename its `.ccam/profile` directory and any `CCAM_*` variables,
and reinstall the plugin under its new name.

Two other name families are deliberately left alone here, since they are
not just strings: the `Claude-Code-Monitor` repository/marketplace name,
and the `agent-dashboard` npm package plus its `~/.claude/agent-dashboard`
runtime directory, which holds the live database and needs a migration
rather than a rename.

Verified: server 1406/1406, client 459/459, `grep -i ccam` clean across
tracked files, `openapi.yaml` regenerated (95 paths, unchanged count).
2026-09-07 12:09:15 +07:00

62 lines
1.8 KiB
JavaScript

/**
* @file Turns a GitHub Actions run for one ref into a single derived fact —
* {state, checks} — for ship-feature-lane's Stage 13 CI-wait. Deliberately a
* snapshot, not a poll loop: the driving skill owns the wait/retry decision
* (docs/LANES.md "Orchestration: what AgentHub does NOT do"), this module only
* reports what gh already knows.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const { gh } = require("./gh");
/** A 7-40 char hex string reads as a commit sha; anything else is a branch name. */
const SHA_RE = /^[0-9a-f]{7,40}$/i;
/**
* @param {string} cwd - The lane's repo directory (gh resolves the GitHub
* repo from this directory's git remote).
* @param {string} ref - A branch name or commit sha.
* @returns {Promise<{state: "success"|"failure"|"pending", ref: string, checks: Array}>}
*/
async function ciStatus(cwd, ref) {
const refFlag = SHA_RE.test(ref) ? "--commit" : "--branch";
const { stdout: listOut } = await gh(cwd, [
"run",
"list",
refFlag,
ref,
"--json",
"databaseId,status,conclusion",
"--limit",
"1",
]);
const runs = JSON.parse(listOut);
if (runs.length === 0) {
return { state: "pending", ref, checks: [] };
}
const run = runs[0];
if (run.status !== "completed") {
return { state: "pending", ref, checks: [] };
}
const { stdout: viewOut } = await gh(cwd, [
"run",
"view",
String(run.databaseId),
"--json",
"jobs",
]);
const { jobs } = JSON.parse(viewOut);
const checks = jobs.map((job) => ({
name: job.name,
conclusion: job.conclusion || job.status,
url: job.url || null,
}));
const FAILING = new Set(["failure", "cancelled", "timed_out", "action_required"]);
const state = checks.some((c) => FAILING.has(c.conclusion)) ? "failure" : "success";
return { state, ref, checks };
}
module.exports = { ciStatus };