mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
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.
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
/**
|
|
* 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}`;
|
|
}
|