Official
git
Built-in git UI (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/git@0.3.3
Permissions in 0.3.3
Files
github.ts1.9 KB
// The branch's remote on GitHub and what gh answers about its pull requests, kept pure for tests.
import * as z from "zod";
export interface Remote {
readonly name: string;
readonly url: string;
/** The branch on the remote, as `feature` of `origin/feature`. */
readonly branch: string;
}
/** The remote an upstream such as `origin/feature` belongs to, with its fetch URL, from `git remote -v`. */
export function upstreamRemote(upstream: string, remotes: string): Remote | null {
const urls = new Map<string, string>();
for (const line of remotes.split("\n")) {
const [name, url, kind] = line.trim().split(/\s+/);
if (name && url && kind === "(fetch)") urls.set(name, url);
}
// The longest name wins, since a remote's name may itself hold a slash.
const name = [...urls.keys()]
.filter((remote) => upstream.startsWith(`${remote}/`))
.sort((a, b) => b.length - a.length)[0];
const url = name === undefined ? undefined : urls.get(name);
return name === undefined || url === undefined ? null : { name, url, branch: upstream.slice(name.length + 1) };
}
/** Whether a remote URL (`https://github.com/o/r.git`, `git@github.com:o/r.git`, or an SSH alias such as
* `github-work:o/r.git`) points at GitHub or a GitHub Enterprise server. */
export function onGitHub(url: string): boolean {
const host = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]+@)?([^/:]+)/i.exec(url)?.[1] ?? /^(?:[^@/]+@)?([^/:]+):/.exec(url)?.[1];
return !!host && host.toLowerCase().includes("github");
}
/** What `gh pr list --json url,number` prints, as parsed JSON. */
export const PullList = z.array(z.object({ url: z.string(), number: z.number() }));
/** The pull request `gh pr create` printed, or `null` when its output holds no link. */
export function createdPull(stdout: string): { url: string; number: number } | null {
const match = /https?:\/\/\S+\/pull\/(\d+)/.exec(stdout);
return match?.[1] ? { url: match[0], number: Number(match[1]) } : null;
}
No comments yet.