mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-18 21:01:19 -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
@@ -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));
|
||||
}
|
||||
Reference in new issue
Block a user