mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 04:45:33 -08:00
Link the git board's branch title to the branch on its host
AI Assisted
This commit is contained in:
1 parent
97b5df61ea
commit
b38f2b987b
7 files changed
+99
-8
No files matched your search
@@ -63,9 +63,9 @@ One row per file under `src/web-console/public/` (the games and their sound are
|
||||
| `public/help.js` | the Help dialog's PURE rules: `HELP_TABS` (21 tabs: ids, order, labels, diagram flags; every tab uses the chosen highlight color; Implementation Loop sits right after Watching a build, The git board right after it, and Activities right after Ask a quick question), `helpTabFor()` (which tab opens, FR-8 order, first match wins: finished → Stopping and finishing, server gone or agent adrift → When something looks stuck, opened from the Workspace dialog → Your workspace, then Ask, the Subagents tab → Helpers (subagents), a red-meter dashboard → Session meter, dashboard, a doc or the Overview, a git session → The git board, a build, else What this page is) and `helpKeyTarget()` (roving arrow keys, Home, End, wrapping; a re-export of `tabs.js`'s `tabKeyTarget`). No module-scope DOM, so `node --test` covers it |
|
||||
| `public/tabs.js` | the WAI-ARIA tabs shared by Help and User Preferences: `wireTabs()` (buttons and panel links, roving tabindex, automatic activation, `aria-orientation` switching at 720 px, an optional `beforeSelect` guard) and the pure `tabKeyTarget()` |
|
||||
| `public/prefs.js` | User Preferences' PURE rules: `PREFS_TABS` (Appearance, Agents & models, System, Sounds & activities, with hints and the sections each holds), `prefsOpenTab()` and `prefsResetScope()` (the looks keys Back to default resets per tab, or null) |
|
||||
| `public/git-board.js` | PURE, one import (`pr-url.js`): the git board's rules from a `state.git` snapshot: branch order and the Remote only fold at `REMOTE_FOLD` 50, whether a new branch name is free, which buttons show and are enabled, whether the board still waits on the agent (`boardAwaiting()`: from a click until the agent's next post, not just until `wait` collects it), the plain sentence each click sends as `reply`, the "Last refreshed" line, which files start ticked in the commit dialog, and the pull-request link; the next step (ten rules, `nextStep()`), the tab that owns it, per-tab badges (`tabBadges()`), the busy mode and per-control gate (`busyMode()`, `controlAllowed()`), the tab to show (`pickTab()`), and the create-panel sources and clean-up groups. `app.js` only renders what it says |
|
||||
| `public/git-board-view.js` | No DOM access of its own: `drawGitBoard(ctx)` draws the tabbed board (header, tab strip with Done with git, the card slot, step strip, Changes / Branches / Sync) from the helpers it is handed (`el`, `md`, `copyButton`), every control through one gate; `screens/git-host.js` hosts it, and `scripts/test-web-console-git-board.mjs` drives it with a recording fake `el` |
|
||||
| `public/pr-url.js` | PURE, no imports: `prUrl()`, the "open a pull request" link for the GitHub, GitLab, Azure DevOps and Bitbucket shapes (`null` for an unknown kind, no web address, or a non-https result). `git-repo.mjs` re-exports it, and the board's base picker rebuilds the link in the browser with the same code |
|
||||
| `public/git-board.js` | PURE, one import (`pr-url.js`): the git board's rules from a `state.git` snapshot: branch order and the Remote only fold at `REMOTE_FOLD` 50, whether a new branch name is free, which buttons show and are enabled, whether the board still waits on the agent (`boardAwaiting()`: from a click until the agent's next post, not just until `wait` collects it), the plain sentence each click sends as `reply`, the "Last refreshed" line, which files start ticked in the commit dialog, the pull-request link, and the current branch's page on its host (`boardBranchLink()`, null until the branch is pushed under its own name); the next step (ten rules, `nextStep()`), the tab that owns it, per-tab badges (`tabBadges()`), the busy mode and per-control gate (`busyMode()`, `controlAllowed()`), the tab to show (`pickTab()`), and the create-panel sources and clean-up groups. `app.js` only renders what it says |
|
||||
| `public/git-board-view.js` | No DOM access of its own: `drawGitBoard(ctx)` draws the tabbed board (header, whose branch name is a link to the branch on its host once pushed, tab strip with Done with git, the card slot, step strip, Changes / Branches / Sync) from the helpers it is handed (`el`, `md`, `copyButton`), every control through one gate; `screens/git-host.js` hosts it, and `scripts/test-web-console-git-board.mjs` drives it with a recording fake `el` |
|
||||
| `public/pr-url.js` | PURE, no imports: `prUrl()`, the "open a pull request" link for the GitHub, GitLab, Azure DevOps and Bitbucket shapes (`null` for an unknown kind, no web address, or a non-https result), and `branchUrl()`, the branch's own page on the same four hosts under the same rules. `git-repo.mjs` re-exports `prUrl()`, and the board's base picker rebuilds the link in the browser with the same code |
|
||||
| `public/workspace.js` | PURE, no imports: the Workspace's name rules (`nameProblem()`, `NAME_MAX`, `defaultName()`, `freeName()` for the `-2` suggestion), the footer label and its width tiers (`footerLabel()`, `FOOTER_TIERS`) and `changeLine()`, the `Workspace: …` reply line an agent is handed per change. Imported by the server, `cmd-chat.mjs`, `cmd-post-wait.mjs`, `workspace.mjs` and the page |
|
||||
| `public/meter.js` | PURE, imports only `skills.js`: the session meter. `WEIGHTS` (the events that are not a skill's own launch, merged with each skill's `weight` from `skills.js`; its keys are also `RUN_EVENTS`, the `run` events `post` accepts), `LAUNCH_COUNTED` (workflows whose launch itself scores), the built-phase sizing (`TASK_EVENTS`, the keys of `TASK_BONUS`: `implement-phase` +0 and `implement-review-phase` +1; `isTaskCount()` accepts a whole `tasks` from 1 to `MAX_TASKS` 999; `runPoints()` scores such a run `ceil(tasks / TASKS_PER_POINT)` (3) plus its bonus, and any other run its `WEIGHTS` value), `ANSWERS_PER_POINT` 2 (`answer` entries score per skill run, `floor(count / 2)`), `breakdownFrom()` (the click-the-ring list: one row per scoring entry plus one answers row per skill run), `pointsFrom()` (the count, its sum, folded from `ledger.ndjson` and deduplicated by id, never stored), `levelFor()` with `YELLOW_AT` 5 / `RED_AT` 10, `ringFraction()` (full at `RING_FULL` 15), `WORDS`, `tooltipFor()`, `RED_BANNER` and `meterView()` |
|
||||
| `public/mentions.js` | PURE, no imports: the `@name` popover's logic — `mentionAt()` finds an `@partial` at the caret, `matchNames()` filters the workspace names, `applyMention()` splices a pick in and returns the new caret. Used by the Ask box, notes and text answers |
|
||||
|
||||
@@ -408,6 +408,17 @@ test("git board view: every function of today's board is reachable on some tab",
|
||||
const head = draw(id).node.children.find((c) => c.tag === "header");
|
||||
if (s.git.head.branch) assert.ok(head.textContent.includes(s.git.head.branch), `${id}: the header names the branch`);
|
||||
}
|
||||
// A pushed branch's name is a link to it on its host, in every mode; an unpublished one is plain text.
|
||||
const branchLink = (id, mode) => walk(draw(id, { mode }).node).find((n) => n.tag === "a" && n.classes.has("git-branch-link"));
|
||||
for (const mode of MODES) {
|
||||
const a = branchLink("cp-pushed", mode);
|
||||
assert.equal(a.href, `https://github.com/jparkerweb/plan2code/tree/${STATES["cp-pushed"].git.head.branch}`, `cp-pushed · ${mode}`);
|
||||
assert.equal(a.target, "_blank");
|
||||
assert.equal(a.rel, "noopener");
|
||||
assert.equal(a.textContent, STATES["cp-pushed"].git.head.branch);
|
||||
}
|
||||
assert.equal(branchLink("e-gone", "idle"), undefined, "no link once the remote copy is deleted");
|
||||
assert.equal(branchLink("e-no-remote", "idle"), undefined, "no link with no remote");
|
||||
assert.ok(draw("e-no-remote").node.children[0].textContent.includes("git remote add origin <url>"));
|
||||
});
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
UNTRACKED_TICK_LIMIT,
|
||||
boardActions,
|
||||
boardAwaiting,
|
||||
boardBranchLink,
|
||||
boardPrLink,
|
||||
commitTicks,
|
||||
composeBranchName,
|
||||
@@ -36,7 +37,7 @@ import {
|
||||
orderBranches,
|
||||
refreshedLine,
|
||||
} from "../src/web-console/public/git-board.js";
|
||||
import { prUrl } from "../src/web-console/public/pr-url.js";
|
||||
import { prUrl, branchUrl } from "../src/web-console/public/pr-url.js";
|
||||
import { PROTECTED_CONSOLE_FILES, readLedger } from "../src/web-console/sessions.mjs";
|
||||
import {
|
||||
CONSOLE_CLI,
|
||||
@@ -559,6 +560,31 @@ test("git board: boardPrLink builds the link for a pushed feature branch only",
|
||||
assert.deepEqual(boardPrLink(unknown, "main"), { url: null, needsKind: true, host: "git.example.com" });
|
||||
});
|
||||
|
||||
test("git board: boardBranchLink opens the current branch on its host, once it is pushed", () => {
|
||||
assert.equal(boardBranchLink(snap()), "https://github.com/jparkerweb/plan2code/tree/feature/x");
|
||||
const onMain = snap({ branches: [row("main", { default: true, current: true })] });
|
||||
assert.equal(boardBranchLink(onMain), "https://github.com/jparkerweb/plan2code/tree/main", "the default branch has a page too");
|
||||
// A branch made from origin/main tracks origin/main until it is published: that page is not this branch.
|
||||
const fromMain = snap({ branches: [row("feature/x", { current: true, upstream: "origin/main" })] });
|
||||
assert.equal(boardBranchLink(fromMain), null, "no link to the branch it was made from");
|
||||
const renamed = snap({ branches: [row("feature/x", { current: true, upstream: "origin/feature/theirs" })] });
|
||||
assert.equal(boardBranchLink(renamed), null, "nor to an upstream under another name");
|
||||
const unpushed = snap({ branches: [row("feature/x", { current: true, upstream: null, upstreamRemote: null })] });
|
||||
assert.equal(boardBranchLink(unpushed), null, "nothing to open before a publish");
|
||||
assert.equal(boardBranchLink(snap({ branches: [row("feature/x", { current: true, gone: true })] })), null, "nor once the remote copy is deleted");
|
||||
const unknown = snap({
|
||||
remotes: [{ name: "origin", url: "git@git.example.com:a/b.git", host: "git.example.com", web: "https://git.example.com/a/b", kind: null }],
|
||||
});
|
||||
assert.equal(boardBranchLink(unknown), null, "nor on a host of unknown kind");
|
||||
|
||||
const web = "https://h.example.com/a/b";
|
||||
assert.equal(branchUrl({ web, kind: "gitlab" }, "feature/a b"), `${web}/-/tree/feature/a%20b`);
|
||||
assert.equal(branchUrl({ web, kind: "azure" }, "feature/x"), `${web}?version=GBfeature%2Fx`);
|
||||
assert.equal(branchUrl({ web, kind: "bitbucket" }, "feature/x"), `${web}/branch/feature/x`);
|
||||
assert.equal(branchUrl({ web, kind: "none" }, "main"), null);
|
||||
assert.equal(branchUrl({ web: "http://h.example.com/a/b", kind: "github" }, "main"), null, "https only");
|
||||
});
|
||||
|
||||
test("git board: the page draws it from git-board.js, with no inline styles", () => {
|
||||
const dir = path.join(path.dirname(CONSOLE_CLI), "public");
|
||||
const html = fs.readFileSync(path.join(dir, "index.html"), "utf8");
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
GIT_TABS,
|
||||
PR_HOST_LABELS,
|
||||
boardActions,
|
||||
boardBranchLink,
|
||||
boardPrLink,
|
||||
cleanupGroups,
|
||||
commitTicks,
|
||||
@@ -149,7 +150,19 @@ function header(ctx) {
|
||||
const row = h.el("div", "git-head-row");
|
||||
// Mid-rebase HEAD is detached, but the person is still on their branch.
|
||||
const title = head.branch || (head.rebasing ? `${head.rebasing} · rebasing` : `Not on a branch (at ${head.detached || "an unknown commit"})`);
|
||||
row.appendChild(h.el("h2", "git-branch", title));
|
||||
// A pushed branch's name opens it on its host. The link only leaves the
|
||||
// page, so it is not a board control and stays live while the board is busy.
|
||||
const url = head.branch ? boardBranchLink(git) : null;
|
||||
if (url) {
|
||||
const h2 = h.el("h2", "git-branch");
|
||||
const a = h.el("a", "git-branch-link", title);
|
||||
a.href = url;
|
||||
a.target = "_blank";
|
||||
a.rel = "noopener";
|
||||
a.title = `Open ${title} on ${(cur && cur.upstreamRemote) || "the remote"} in your browser`;
|
||||
h2.appendChild(a);
|
||||
row.appendChild(h2);
|
||||
} else row.appendChild(h.el("h2", "git-branch", title));
|
||||
if (head.branch) {
|
||||
row.appendChild(
|
||||
h.el("span", "git-track", head.upstream && head.gone ? "remote copy deleted" : head.upstream ? `↑${head.ahead || 0} ↓${head.behind || 0}` : "not published")
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// module scope and only one import: the page and `node --test` both import
|
||||
// this file.
|
||||
|
||||
import { prUrl } from "./pr-url.js";
|
||||
import { prUrl, branchUrl } from "./pr-url.js";
|
||||
|
||||
export const BRANCH_TYPES = Object.freeze(["feature", "fix", "chore", "docs", "refactor", "test"]);
|
||||
export const REMOTE_FOLD = 50;
|
||||
@@ -423,6 +423,21 @@ export function boardPrLink(git, base) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The current branch's page on its remote, or null when there is nothing to
|
||||
* open: not pushed, gone upstream, or a host of unknown kind. Also null when
|
||||
* the upstream has another name: a branch made from origin/main tracks
|
||||
* origin/main until it is published, and that page is not this branch.
|
||||
*/
|
||||
export function boardBranchLink(git) {
|
||||
const cur = currentRow(git);
|
||||
if (!cur || !cur.upstream || cur.gone || !cur.upstreamRemote) return null;
|
||||
const remote = list(git.remotes).find((r) => r && r.name === cur.upstreamRemote);
|
||||
if (!remote) return null;
|
||||
if (cur.upstream !== `${cur.upstreamRemote}/${cur.name}`) return null;
|
||||
return branchUrl(remote, cur.name);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------- next step */
|
||||
|
||||
export const GIT_TABS = Object.freeze([
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Plan2Code Web Console - the pull-request link for a branch.
|
||||
// Plan2Code Web Console - the pull-request link for a branch, and the link to
|
||||
// the branch itself.
|
||||
//
|
||||
// One pure builder for the four host shapes in the git-dashboard spec
|
||||
// (overview.md -> Pull-request URL shapes). git-repo.mjs re-exports it for the
|
||||
@@ -27,10 +28,31 @@ const SHAPES = {
|
||||
export function prUrl({ web, kind } = {}, { base, head } = {}) {
|
||||
const shape = SHAPES[kind];
|
||||
if (!shape || !web || !base || !head) return null;
|
||||
const url = shape(String(web).replace(/\/+$/, ""), base, head);
|
||||
return httpsOnly(shape(String(web).replace(/\/+$/, ""), base, head));
|
||||
}
|
||||
|
||||
const httpsOnly = (url) => {
|
||||
try {
|
||||
return new URL(url).protocol === "https:" ? url : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// Where each host shows one branch's files.
|
||||
const BRANCH_SHAPES = {
|
||||
github: (web, branch) => `${web}/tree/${segments(branch)}`,
|
||||
gitlab: (web, branch) => `${web}/-/tree/${segments(branch)}`,
|
||||
azure: (web, branch) => `${web}?version=GB${q(branch)}`,
|
||||
bitbucket: (web, branch) => `${web}/branch/${segments(branch)}`,
|
||||
};
|
||||
|
||||
/**
|
||||
* The page for `branch` on a remote, under the same rules as prUrl(): null
|
||||
* for an unknown host kind, no web address, or a result that is not https:.
|
||||
*/
|
||||
export function branchUrl({ web, kind } = {}, branch) {
|
||||
const shape = BRANCH_SHAPES[kind];
|
||||
if (!shape || !web || !branch) return null;
|
||||
return httpsOnly(shape(String(web).replace(/\/+$/, ""), branch));
|
||||
}
|
||||
@@ -153,6 +153,10 @@
|
||||
}
|
||||
.git-head-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 14px; }
|
||||
.git-branch { margin: 0; font: 600 22px/1.2 var(--serif); overflow-wrap: anywhere; }
|
||||
/* The branch name as a link to its host: it reads as the title until hovered. */
|
||||
.git-branch-link { color: inherit; text-decoration: underline; text-decoration-color: var(--rule-2); text-decoration-thickness: 1px; text-underline-offset: 4px; }
|
||||
.git-branch-link::after { content: " ↗"; font: 400 14px/1 var(--mono); color: var(--ink-2); }
|
||||
.git-branch-link:hover, .git-branch-link:focus-visible { color: var(--accent); text-decoration-color: currentColor; }
|
||||
.git-track { font-family: var(--mono); font-size: 14px; color: var(--ink-2); }
|
||||
.git-head-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 13.5px; color: var(--ink-2); }
|
||||
.git-noremote { font-weight: 600; color: var(--stage); }
|
||||
|
||||
Reference in new issue
Block a user