vouchington-tooling 0.59.0 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/dist/cli/commands/hook.d.mts +2 -0
- package/dist/cli/commands/hook.mjs +19 -0
- package/dist/cli/index.mjs +6 -0
- package/dist/cli/parse-forwarded-commands.d.mts +6 -0
- package/dist/cli/parse-forwarded-commands.mjs +4 -0
- package/dist/cli/parse.d.mts +6 -0
- package/dist/cli/usage-text.d.mts +1 -0
- package/dist/cli/usage-text.mjs +170 -0
- package/dist/cli/usage.d.mts +2 -1
- package/dist/cli/usage.mjs +2 -156
- package/dist/command-policy/engine.d.mts +7 -0
- package/dist/command-policy/engine.mjs +58 -0
- package/dist/command-policy/git-patterns.d.mts +20 -0
- package/dist/command-policy/git-patterns.mjs +82 -0
- package/dist/command-policy/git-process.d.mts +4 -0
- package/dist/command-policy/git-process.mjs +54 -0
- package/dist/command-policy/github-checkout-owners.d.mts +22 -0
- package/dist/command-policy/github-checkout-owners.mjs +122 -0
- package/dist/command-policy/github-command-context.d.mts +6 -0
- package/dist/command-policy/github-command-context.mjs +19 -0
- package/dist/command-policy/github-command-cwd.d.mts +8 -0
- package/dist/command-policy/github-command-cwd.mjs +130 -0
- package/dist/command-policy/github-command-position.d.mts +7 -0
- package/dist/command-policy/github-command-position.mjs +12 -0
- package/dist/command-policy/github-configured-base.d.mts +25 -0
- package/dist/command-policy/github-configured-base.mjs +59 -0
- package/dist/command-policy/github-invocation.d.mts +9 -0
- package/dist/command-policy/github-invocation.mjs +80 -0
- package/dist/command-policy/github-merge-authority.d.mts +21 -0
- package/dist/command-policy/github-merge-authority.mjs +86 -0
- package/dist/command-policy/github-option-flags.d.mts +3 -0
- package/dist/command-policy/github-option-flags.mjs +67 -0
- package/dist/command-policy/github-options.d.mts +12 -0
- package/dist/command-policy/github-options.mjs +73 -0
- package/dist/command-policy/github-stack-workflow.d.mts +9 -0
- package/dist/command-policy/github-stack-workflow.mjs +94 -0
- package/dist/command-policy/github-workflow.d.mts +7 -0
- package/dist/command-policy/github-workflow.mjs +50 -0
- package/dist/command-policy/hook/args.d.mts +11 -0
- package/dist/command-policy/hook/args.mjs +49 -0
- package/dist/command-policy/hook/harness.d.mts +26 -0
- package/dist/command-policy/hook/harness.mjs +119 -0
- package/dist/command-policy/hook/policy-module.d.mts +7 -0
- package/dist/command-policy/hook/policy-module.mjs +48 -0
- package/dist/command-policy/hook/post-tool-use.d.mts +9 -0
- package/dist/command-policy/hook/post-tool-use.mjs +51 -0
- package/dist/command-policy/hook/pre-tool-use.d.mts +21 -0
- package/dist/command-policy/hook/pre-tool-use.mjs +45 -0
- package/dist/command-policy/hook/run.d.mts +17 -0
- package/dist/command-policy/hook/run.mjs +69 -0
- package/dist/command-policy/hook/types.d.mts +33 -0
- package/dist/command-policy/hook/types.mjs +5 -0
- package/dist/command-policy/index.d.mts +29 -0
- package/dist/command-policy/index.mjs +23 -0
- package/dist/command-policy/path-references.d.mts +14 -0
- package/dist/command-policy/path-references.mjs +68 -0
- package/dist/command-policy/path-rules.d.mts +11 -0
- package/dist/command-policy/path-rules.mjs +37 -0
- package/dist/command-policy/payload.d.mts +8 -0
- package/dist/command-policy/payload.mjs +54 -0
- package/dist/command-policy/types.d.mts +77 -0
- package/dist/command-policy/types.mjs +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -0
- package/dist/tmux/cli-shared.d.mts +18 -0
- package/dist/tmux/cli-shared.mjs +8 -0
- package/dist/tmux/cli.d.mts +3 -0
- package/dist/tmux/cli.mjs +34 -0
- package/dist/tmux/config.d.mts +24 -0
- package/dist/tmux/config.mjs +91 -0
- package/dist/tmux/fake-tmux.test-helpers.d.mts +46 -0
- package/dist/tmux/fake-tmux.test-helpers.mjs +105 -0
- package/dist/tmux/hook-payload.d.mts +8 -0
- package/dist/tmux/hook-payload.mjs +39 -0
- package/dist/tmux/index.d.mts +9 -0
- package/dist/tmux/index.mjs +7 -0
- package/dist/tmux/launcher.d.mts +11 -0
- package/dist/tmux/launcher.mjs +127 -0
- package/dist/tmux/reminder-post-tool.d.mts +21 -0
- package/dist/tmux/reminder-post-tool.mjs +88 -0
- package/dist/tmux/runner.d.mts +11 -0
- package/dist/tmux/runner.mjs +26 -0
- package/dist/tmux/session-name.d.mts +5 -0
- package/dist/tmux/session-name.mjs +10 -0
- package/dist/tmux/shell-quote.d.mts +9 -0
- package/dist/tmux/shell-quote.mjs +16 -0
- package/dist/tmux/up.d.mts +2 -0
- package/dist/tmux/up.mjs +73 -0
- package/dist/tmux/windows.d.mts +18 -0
- package/dist/tmux/windows.mjs +50 -0
- package/package.json +11 -1
- package/scripts/__pycache__/run_bounded_process.cpython-312.pyc +0 -0
- package/scripts/tmux/tmux-agent-reminder.sh +68 -0
- package/scripts/tmux/tmux-name.sh +34 -0
- package/scripts/tmux/tmux-read-title.sh +13 -0
- package/scripts/tmux/tmux-target.sh +130 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { commandsToInspectForGitPolicy, isInteractiveRebaseContinue, } from "../shell-parse/index.mjs";
|
|
2
|
+
import { findBlockedPatternReason } from "./git-patterns.mjs";
|
|
3
|
+
import { findGitHubWorkflowBlock } from "./github-workflow.mjs";
|
|
4
|
+
import { findInteractiveMergeConfirm } from "./github-merge-authority.mjs";
|
|
5
|
+
import { extractToolCommand, hookCwd } from "./payload.mjs";
|
|
6
|
+
import { findPathTypo, referencesProtectedPath } from "./path-rules.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* Decides whether a tool call may run under a caller-supplied rule table. Every check that can
|
|
9
|
+
* block runs first; the interactive lone-merge confirm is the final return, so a block anywhere in
|
|
10
|
+
* the command always beats the merge allow. Returns null when the policy has no opinion.
|
|
11
|
+
*/
|
|
12
|
+
export function evaluateCommandPolicy(payload, policy, options = {}) {
|
|
13
|
+
const command = extractToolCommand(payload);
|
|
14
|
+
const automationContext = options.automationContext ?? true;
|
|
15
|
+
const typo = findPathTypo(payload, command, policy.typoPaths ?? []);
|
|
16
|
+
if (typo !== undefined) {
|
|
17
|
+
return { reason: typo.reason };
|
|
18
|
+
}
|
|
19
|
+
if (automationContext &&
|
|
20
|
+
policy.protectedPaths !== undefined &&
|
|
21
|
+
referencesProtectedPath(payload, command, policy.protectedPaths)) {
|
|
22
|
+
return { reason: policy.protectedPaths.reason };
|
|
23
|
+
}
|
|
24
|
+
// An apply_patch payload is path-checked above and carries no shell to inspect.
|
|
25
|
+
if (command === '' || command.startsWith('*** Begin Patch')) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const workflowBlock = findGitHubWorkflowBlock(command, options.cwd ?? hookCwd(payload), {
|
|
29
|
+
automationContext,
|
|
30
|
+
mergeGuidance: policy.mergeGuidance,
|
|
31
|
+
stack: policy.stack,
|
|
32
|
+
});
|
|
33
|
+
if (workflowBlock !== null) {
|
|
34
|
+
return workflowBlock;
|
|
35
|
+
}
|
|
36
|
+
return (findScriptBlock(command, policy) ??
|
|
37
|
+
findInteractiveMergeConfirm(command, automationContext, policy.mergeGuidance ?? ''));
|
|
38
|
+
}
|
|
39
|
+
function findScriptBlock(command, policy) {
|
|
40
|
+
const scripts = commandsToInspectForGitPolicy(command);
|
|
41
|
+
for (const script of scripts) {
|
|
42
|
+
const reason = findBlockedPatternReason(script, policy.commandPatterns ?? []);
|
|
43
|
+
if (reason !== null)
|
|
44
|
+
return { reason };
|
|
45
|
+
}
|
|
46
|
+
if (!/\bgit\b/.test(command)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
for (const script of scripts) {
|
|
50
|
+
if (policy.rebaseContinueReason !== undefined && isInteractiveRebaseContinue(script)) {
|
|
51
|
+
return { reason: policy.rebaseContinueReason };
|
|
52
|
+
}
|
|
53
|
+
const reason = findBlockedPatternReason(script, policy.gitPatterns ?? []);
|
|
54
|
+
if (reason !== null)
|
|
55
|
+
return { reason };
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PatternRule } from './types.mts';
|
|
2
|
+
/**
|
|
3
|
+
* Why a git command breaks the given rules, or null. Each rule reads one simple command: the span
|
|
4
|
+
* after `git` stops at `|`, `;`, `&`, and newline, so a flag on a piped or chained command
|
|
5
|
+
* (`git commit -F msg | tail -n 20`) is not a git flag. A command substitution's own separators
|
|
6
|
+
* are blanked first, so `git push origin $(git branch --show-current | head -1) --force` is one
|
|
7
|
+
* command.
|
|
8
|
+
*/
|
|
9
|
+
export declare function findBlockedPatternReason(command: string, rules: readonly PatternRule[]): string | null;
|
|
10
|
+
export declare const PLAIN_FORCE_PUSH_REASON = "Force pushes are banned by repository policy.";
|
|
11
|
+
/**
|
|
12
|
+
* The generic git-hygiene bans, as an opt-in preset for `CommandPolicy.gitPatterns`: plain force
|
|
13
|
+
* pushes, amends, ours/theirs strategies, and every way to skip git hooks. Each reason is
|
|
14
|
+
* overridable; `pullRebaseReason` is the only one a repository usually rewrites, to name its own
|
|
15
|
+
* rebase script.
|
|
16
|
+
*/
|
|
17
|
+
export declare function standardGitPatterns(reasons?: {
|
|
18
|
+
forcePush?: string;
|
|
19
|
+
pullRebase?: string;
|
|
20
|
+
}): PatternRule[];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { readBacktickSubstitution, readParenthesizedSubstitution } from "../shell-parse/index.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Why a git command breaks the given rules, or null. Each rule reads one simple command: the span
|
|
4
|
+
* after `git` stops at `|`, `;`, `&`, and newline, so a flag on a piped or chained command
|
|
5
|
+
* (`git commit -F msg | tail -n 20`) is not a git flag. A command substitution's own separators
|
|
6
|
+
* are blanked first, so `git push origin $(git branch --show-current | head -1) --force` is one
|
|
7
|
+
* command.
|
|
8
|
+
*/
|
|
9
|
+
export function findBlockedPatternReason(command, rules) {
|
|
10
|
+
const text = blankSubstitutionSeparators(command);
|
|
11
|
+
return rules.find(({ pattern }) => matches(pattern, text))?.reason ?? null;
|
|
12
|
+
}
|
|
13
|
+
// A global or sticky pattern keeps `lastIndex` between tests, so reset it to keep decisions pure.
|
|
14
|
+
function matches(pattern, text) {
|
|
15
|
+
pattern.lastIndex = 0;
|
|
16
|
+
return pattern.test(text);
|
|
17
|
+
}
|
|
18
|
+
function blankSubstitutionSeparators(command) {
|
|
19
|
+
let result = '';
|
|
20
|
+
for (let index = 0; index < command.length; index += 1) {
|
|
21
|
+
const endIndex = substitutionEndIndex(command, index);
|
|
22
|
+
if (endIndex === null) {
|
|
23
|
+
result += command[index];
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
result += command.slice(index, endIndex + 1).replace(/[|;&\n]/g, ' ');
|
|
27
|
+
index = endIndex;
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function substitutionEndIndex(command, index) {
|
|
32
|
+
if (command.startsWith('$(', index)) {
|
|
33
|
+
return readParenthesizedSubstitution(command, index + 2)?.endIndex ?? null;
|
|
34
|
+
}
|
|
35
|
+
if (command[index] === '`') {
|
|
36
|
+
return readBacktickSubstitution(command, index + 1)?.endIndex ?? null;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
export const PLAIN_FORCE_PUSH_REASON = 'Force pushes are banned by repository policy.';
|
|
41
|
+
/**
|
|
42
|
+
* The generic git-hygiene bans, as an opt-in preset for `CommandPolicy.gitPatterns`: plain force
|
|
43
|
+
* pushes, amends, ours/theirs strategies, and every way to skip git hooks. Each reason is
|
|
44
|
+
* overridable; `pullRebaseReason` is the only one a repository usually rewrites, to name its own
|
|
45
|
+
* rebase script.
|
|
46
|
+
*/
|
|
47
|
+
export function standardGitPatterns(reasons = {}) {
|
|
48
|
+
return [
|
|
49
|
+
{
|
|
50
|
+
pattern: /\bgit\s+push\b[^|;&\n]*\s(?:--force(?!-with-lease(?:\b|=))\b|--mirror\b|-[A-Za-z]*f[A-Za-z]*\b|\+[^;&|()\s]+)/,
|
|
51
|
+
reason: reasons.forcePush ?? PLAIN_FORCE_PUSH_REASON,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
pattern: /\bgit\s+commit\b[^|;&\n]*--amend\b/,
|
|
55
|
+
reason: 'Commit amend is banned by repository policy.',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
pattern: /\bgit\s+pull\b[^|;&\n]*(?:--rebase\b|\s-[A-Za-z]*r[A-Za-z]*\b)/,
|
|
59
|
+
reason: reasons.pullRebase ?? 'git pull --rebase and git pull -r are banned.',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
pattern: /\bgit\b[^|;&\n]*(?:\s-X(?:=|\s)?(?:ours|theirs)\b|\s-X(?:ours|theirs)\b|\s(?:-s\s*|--strategy(?:=|\s+))ours\b|--strategy-option(?:=|\s+)(?:ours|theirs)\b)/,
|
|
63
|
+
reason: 'Git strategy options for ours/theirs are banned; during rebase they can silently keep the wrong side.',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
pattern: /\bgit\s+(?:checkout|restore)\b[^|;&\n]*(?:--ours|--theirs)\b/,
|
|
67
|
+
reason: 'git checkout/restore --ours/--theirs is banned; resolve rebase conflicts manually.',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
pattern: /\bgit\b[^|;&\n]*--no-verify\b/,
|
|
71
|
+
reason: '--no-verify bypasses repository git hooks. Fix the underlying failure instead of skipping hooks.',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
pattern: /\bgit\s+commit\b[^|;&\n]*\s-[A-Za-z]*n[A-Za-z]*\b/,
|
|
75
|
+
reason: 'git commit -n bypasses the commit-msg and pre-commit hooks. Fix the underlying failure instead.',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
pattern: /\bgit\b[^|;&\n]*-c\s+core\.hooksPath\s*=/i,
|
|
79
|
+
reason: 'Overriding core.hooksPath disables git hooks. Fix the underlying failure instead.',
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
const WORKTREE_OVERRIDE_ENV = new Set(['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_PREFIX']);
|
|
3
|
+
function probeEnv() {
|
|
4
|
+
return Object.fromEntries(Object.entries(process.env).filter(([key]) => !WORKTREE_OVERRIDE_ENV.has(key)));
|
|
5
|
+
}
|
|
6
|
+
function run(cwd, args) {
|
|
7
|
+
try {
|
|
8
|
+
const stdout = execFileSync('git', args, {
|
|
9
|
+
cwd,
|
|
10
|
+
encoding: 'utf8',
|
|
11
|
+
env: probeEnv(),
|
|
12
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
13
|
+
timeout: 5_000,
|
|
14
|
+
});
|
|
15
|
+
return { ok: true, stdout };
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
return { ok: false, status: err.status };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function trimmed(cwd, args) {
|
|
22
|
+
const result = run(cwd, args);
|
|
23
|
+
const text = result.ok ? result.stdout.trim() : '';
|
|
24
|
+
return text === '' ? undefined : text;
|
|
25
|
+
}
|
|
26
|
+
const gitCurrentBranch = (cwd) => trimmed(cwd, ['branch', '--show-current']);
|
|
27
|
+
const gitConfigValue = (cwd, key) => trimmed(cwd, ['config', '--get', key]);
|
|
28
|
+
// Full object id a fully qualified ref names, or undefined when the ref is missing or git fails.
|
|
29
|
+
const gitResolveRef = (cwd, ref) => trimmed(cwd, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);
|
|
30
|
+
// `merge-base --is-ancestor` is exit-code-only: 0 = ancestor, 1 = provably not, anything else
|
|
31
|
+
// (128 for an unknown ref, a timeout, a missing binary) is indeterminate and fails open.
|
|
32
|
+
function gitIsAncestor(cwd, ancestor, descendant) {
|
|
33
|
+
const result = run(cwd, ['merge-base', '--is-ancestor', ancestor, descendant]);
|
|
34
|
+
if (result.ok)
|
|
35
|
+
return true;
|
|
36
|
+
return result.status === 1 ? false : undefined;
|
|
37
|
+
}
|
|
38
|
+
export function gitRemoteVerbose(cwd) {
|
|
39
|
+
const result = run(cwd, ['remote', '-v']);
|
|
40
|
+
return result.ok ? result.stdout : undefined;
|
|
41
|
+
}
|
|
42
|
+
// `config --get-regexp` exits 1 when nothing matches, which is an empty answer, not a failure.
|
|
43
|
+
export function gitConfiguredRemoteDefaults(cwd) {
|
|
44
|
+
const result = run(cwd, ['config', '--get-regexp', '^remote\\..+\\.gh-resolved$']);
|
|
45
|
+
if (result.ok)
|
|
46
|
+
return result.stdout;
|
|
47
|
+
return result.status === 1 ? '' : undefined;
|
|
48
|
+
}
|
|
49
|
+
export const defaultGitProbe = {
|
|
50
|
+
currentBranch: gitCurrentBranch,
|
|
51
|
+
configValue: gitConfigValue,
|
|
52
|
+
isAncestor: gitIsAncestor,
|
|
53
|
+
resolveRef: gitResolveRef,
|
|
54
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every lowercased owner of a checkout's GitHub repositories, read the way gh reads them: the fetch
|
|
3
|
+
* URLs of `git remote -v` plus any `gh repo set-default` (`remote.<name>.gh-resolved`). Hostless
|
|
4
|
+
* (local-path) remotes are ignored, like gh does; undefined when the checkout can't be read, prints
|
|
5
|
+
* a remote line the hook doesn't recognize, or has a hosted remote or set-default that isn't
|
|
6
|
+
* OWNER/REPO.
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkoutOwners(cwd: string): ReadonlySet<string> | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* A checkout's owner when {@link checkoutOwners} finds exactly one, so whichever remote gh picks is
|
|
11
|
+
* that owner's; undefined when there are none or several.
|
|
12
|
+
*/
|
|
13
|
+
export declare function checkoutOwner(cwd: string): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The owners a session's own checkout belongs to: its {@link checkoutOwners} plus the owner of its
|
|
16
|
+
* root `package.json` `repository`, so a fork-only checkout still counts the upstream it declares.
|
|
17
|
+
* Undefined — keep every content rule — when either is unreadable, the declared repository isn't
|
|
18
|
+
* a hosted OWNER/REPO, or no owner is known at all.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sessionHomeOwners(worktreeRoot: string): ReadonlySet<string> | undefined;
|
|
21
|
+
export declare function ownerOfRepoSelector(value: string): string | undefined;
|
|
22
|
+
export declare function githubOwner(value: string): string | undefined;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { gitConfiguredRemoteDefaults, gitRemoteVerbose } from "./git-process.mjs";
|
|
4
|
+
// GitHub's owner-name characters. A shell expansion (`$OWNER`, a glob, `~`) never matches, so an
|
|
5
|
+
// owner the hook can't read literally is never mistaken for a different one.
|
|
6
|
+
const GITHUB_OWNER = /^[a-z\d_][a-z\d_-]*$/i;
|
|
7
|
+
const REPO_SELECTOR_CHARACTERS = /^[\w.:@/-]+$/;
|
|
8
|
+
// One `git remote -v` line: `<name>\t<url> (fetch|push)`, which a partial clone suffixes with its
|
|
9
|
+
// ` [<filter>]`.
|
|
10
|
+
const REMOTE_LINE = /^[^\t]+\t(.+) \((fetch|push)\)(?: \[[^\]]*\])?$/;
|
|
11
|
+
/**
|
|
12
|
+
* Every lowercased owner of a checkout's GitHub repositories, read the way gh reads them: the fetch
|
|
13
|
+
* URLs of `git remote -v` plus any `gh repo set-default` (`remote.<name>.gh-resolved`). Hostless
|
|
14
|
+
* (local-path) remotes are ignored, like gh does; undefined when the checkout can't be read, prints
|
|
15
|
+
* a remote line the hook doesn't recognize, or has a hosted remote or set-default that isn't
|
|
16
|
+
* OWNER/REPO.
|
|
17
|
+
*/
|
|
18
|
+
export function checkoutOwners(cwd) {
|
|
19
|
+
const remotes = gitRemoteVerbose(cwd);
|
|
20
|
+
const defaults = gitConfiguredRemoteDefaults(cwd);
|
|
21
|
+
if (remotes === undefined || defaults === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const owners = new Set();
|
|
25
|
+
for (const line of remotes.split('\n').filter(Boolean)) {
|
|
26
|
+
const owner = remoteLineOwner(line);
|
|
27
|
+
if (owner === undefined) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
if (owner !== null) {
|
|
31
|
+
owners.add(owner);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (const line of defaults.split('\n')) {
|
|
35
|
+
const value = line.slice(line.indexOf(' ') + 1);
|
|
36
|
+
if (line === '' || value === 'base') {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const owner = ownerOfRepoSelector(value);
|
|
40
|
+
if (owner === undefined) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
owners.add(owner);
|
|
44
|
+
}
|
|
45
|
+
return owners;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A checkout's owner when {@link checkoutOwners} finds exactly one, so whichever remote gh picks is
|
|
49
|
+
* that owner's; undefined when there are none or several.
|
|
50
|
+
*/
|
|
51
|
+
export function checkoutOwner(cwd) {
|
|
52
|
+
const owners = checkoutOwners(cwd);
|
|
53
|
+
return owners?.size === 1 ? [...owners][0] : undefined;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The owners a session's own checkout belongs to: its {@link checkoutOwners} plus the owner of its
|
|
57
|
+
* root `package.json` `repository`, so a fork-only checkout still counts the upstream it declares.
|
|
58
|
+
* Undefined — keep every content rule — when either is unreadable, the declared repository isn't
|
|
59
|
+
* a hosted OWNER/REPO, or no owner is known at all.
|
|
60
|
+
*/
|
|
61
|
+
export function sessionHomeOwners(worktreeRoot) {
|
|
62
|
+
const owners = checkoutOwners(worktreeRoot);
|
|
63
|
+
const declared = declaredRepositoryOwner(worktreeRoot);
|
|
64
|
+
if (owners === undefined || declared === undefined) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
const home = declared === null ? owners : new Set([...owners, declared]);
|
|
68
|
+
return home.size === 0 ? undefined : home;
|
|
69
|
+
}
|
|
70
|
+
// gh's `[HOST/]OWNER/REPO` or repository URL form.
|
|
71
|
+
export function ownerOfRepoSelector(value) {
|
|
72
|
+
const path = value.replace(/^https?:\/\//i, '').replace(/\/$/, '');
|
|
73
|
+
const segments = path.split('/');
|
|
74
|
+
if (!REPO_SELECTOR_CHARACTERS.test(path) || segments.length < 2 || segments.length > 3) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return segments.includes('') ? undefined : githubOwner(segments[segments.length - 2]);
|
|
78
|
+
}
|
|
79
|
+
export function githubOwner(value) {
|
|
80
|
+
return GITHUB_OWNER.test(value) ? value.toLowerCase() : undefined;
|
|
81
|
+
}
|
|
82
|
+
// null when package.json is absent or declares no repository; undefined when it can't be read or
|
|
83
|
+
// the declaration isn't a hosted OWNER/REPO URL (npm's bare `owner/repo` shorthand included).
|
|
84
|
+
function declaredRepositoryOwner(root) {
|
|
85
|
+
let manifest;
|
|
86
|
+
try {
|
|
87
|
+
manifest = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
return err.code === 'ENOENT' ? null : undefined;
|
|
91
|
+
}
|
|
92
|
+
const repository = manifest?.repository;
|
|
93
|
+
if (repository === undefined) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const url = typeof repository === 'string' ? repository : repository?.url;
|
|
97
|
+
return typeof url === 'string' ? (ownerOfRemoteUrl(url) ?? undefined) : undefined;
|
|
98
|
+
}
|
|
99
|
+
// null for a push line or a hostless fetch URL; undefined for a line the hook doesn't recognize.
|
|
100
|
+
function remoteLineOwner(line) {
|
|
101
|
+
const match = REMOTE_LINE.exec(line);
|
|
102
|
+
if (match === null) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return match[2] === 'push' ? null : ownerOfRemoteUrl(match[1]);
|
|
106
|
+
}
|
|
107
|
+
// null for a hostless remote gh ignores (a local path or file://); undefined for a hosted URL that
|
|
108
|
+
// isn't OWNER/REPO.
|
|
109
|
+
function ownerOfRemoteUrl(url) {
|
|
110
|
+
const withScheme = /^([a-z][a-z\d+.-]*):\/\/([^/]*)(.*)$/i.exec(url);
|
|
111
|
+
if (withScheme !== null) {
|
|
112
|
+
const [, scheme, host, path] = withScheme;
|
|
113
|
+
return scheme.toLowerCase() === 'file' || host === '' ? null : ownerOfRemotePath(path);
|
|
114
|
+
}
|
|
115
|
+
// git's scp-like `[user@]host:path` form needs a colon before any slash.
|
|
116
|
+
const scpLike = /^[^/:]+:(.*)$/.exec(url);
|
|
117
|
+
return scpLike === null ? null : ownerOfRemotePath(scpLike[1]);
|
|
118
|
+
}
|
|
119
|
+
function ownerOfRemotePath(path) {
|
|
120
|
+
const segments = path.replace(/^\/+|\/+$/g, '').split('/');
|
|
121
|
+
return segments.length === 2 && segments[1] !== '' ? githubOwner(segments[0]) : undefined;
|
|
122
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The command text and every script nested in it that the GitHub policies read. A heredoc body is
|
|
3
|
+
* data unless a shell may read it as its script, but an unquoted-delimiter body still runs its
|
|
4
|
+
* command substitutions, so each candidate is read with its bodies blanked.
|
|
5
|
+
*/
|
|
6
|
+
export declare function commandsToInspectForGitHubPolicy(command: string): string[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { extractShellCommandArguments, extractShellCommandSubstitutions, stripNonShellHeredocBodies, } from "../shell-parse/index.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* The command text and every script nested in it that the GitHub policies read. A heredoc body is
|
|
4
|
+
* data unless a shell may read it as its script, but an unquoted-delimiter body still runs its
|
|
5
|
+
* command substitutions, so each candidate is read with its bodies blanked.
|
|
6
|
+
*/
|
|
7
|
+
export function commandsToInspectForGitHubPolicy(command) {
|
|
8
|
+
const commands = [command.replace(/\\\n/g, ' ')];
|
|
9
|
+
const inspected = new Set();
|
|
10
|
+
for (const command of commands) {
|
|
11
|
+
const { bodySubstitutions, shellBodies, textWithoutBodies: candidate, } = stripNonShellHeredocBodies(command);
|
|
12
|
+
if (inspected.has(candidate)) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
inspected.add(candidate);
|
|
16
|
+
commands.push(...extractShellCommandArguments(candidate).map(({ command: shellCommand }) => shellCommand), ...extractShellCommandSubstitutions(candidate), ...shellBodies, ...bodySubstitutions);
|
|
17
|
+
}
|
|
18
|
+
return [...inspected];
|
|
19
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Working directory the `gh` token at `index` would see after sequential
|
|
3
|
+
* command-local `cd` and its own `env -C` wrappers. `baseCwd` is session
|
|
4
|
+
* `hookCwd`. Returns `undefined` when cwd is unknown so callers fail open
|
|
5
|
+
* instead of using the session checkout. Absolute `cd` after `&&`/`;` and an
|
|
6
|
+
* absolute `env -C` recover a known directory.
|
|
7
|
+
*/
|
|
8
|
+
export declare function commandCwd(tokens: string[], index: number, baseCwd: string): string | undefined;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
2
|
+
import { commandPrefixAt, commandSegmentStart } from "./github-command-position.mjs";
|
|
3
|
+
import { isShellCommandSeparator, nextShellCommandSeparatorIndex, } from "../shell-parse/index.mjs";
|
|
4
|
+
const CD_JOINERS = new Set(['&&', ';', '\n', '(']);
|
|
5
|
+
const CONDITIONAL_PREFIXES = new Set(['then', 'else', 'elif', 'do']);
|
|
6
|
+
const UNRESOLVED_DIRECTORY = /[$`~*?[{]/;
|
|
7
|
+
// Wrappers that still run the shell's own `cd` builtin; the rest exec a separate `cd` process
|
|
8
|
+
// whose directory change dies with it.
|
|
9
|
+
const BUILTIN_CD_WRAPPERS = new Set(['builtin', 'command', 'time']);
|
|
10
|
+
/**
|
|
11
|
+
* Working directory the `gh` token at `index` would see after sequential
|
|
12
|
+
* command-local `cd` and its own `env -C` wrappers. `baseCwd` is session
|
|
13
|
+
* `hookCwd`. Returns `undefined` when cwd is unknown so callers fail open
|
|
14
|
+
* instead of using the session checkout. Absolute `cd` after `&&`/`;` and an
|
|
15
|
+
* absolute `env -C` recover a known directory.
|
|
16
|
+
*/
|
|
17
|
+
export function commandCwd(tokens, index, baseCwd) {
|
|
18
|
+
const shellCwd = sequentialShellCwd(tokens, index, baseCwd);
|
|
19
|
+
const prefix = commandPrefixAt(tokens, index);
|
|
20
|
+
return prefix === null ? shellCwd : applyEnvChdir(prefix, shellCwd);
|
|
21
|
+
}
|
|
22
|
+
function applyEnvChdir(prefix, shellCwd) {
|
|
23
|
+
let current = shellCwd;
|
|
24
|
+
for (const directory of prefix.chdir) {
|
|
25
|
+
if (UNRESOLVED_DIRECTORY.test(directory))
|
|
26
|
+
return undefined;
|
|
27
|
+
if (isAbsolute(directory))
|
|
28
|
+
current = resolve(directory);
|
|
29
|
+
else
|
|
30
|
+
current = current === undefined ? undefined : resolve(current, directory);
|
|
31
|
+
}
|
|
32
|
+
return current;
|
|
33
|
+
}
|
|
34
|
+
function sequentialShellCwd(tokens, index, baseCwd) {
|
|
35
|
+
const stack = [baseCwd];
|
|
36
|
+
let functionDepth = 0;
|
|
37
|
+
for (let cursor = 0; cursor < index; cursor += 1) {
|
|
38
|
+
const token = tokens[cursor];
|
|
39
|
+
if (token === '{') {
|
|
40
|
+
// Inside a function body every nested `{` also opens a group, so its `}` must not end the body.
|
|
41
|
+
if (functionDepth > 0 || tokens[cursor - 1] === ')' || tokens[cursor - 2] === 'function') {
|
|
42
|
+
functionDepth += 1;
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (token === '}') {
|
|
47
|
+
if (functionDepth > 0)
|
|
48
|
+
functionDepth -= 1;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (token === '(') {
|
|
52
|
+
stack.push(stack.at(-1));
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (token === ')') {
|
|
56
|
+
if (stack.length > 1)
|
|
57
|
+
stack.pop();
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (functionDepth > 0)
|
|
61
|
+
continue;
|
|
62
|
+
if (token !== 'cd' || !runsBuiltinCd(tokens, cursor))
|
|
63
|
+
continue;
|
|
64
|
+
const joinerIndex = nextShellCommandSeparatorIndex(tokens, cursor);
|
|
65
|
+
const joiner = joinerIndex < tokens.length ? tokens[joinerIndex] : undefined;
|
|
66
|
+
if (joiner === undefined || joinerIndex >= index)
|
|
67
|
+
continue;
|
|
68
|
+
const previous = previousJoiner(tokens, cursor);
|
|
69
|
+
if (previous === '|')
|
|
70
|
+
continue;
|
|
71
|
+
if (joiner === '||' || previous === '||') {
|
|
72
|
+
stack[stack.length - 1] = undefined;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!CD_JOINERS.has(joiner))
|
|
76
|
+
continue;
|
|
77
|
+
if (cdIsConditional(tokens, cursor)) {
|
|
78
|
+
stack[stack.length - 1] = undefined;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const directory = cdDirectoryOperand(tokens, cursor);
|
|
82
|
+
if (directory === undefined) {
|
|
83
|
+
stack[stack.length - 1] = undefined;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const current = stack.at(-1);
|
|
87
|
+
if (isAbsolute(directory)) {
|
|
88
|
+
stack[stack.length - 1] = resolve(directory);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
stack[stack.length - 1] = current === undefined ? undefined : resolve(current, directory);
|
|
92
|
+
}
|
|
93
|
+
return stack.at(-1);
|
|
94
|
+
}
|
|
95
|
+
function runsBuiltinCd(tokens, cdIndex) {
|
|
96
|
+
const prefix = commandPrefixAt(tokens, cdIndex);
|
|
97
|
+
return prefix !== null && prefix.wrappers.every((wrapper) => BUILTIN_CD_WRAPPERS.has(wrapper));
|
|
98
|
+
}
|
|
99
|
+
function cdIsConditional(tokens, cdIndex) {
|
|
100
|
+
return tokens
|
|
101
|
+
.slice(commandSegmentStart(tokens, cdIndex), cdIndex)
|
|
102
|
+
.some((token) => CONDITIONAL_PREFIXES.has(token));
|
|
103
|
+
}
|
|
104
|
+
function previousJoiner(tokens, index) {
|
|
105
|
+
const start = commandSegmentStart(tokens, index);
|
|
106
|
+
return start > 0 ? tokens[start - 1] : undefined;
|
|
107
|
+
}
|
|
108
|
+
function cdDirectoryOperand(tokens, cdIndex) {
|
|
109
|
+
let operandIndex = cdIndex + 1;
|
|
110
|
+
if (tokens[operandIndex] === '--')
|
|
111
|
+
operandIndex += 1;
|
|
112
|
+
let physical = false;
|
|
113
|
+
while (tokens[operandIndex] === '-P' || tokens[operandIndex] === '-L') {
|
|
114
|
+
if (tokens[operandIndex] === '-P')
|
|
115
|
+
physical = true;
|
|
116
|
+
operandIndex += 1;
|
|
117
|
+
}
|
|
118
|
+
const directory = tokens[operandIndex];
|
|
119
|
+
const rest = tokens[operandIndex + 1];
|
|
120
|
+
if (physical ||
|
|
121
|
+
directory === undefined ||
|
|
122
|
+
isShellCommandSeparator(directory) ||
|
|
123
|
+
directory === '-' ||
|
|
124
|
+
directory.startsWith('-') ||
|
|
125
|
+
UNRESOLVED_DIRECTORY.test(directory) ||
|
|
126
|
+
(rest !== undefined && !isShellCommandSeparator(rest))) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
return directory;
|
|
130
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type CommandPrefix } from '../shell-parse/index.mts';
|
|
2
|
+
export declare function commandSegmentStart(tokens: string[], index: number): number;
|
|
3
|
+
/**
|
|
4
|
+
* The wrapper chain before `tokens[index]` in its command segment, or null when `tokens[index]`
|
|
5
|
+
* is an argument rather than the command the shell runs. See shell-command-wrappers.mts.
|
|
6
|
+
*/
|
|
7
|
+
export declare function commandPrefixAt(tokens: string[], index: number): CommandPrefix | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isGhCommandSeparator } from "./github-options.mjs";
|
|
2
|
+
import { commandSegmentStart as shellSegmentStart, parseCommandPrefix, } from "../shell-parse/index.mjs";
|
|
3
|
+
export function commandSegmentStart(tokens, index) {
|
|
4
|
+
return shellSegmentStart(tokens, index, isGhCommandSeparator);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The wrapper chain before `tokens[index]` in its command segment, or null when `tokens[index]`
|
|
8
|
+
* is an argument rather than the command the shell runs. See shell-command-wrappers.mts.
|
|
9
|
+
*/
|
|
10
|
+
export function commandPrefixAt(tokens, index) {
|
|
11
|
+
return parseCommandPrefix(tokens.slice(commandSegmentStart(tokens, index), index));
|
|
12
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { BlockDecision, GitProbe } from './types.mts';
|
|
2
|
+
export type ResolvedStackPolicy = {
|
|
3
|
+
baseBranch: string;
|
|
4
|
+
remote: string;
|
|
5
|
+
guidance: string;
|
|
6
|
+
draftFollowUp: string;
|
|
7
|
+
git: GitProbe;
|
|
8
|
+
};
|
|
9
|
+
/** Appends the caller's guidance to a reason. */
|
|
10
|
+
export declare function withGuidance(reason: string, guidance: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Effective base `gh pr create` uses when `--base`/`-B` is omitted:
|
|
13
|
+
* `branch.<current>.gh-merge-base`, else undefined (repo default).
|
|
14
|
+
*/
|
|
15
|
+
export declare function configuredPullRequestBase(cwd: string, git: GitProbe): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Root guard for `gh stack init`: a stack rooted off the base branch cannot drain if its parent is
|
|
18
|
+
* ever abandoned. Scoped to `init` only, since `gh stack add` only appends to an existing stack. An
|
|
19
|
+
* explicit `--base` needs no checkout; the HEAD ancestry and local-base freshness checks read
|
|
20
|
+
* `cwd`, so an unknown `cwd` skips just those. gh-stack roots the first layer at the local base
|
|
21
|
+
* branch, never the remote one, so a stale local base misroots the stack even when HEAD passed the
|
|
22
|
+
* ancestry check. A missing local base is fine: gh-stack creates it from the remote.
|
|
23
|
+
*/
|
|
24
|
+
export declare function findStackInitBaseBlock(optionTokens: string[], cwd: string | undefined, policy: ResolvedStackPolicy): BlockDecision | null;
|
|
25
|
+
export declare function findHandRolledStackBaseBlock(action: string, optionTokens: string[], cwd: string | undefined, policy: ResolvedStackPolicy): BlockDecision | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { lastNamedOption } from "./github-option-flags.mjs";
|
|
2
|
+
/** Appends the caller's guidance to a reason. */
|
|
3
|
+
export function withGuidance(reason, guidance) {
|
|
4
|
+
return guidance === '' ? reason : `${reason} ${guidance}`;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Effective base `gh pr create` uses when `--base`/`-B` is omitted:
|
|
8
|
+
* `branch.<current>.gh-merge-base`, else undefined (repo default).
|
|
9
|
+
*/
|
|
10
|
+
export function configuredPullRequestBase(cwd, git) {
|
|
11
|
+
const branch = git.currentBranch(cwd);
|
|
12
|
+
return branch === undefined ? undefined : git.configValue(cwd, `branch.${branch}.gh-merge-base`);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Root guard for `gh stack init`: a stack rooted off the base branch cannot drain if its parent is
|
|
16
|
+
* ever abandoned. Scoped to `init` only, since `gh stack add` only appends to an existing stack. An
|
|
17
|
+
* explicit `--base` needs no checkout; the HEAD ancestry and local-base freshness checks read
|
|
18
|
+
* `cwd`, so an unknown `cwd` skips just those. gh-stack roots the first layer at the local base
|
|
19
|
+
* branch, never the remote one, so a stale local base misroots the stack even when HEAD passed the
|
|
20
|
+
* ancestry check. A missing local base is fine: gh-stack creates it from the remote.
|
|
21
|
+
*/
|
|
22
|
+
export function findStackInitBaseBlock(optionTokens, cwd, policy) {
|
|
23
|
+
const { baseBranch, git, guidance, remote } = policy;
|
|
24
|
+
const remoteBase = `${remote}/${baseBranch}`;
|
|
25
|
+
const base = lastNamedOption(optionTokens, 'base', 'b');
|
|
26
|
+
if (base !== undefined && base !== baseBranch) {
|
|
27
|
+
return {
|
|
28
|
+
reason: withGuidance(`gh stack init must root on ${baseBranch}, not an unmerged branch - omit --base/-b (it defaults to the repo default branch) or pass --base ${baseBranch}.`, guidance),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (cwd !== undefined && git.isAncestor(cwd, 'HEAD', remoteBase) === false) {
|
|
32
|
+
return {
|
|
33
|
+
reason: withGuidance(`gh stack init must run from a commit already merged into ${remoteBase} (HEAD is not an ancestor of ${remoteBase}) - check out an up-to-date ${baseBranch} before initializing a stack.`, guidance),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const localBase = cwd === undefined ? undefined : git.resolveRef(cwd, `refs/heads/${baseBranch}`);
|
|
37
|
+
const remoteHead = cwd === undefined ? undefined : git.resolveRef(cwd, `refs/remotes/${remote}/${baseBranch}`);
|
|
38
|
+
if (localBase !== undefined && remoteHead !== undefined && localBase !== remoteHead) {
|
|
39
|
+
return {
|
|
40
|
+
reason: withGuidance(`gh stack init roots the stack at local \`${baseBranch}\`, which differs from ${remoteBase} (stale local ${baseBranch}). Fast-forward it first without touching another checkout: if no worktree has ${baseBranch} checked out, run \`git fetch ${remote} ${baseBranch}:${baseBranch}\`; if it is checked out in the primary checkout, have that checkout fast-forward itself - never move ${baseBranch} from this worktree, and do not check it out here.`, guidance),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
// An explicit `--base` needs no checkout; only the configured default reads gh's directory, so a
|
|
46
|
+
// `cwd` the hook cannot resolve skips just that fallback.
|
|
47
|
+
export function findHandRolledStackBaseBlock(action, optionTokens, cwd, policy) {
|
|
48
|
+
const base = lastNamedOption(optionTokens, 'base', 'B');
|
|
49
|
+
const effectiveBase = base ??
|
|
50
|
+
(cwd !== undefined && (action === 'create' || action === 'new')
|
|
51
|
+
? configuredPullRequestBase(cwd, policy.git)
|
|
52
|
+
: undefined);
|
|
53
|
+
if (effectiveBase === undefined || effectiveBase === policy.baseBranch) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
reason: withGuidance(`PRs must target ${policy.baseBranch} unless they are part of a native GitHub stack. Use \`gh stack\`, not \`gh pr create/edit --base <unmerged-branch>\`.`, policy.guidance),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type GhInvocation = {
|
|
2
|
+
action: string;
|
|
3
|
+
area: string;
|
|
4
|
+
arguments: string[];
|
|
5
|
+
optionTokenIndexes: number[];
|
|
6
|
+
optionTokens: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare function parseGhOrGhStackInvocation(tokens: string[], index: number): GhInvocation | null;
|
|
9
|
+
export declare function parseGhInvocation(tokens: string[], ghIndex: number): GhInvocation | null;
|