Files
backnotprop__plannotator/packages/shared/review-args.ts
Michael Ramos 56df64c751 Add modern GitButler review support (#1067)
Adds current-architecture GitButler workspace, stack, and branch review support across Bun and Pi while preserving the existing Git, JJ, and P4 paths.

Co-authored-by: Dan Susman <56033661+dansusman@users.noreply.github.com>
2026-07-17 07:37:50 -07:00

89 lines
1.9 KiB
TypeScript

import type { VcsSelection } from "./vcs-core";
import { stripWrappingQuotes } from "./resolve-file";
export interface ParsedReviewArgs {
prUrl?: string;
vcsType?: VcsSelection;
useLocal: boolean;
}
export function parseReviewArgs(input: string | string[]): ParsedReviewArgs {
const tokens = Array.isArray(input)
? input.map((token) => stripWrappingQuotes(token.trim())).filter(Boolean)
: tokenizeReviewArgs(input ?? "");
let vcsType: VcsSelection | undefined;
let useLocal = true;
const positional: string[] = [];
for (const token of tokens) {
switch (token) {
case "--git":
vcsType = "git";
break;
case "--gitbutler":
vcsType = "gitbutler";
break;
case "--local":
useLocal = true;
break;
case "--no-local":
useLocal = false;
break;
default:
positional.push(token);
break;
}
}
const target = positional[0];
return {
prUrl: target && isReviewUrl(target) ? target : undefined,
vcsType,
useLocal,
};
}
function isReviewUrl(value: string): boolean {
return value.startsWith("http://") || value.startsWith("https://");
}
function tokenizeReviewArgs(input: string): string[] {
const raw = input.trim();
if (!raw) return [];
const tokens: string[] = [];
let current = "";
let quote: "'" | "\"" | undefined;
for (let i = 0; i < raw.length; i++) {
const char = raw[i];
if (quote) {
if (char === quote) {
quote = undefined;
} else {
current += char;
}
continue;
}
if (char === "'" || char === "\"") {
quote = char;
continue;
}
if (/\s/.test(char)) {
if (current) {
tokens.push(current);
current = "";
}
continue;
}
current += char;
}
if (current) tokens.push(current);
return tokens.map((token) => stripWrappingQuotes(token.trim())).filter(Boolean);
}