Link the git board's branch title to the branch on its host

AI Assisted
This commit is contained in:
jparkerweb committed 2026-11-12 07:55:59 -08:00
1 parent 97b5df61ea
commit b38f2b987b
7 files changed
+99 -8

No files matched your search

+14 -1
View File
@@ -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")
+16 -1
View File
@@ -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([
+24 -2
View File
@@ -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));
}
+4
View File
@@ -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); }