feat(panel): clickable Branch/PR links + branch copy button

The Branch value in the task-detail card and the Branch/PR badges in the task
list were static text. Make them open the real thing on GitHub, keeping their
exact look:

- New repo-url helper normalizes a project git_url (https/ssh, with/without
  .git) into web URLs for a branch (/tree/<branch>) and PR (/pull/<n>),
  returning null so callers fall back to a plain label.
- Task-detail Branch card: the branch is now a link to its GitHub tree URL and
  gains a copy button (reuses CopyButton); PR was already linked.
- List-row git badge (git-status-badge): the PR badge links to task.pr_url
  (or the built pull URL) and the Branch badge links to the branch tree URL.
  The row's click handler already ignores <a> clicks, so opening a branch/PR
  never toggles the row. git_url is threaded via a projectGitUrls map from the
  tasks page, alongside the existing projectNames map.

panel typecheck + eslint clean.
This commit is contained in:
Renn F
2026-06-21 07:15:58 +02:00
parent c3ee5f09ba
commit 0740dc141e
5 changed files with 437 additions and 141 deletions
+45
View File
@@ -0,0 +1,45 @@
/**
* Helpers to turn a project's stored `git_url` into clickable GitHub-style
* web URLs for branches and PRs.
*
* `git_url` may be an https clone URL (`https://github.com/owner/repo.git`),
* an ssh URL (`git@github.com:owner/repo.git`), or already a web URL — with or
* without a trailing `.git`. Each helper returns `null` when it can't build a
* usable URL, so callers render a plain (non-link) label as a graceful
* fallback rather than a broken link.
*/
/** Normalize a git_url to its web base, e.g. `https://github.com/owner/repo`. */
export function repoWebUrl(gitUrl: string | null | undefined): string | null {
if (!gitUrl) return null;
let url = gitUrl.trim();
// ssh form: git@host:owner/repo(.git) -> https://host/owner/repo
const ssh = url.match(/^git@([^:]+):(.+)$/);
if (ssh) {
url = `https://${ssh[1]}/${ssh[2]}`;
}
url = url.replace(/\.git$/, "").replace(/\/+$/, "");
return /^https?:\/\//.test(url) ? url : null;
}
/** Web URL for a branch, e.g. `…/repo/tree/feature/backend/abc`. */
export function branchUrl(
gitUrl: string | null | undefined,
branch: string | null | undefined,
): string | null {
const base = repoWebUrl(gitUrl);
if (!base || !branch) return null;
// roboco branch names are url-safe ([a-z0-9/_-]); slashes are kept so GitHub
// resolves the full ref path.
return `${base}/tree/${branch}`;
}
/** Web URL for a pull request, e.g. `…/repo/pull/54`. */
export function pullUrl(
gitUrl: string | null | undefined,
prNumber: number | null | undefined,
): string | null {
const base = repoWebUrl(gitUrl);
if (!base || !prNumber) return null;
return `${base}/pull/${prNumber}`;
}