@ethlete/agent-rules 0.1.0-next.5 → 0.1.0-next.6

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +167 -3
  3. package/content/git-hooks/post-checkout.sh +10 -0
  4. package/content/git-hooks/pre-push.sh +5 -0
  5. package/content/hooks/context-warning.py +39 -11
  6. package/content/skills/git-flow/SKILL.md +83 -0
  7. package/content/skills/handoff/SKILL.md +4 -0
  8. package/content/skills/query/SKILL.md +17 -13
  9. package/package.json +12 -1
  10. package/src/index.js +10 -5
  11. package/src/index.js.map +1 -1
  12. package/src/lib/config.d.ts +28 -0
  13. package/src/lib/config.js +20 -3
  14. package/src/lib/config.js.map +1 -1
  15. package/src/lib/git-flow/build.d.ts +35 -0
  16. package/src/lib/git-flow/build.js +24 -0
  17. package/src/lib/git-flow/build.js.map +1 -0
  18. package/src/lib/git-flow/config.d.ts +59 -0
  19. package/src/lib/git-flow/config.js +50 -0
  20. package/src/lib/git-flow/config.js.map +1 -0
  21. package/src/lib/git-flow/index.d.ts +5 -0
  22. package/src/lib/git-flow/index.js +9 -0
  23. package/src/lib/git-flow/index.js.map +1 -0
  24. package/src/lib/git-flow/parse.d.ts +49 -0
  25. package/src/lib/git-flow/parse.js +274 -0
  26. package/src/lib/git-flow/parse.js.map +1 -0
  27. package/src/lib/git-flow/start.d.ts +22 -0
  28. package/src/lib/git-flow/start.js +24 -0
  29. package/src/lib/git-flow/start.js.map +1 -0
  30. package/src/lib/git-flow/validate.d.ts +34 -0
  31. package/src/lib/git-flow/validate.js +72 -0
  32. package/src/lib/git-flow/validate.js.map +1 -0
  33. package/src/lib/git-flow-command.d.ts +4 -0
  34. package/src/lib/git-flow-command.js +157 -0
  35. package/src/lib/git-flow-command.js.map +1 -0
  36. package/src/lib/git-flow-repair.d.ts +17 -0
  37. package/src/lib/git-flow-repair.js +150 -0
  38. package/src/lib/git-flow-repair.js.map +1 -0
  39. package/src/lib/git-flow-start.d.ts +20 -0
  40. package/src/lib/git-flow-start.js +147 -0
  41. package/src/lib/git-flow-start.js.map +1 -0
  42. package/src/lib/git.d.ts +27 -0
  43. package/src/lib/git.js +49 -0
  44. package/src/lib/git.js.map +1 -0
  45. package/src/lib/gitlab.d.ts +35 -0
  46. package/src/lib/gitlab.js +98 -0
  47. package/src/lib/gitlab.js.map +1 -0
  48. package/src/lib/jira.d.ts +28 -0
  49. package/src/lib/jira.js +83 -0
  50. package/src/lib/jira.js.map +1 -0
  51. package/src/lib/plan.js +20 -2
  52. package/src/lib/plan.js.map +1 -1
  53. package/src/lib/prompt.d.ts +8 -0
  54. package/src/lib/prompt.js +27 -0
  55. package/src/lib/prompt.js.map +1 -0
  56. package/src/lib/render.d.ts +12 -1
  57. package/src/lib/render.js +23 -6
  58. package/src/lib/render.js.map +1 -1
  59. package/src/lib/targets/git-hooks.d.ts +25 -0
  60. package/src/lib/targets/git-hooks.js +70 -0
  61. package/src/lib/targets/git-hooks.js.map +1 -0
@@ -0,0 +1,22 @@
1
+ import { BranchNameSpec } from './build';
2
+ import { GitFlowConfig } from './config';
3
+ import { BranchParseResult } from './parse';
4
+ export type StartPlan = {
5
+ branch: string;
6
+ /** The branch to create the new one from. Absent only when `problems` says why. */
7
+ base?: string;
8
+ mrTargets: string[];
9
+ parse: BranchParseResult;
10
+ /** Empty when the plan is safe to execute; every entry is a reason to refuse. */
11
+ problems: string[];
12
+ };
13
+ /**
14
+ * The plan a caller must show before it writes anything: the branch name, the base to branch from
15
+ * and the merge request target. Built through `buildBranchName` and then re-parsed, so a spec the
16
+ * grammar cannot express — a key the project's prefixes reject, a parent that is itself
17
+ * non-conforming — comes back as a problem instead of as a branch somebody has to delete again.
18
+ */
19
+ export declare const planStart: (options: {
20
+ spec: BranchNameSpec;
21
+ config: GitFlowConfig;
22
+ }) => StartPlan;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.planStart = void 0;
4
+ const build_1 = require("./build");
5
+ const parse_1 = require("./parse");
6
+ /**
7
+ * The plan a caller must show before it writes anything: the branch name, the base to branch from
8
+ * and the merge request target. Built through `buildBranchName` and then re-parsed, so a spec the
9
+ * grammar cannot express — a key the project's prefixes reject, a parent that is itself
10
+ * non-conforming — comes back as a problem instead of as a branch somebody has to delete again.
11
+ */
12
+ const planStart = (options) => {
13
+ const { spec, config } = options;
14
+ const branch = (0, build_1.buildBranchName)({ spec, config });
15
+ const parse = (0, parse_1.parseBranch)({ branch, config });
16
+ const problems = [
17
+ ...(parse.kind === spec.kind ? [] : [`"${branch}" parses as ${parse.kind}, not ${spec.kind}.`]),
18
+ ...parse.findings.map((finding) => finding.message),
19
+ ...(parse.expectedBase ? [] : [`"${branch}" has no base branch to branch from.`]),
20
+ ];
21
+ return { branch, base: parse.expectedBase, mrTargets: parse.expectedMrTargets, parse, problems };
22
+ };
23
+ exports.planStart = planStart;
24
+ //# sourceMappingURL=start.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start.js","sourceRoot":"","sources":["../../../../../../libs/agent-rules/src/lib/git-flow/start.ts"],"names":[],"mappings":";;;AAAA,mCAA0D;AAE1D,mCAAyD;AAYzD;;;;;GAKG;AACI,MAAM,SAAS,GAAG,CAAC,OAAwD,EAAa,EAAE;IAC/F,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACjC,MAAM,MAAM,GAAG,IAAA,uBAAe,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,IAAA,mBAAW,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAE9C,MAAM,QAAQ,GAAG;QACf,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,eAAe,KAAK,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAC/F,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;QACnD,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,MAAM,sCAAsC,CAAC,CAAC;KAClF,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,YAAY,EAAE,SAAS,EAAE,KAAK,CAAC,iBAAiB,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACnG,CAAC,CAAC;AAZW,QAAA,SAAS,aAYpB"}
@@ -0,0 +1,34 @@
1
+ import { GitFlowConfig, GitFlowRule, GitFlowSeverity } from './config';
2
+ import { BranchParseResult, GitFlowFinding } from './parse';
3
+ export type GitFlowResolvedFinding = GitFlowFinding & {
4
+ severity: Exclude<GitFlowSeverity, 'off'>;
5
+ };
6
+ export type GitFlowReport = {
7
+ branch: string;
8
+ target?: string;
9
+ parse: BranchParseResult;
10
+ findings: GitFlowResolvedFinding[];
11
+ ok: boolean;
12
+ /** At least one finding resolved to `error`, so the hook or the CI job should exit non-zero. */
13
+ blocked: boolean;
14
+ };
15
+ /**
16
+ * `advisory` caps the *naming* rules at `warn`, because the whole naming zoo is deliberately
17
+ * accepted during the grace period. `protected-push` and `wrong-mr-target` are not naming rules
18
+ * and keep their configured severity in both modes — that is what lets `wrong-mr-target` be
19
+ * promoted to `error` before the naming grace period ends.
20
+ */
21
+ export declare const resolveSeverity: (options: {
22
+ rule: GitFlowRule;
23
+ config: GitFlowConfig;
24
+ }) => GitFlowSeverity;
25
+ /**
26
+ * The single place a verdict is computed — the CLI, the git hook, the CI job and timetrack all
27
+ * call this rather than re-deriving the rules.
28
+ */
29
+ export declare const validateBranch: (options: {
30
+ branch: string;
31
+ config: GitFlowConfig;
32
+ target?: string;
33
+ push?: boolean;
34
+ }) => GitFlowReport;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateBranch = exports.resolveSeverity = void 0;
4
+ const parse_1 = require("./parse");
5
+ /**
6
+ * `advisory` caps the *naming* rules at `warn`, because the whole naming zoo is deliberately
7
+ * accepted during the grace period. `protected-push` and `wrong-mr-target` are not naming rules
8
+ * and keep their configured severity in both modes — that is what lets `wrong-mr-target` be
9
+ * promoted to `error` before the naming grace period ends.
10
+ */
11
+ const resolveSeverity = (options) => {
12
+ const { rule, config } = options;
13
+ const configured = config.severity[rule];
14
+ if (configured === 'off')
15
+ return 'off';
16
+ if (rule === 'protected-push' || rule === 'wrong-mr-target')
17
+ return configured;
18
+ return config.enforcement === 'gated' ? configured : 'warn';
19
+ };
20
+ exports.resolveSeverity = resolveSeverity;
21
+ const mrTargetFindings = (options) => {
22
+ const { parse, target, config } = options;
23
+ if (parse.kind === 'unknown' || parse.expectedMrTargets.includes(target))
24
+ return [];
25
+ // A flat feature branch is how the zoo spells a sub-branch of an integration branch, and `dev-*`
26
+ // is an integration branch under its old name — so any main feature may target any other. Tighten
27
+ // this and the rule fires on the team's entire real workflow.
28
+ if (parse.kind === 'main-feature' && (0, parse_1.parseBranch)({ branch: target, config }).kind === 'main-feature')
29
+ return [];
30
+ const expected = parse.expectedMrTargets;
31
+ return [
32
+ {
33
+ rule: 'wrong-mr-target',
34
+ message: expected.length
35
+ ? `A ${parse.kind} branch must merge into ${expected.join(' or ')}, not ${target}.`
36
+ : `A ${parse.kind} branch has no merge request target.`,
37
+ suggestion: expected[0],
38
+ },
39
+ ];
40
+ };
41
+ /**
42
+ * The single place a verdict is computed — the CLI, the git hook, the CI job and timetrack all
43
+ * call this rather than re-deriving the rules.
44
+ */
45
+ const validateBranch = (options) => {
46
+ const { config, push } = options;
47
+ const branch = (0, parse_1.stripRefPrefix)(options.branch);
48
+ const target = options.target ? (0, parse_1.stripRefPrefix)(options.target) : undefined;
49
+ const parse = (0, parse_1.parseBranch)({ branch, config });
50
+ const findings = [...parse.findings];
51
+ if (target)
52
+ findings.push(...mrTargetFindings({ parse, target, config }));
53
+ if (push && parse.kind === 'protected') {
54
+ findings.push({
55
+ rule: 'protected-push',
56
+ message: `${branch} is protected — push a branch and open a merge request.`,
57
+ });
58
+ }
59
+ const resolved = findings
60
+ .map((finding) => (Object.assign(Object.assign({}, finding), { severity: (0, exports.resolveSeverity)({ rule: finding.rule, config }) })))
61
+ .filter((finding) => finding.severity !== 'off');
62
+ return {
63
+ branch,
64
+ target,
65
+ parse,
66
+ findings: resolved,
67
+ ok: resolved.length === 0,
68
+ blocked: resolved.some((finding) => finding.severity === 'error'),
69
+ };
70
+ };
71
+ exports.validateBranch = validateBranch;
72
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../../../libs/agent-rules/src/lib/git-flow/validate.ts"],"names":[],"mappings":";;;AACA,mCAAyF;AAczF;;;;;GAKG;AACI,MAAM,eAAe,GAAG,CAAC,OAAqD,EAAmB,EAAE;IACxG,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IACjC,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEzC,IAAI,UAAU,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IACvC,IAAI,IAAI,KAAK,gBAAgB,IAAI,IAAI,KAAK,iBAAiB;QAAE,OAAO,UAAU,CAAC;IAE/E,OAAO,MAAM,CAAC,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9D,CAAC,CAAC;AARW,QAAA,eAAe,mBAQ1B;AAEF,MAAM,gBAAgB,GAAG,CAAC,OAIzB,EAAoB,EAAE;IACrB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IA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I,CAAC,GAAG,gBAAgB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAE1E,IAAI,IAAI,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QACvC,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,GAAG,MAAM,yDAAyD;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,MAAM,QAAQ,GAAG,QAAQ;SACtB,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,iCAAM,OAAO,KAAE,QAAQ,EAAE,IAAA,uBAAe,EAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAG,CAAC;SAC7F,MAAM,CAAC,CAAC,OAAO,EAAqC,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC;IAEtF,OAAO;QACL,MAAM;QACN,MAAM;QACN,KAAK;QACL,QAAQ,EAAE,QAAQ;QAClB,EAAE,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC;QACzB,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;KAClE,CAAC;AACJ,CAAC,CAAC;AAjCW,QAAA,cAAc,kBAiCzB"}
@@ -0,0 +1,4 @@
1
+ export declare const gitFlowCommand: (options: {
2
+ root: string;
3
+ argv: string[];
4
+ }) => Promise<number>;
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gitFlowCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const config_1 = require("./config");
6
+ const git_1 = require("./git");
7
+ const git_flow_1 = require("./git-flow");
8
+ const git_flow_repair_1 = require("./git-flow-repair");
9
+ const git_flow_start_1 = require("./git-flow-start");
10
+ const describeParse = (parse) => {
11
+ const lines = [` kind ${parse.kind}${parse.deprecated ? ' (deprecated spelling)' : ''}`];
12
+ if (parse.type)
13
+ lines.push(` type ${parse.type}`);
14
+ if (parse.storyKey)
15
+ lines.push(` story ${parse.storyKey}${parse.inheritedFrom ? ` (from ${parse.inheritedFrom})` : ''}`);
16
+ if (parse.taskKey)
17
+ lines.push(` task ${parse.taskKey}`);
18
+ if (parse.subject)
19
+ lines.push(` subject ${parse.subject}`);
20
+ if (parse.parent)
21
+ lines.push(` parent ${parse.parent}`);
22
+ if (parse.expectedBase)
23
+ lines.push(` base ${parse.expectedBase}`);
24
+ lines.push(` merges to ${parse.expectedMrTargets.join(' or ') || '—'}`);
25
+ if (parse.suggestedName)
26
+ lines.push(` rename to ${parse.suggestedName}`);
27
+ return lines;
28
+ };
29
+ const checkOne = (options) => {
30
+ const { config, branch, target, push } = options;
31
+ const report = (0, git_flow_1.validateBranch)({ branch, target, push, config });
32
+ console.log(`Branch: ${report.branch}${report.target ? ` → ${report.target}` : ''}`);
33
+ if (report.ok) {
34
+ console.log(` ok ${report.parse.kind}`);
35
+ return 0;
36
+ }
37
+ for (const finding of report.findings) {
38
+ console.log(` ${finding.severity === 'error' ? 'error ' : 'warn '} ${finding.rule} ${finding.message}`);
39
+ }
40
+ if (report.blocked) {
41
+ console.error('\nBlocked by the finding(s) above.');
42
+ return 1;
43
+ }
44
+ console.log(`\nAdvisory only — nothing is blocked. Run \`ethlete-agents git-flow explain ${report.branch}\` for the full parse.`);
45
+ return 0;
46
+ };
47
+ const checkAll = (options) => {
48
+ var _a;
49
+ const { root, config } = options;
50
+ const branches = (0, git_1.allBranches)(root);
51
+ const counts = new Map();
52
+ const offenders = [];
53
+ let conforming = 0;
54
+ let counted = 0;
55
+ let deprecated = 0;
56
+ for (const branch of branches) {
57
+ const parse = (0, git_flow_1.parseBranch)({ branch, config });
58
+ for (const finding of parse.findings)
59
+ counts.set(finding.rule, ((_a = counts.get(finding.rule)) !== null && _a !== void 0 ? _a : 0) + 1);
60
+ if (parse.kind === 'protected')
61
+ continue;
62
+ if (parse.deprecated) {
63
+ deprecated++;
64
+ continue;
65
+ }
66
+ counted++;
67
+ if (parse.ok)
68
+ conforming++;
69
+ else
70
+ offenders.push(` ${branch}${parse.suggestedName ? ` → ${parse.suggestedName}` : ''}`);
71
+ }
72
+ const ratio = counted === 0 ? 100 : Math.round((conforming / counted) * 100);
73
+ console.log(`${conforming}/${counted} branches conform (${ratio}%), ${deprecated} deprecated, ${branches.length} scanned.`);
74
+ if (counts.size > 0) {
75
+ console.log('\nFindings');
76
+ [...counts.entries()]
77
+ .sort((a, b) => b[1] - a[1])
78
+ .forEach(([rule, count]) => console.log(` ${String(count).padStart(4)} ${rule}`));
79
+ }
80
+ if (offenders.length > 0) {
81
+ console.log('\nNon-conforming');
82
+ offenders.forEach((line) => console.log(line));
83
+ }
84
+ return 0;
85
+ };
86
+ const FLAGS_WITH_VALUE = ['--target', '--root', '--to', '--key', '--of', '--subject', '--type', '--release'];
87
+ const positionalArgs = (args) => args.filter((entry, index) => { var _a; return !entry.startsWith('--') && !FLAGS_WITH_VALUE.includes((_a = args[index - 1]) !== null && _a !== void 0 ? _a : ''); });
88
+ const flagValue = (args, flag) => {
89
+ const index = args.indexOf(flag);
90
+ return index === -1 ? undefined : args[index + 1];
91
+ };
92
+ const USAGE = `ethlete-agents git-flow — name, check and repair branches against the repo's git flow
93
+
94
+ git-flow start <KEY> Create the correctly named branch off the correct base
95
+ git-flow check [ref] Validate a branch name (default: the current branch)
96
+ git-flow check --all Adoption report over every local and remote branch
97
+ git-flow repair [ref] Rename a non-conforming branch and retarget its merge requests
98
+ git-flow explain [ref] Print what the parser saw
99
+
100
+ Options for check
101
+ --target <branch> Also validate the merge request target
102
+ --push Also report a direct push to a protected branch
103
+
104
+ Options for start
105
+ --subject <text> Use this subject instead of reading the issue from Jira
106
+ --of <branch> Nest under this branch instead of the parent story's own branch
107
+ --type <type> Branch type for a main feature (default: feat)
108
+ --hotfix Branch off production as a hotfix
109
+ --release <date> Create a release branch instead of a feature branch
110
+ --push Push the new branch and set its upstream
111
+
112
+ Options for repair
113
+ --key <KEY> The issue key to put into the new name
114
+ --to <branch> Use this name instead of the derived one
115
+ --no-mr-check Skip the GitLab merge request lookup (only when you know none point at it)
116
+
117
+ Options for start and repair
118
+ --yes Do not ask for confirmation
119
+ --dry-run Print the plan and stop
120
+ `;
121
+ const gitFlowCommand = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
122
+ const { root, argv } = options;
123
+ // The subcommand is the first positional, not `argv[0]` — a global flag like `--root` may precede it.
124
+ const [subcommand, ref] = positionalArgs(argv);
125
+ const rest = argv;
126
+ const loaded = (0, config_1.loadConfig)({ root });
127
+ const config = loaded.gitFlow;
128
+ const target = flagValue(rest, '--target');
129
+ const shared = { root, assumeYes: rest.includes('--yes'), dryRun: rest.includes('--dry-run') };
130
+ if (subcommand === 'check') {
131
+ if (rest.includes('--all'))
132
+ return checkAll({ root, config });
133
+ return checkOne({ root, config, branch: ref !== null && ref !== void 0 ? ref : (0, git_1.currentBranch)(root), target, push: rest.includes('--push') });
134
+ }
135
+ if (subcommand === 'start') {
136
+ return (0, git_flow_start_1.gitFlowStart)(Object.assign(Object.assign({}, shared), { config: loaded, key: ref, subject: flagValue(rest, '--subject'), type: flagValue(rest, '--type'), parent: flagValue(rest, '--of'), hotfix: rest.includes('--hotfix'), releaseDate: flagValue(rest, '--release'), push: rest.includes('--push') }));
137
+ }
138
+ if (subcommand === 'repair') {
139
+ return (0, git_flow_repair_1.gitFlowRepair)(Object.assign(Object.assign({}, shared), { config: loaded, ref, to: flagValue(rest, '--to'), key: flagValue(rest, '--key'), skipMrCheck: rest.includes('--no-mr-check') }));
140
+ }
141
+ if (subcommand === 'explain') {
142
+ const branch = ref !== null && ref !== void 0 ? ref : (0, git_1.currentBranch)(root);
143
+ const parse = (0, git_flow_1.parseBranch)({ branch, config });
144
+ console.log(`Branch: ${parse.branch}`);
145
+ describeParse(parse).forEach((line) => console.log(line));
146
+ if (parse.findings.length > 0) {
147
+ console.log('\nFindings');
148
+ parse.findings.forEach((finding) => console.log(` ${finding.rule} ${finding.message}`));
149
+ }
150
+ console.log(`\nEnforcement: ${config.enforcement}`);
151
+ return 0;
152
+ }
153
+ console.log(USAGE);
154
+ return subcommand === undefined || subcommand === '--help' || subcommand === '-h' ? 0 : 1;
155
+ });
156
+ exports.gitFlowCommand = gitFlowCommand;
157
+ //# sourceMappingURL=git-flow-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-flow-command.js","sourceRoot":"","sources":["../../../../../libs/agent-rules/src/lib/git-flow-command.ts"],"names":[],"mappings":";;;;AAAA,qCAAsC;AACtC,+BAAmD;AACnD,yCAAwG;AACxG,uDAAkD;AAClD,qDAAgD;AAEhD,MAAM,aAAa,GAAG,CAAC,KAAwB,EAAE,EAAE;IACjD,MAAM,KAAK,GAAG,CAAC,eAAe,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAE/F,IAAI,KAAK,CAAC,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,eAAe,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IACxD,IAAI,KAAK,CAAC,QAAQ;QAChB,KAAK,CAAC,IAAI,CAAC,eAAe,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5G,IAAI,KAAK,CAAC,OAAO;QAAE,KAAK,CAAC,IAAI,CAAC,eAAe,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9D,IAAI,KAAK,CAAC,OAAO;QAAE,KAAK,CAAC,IAAI,CAAC,eAAe,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9D,IAAI,KAAK,CAAC,MAAM;QAAE,KAAK,CAAC,IA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9
+ assumeYes: boolean;
10
+ dryRun: boolean;
11
+ };
12
+ /**
13
+ * Renames a non-conforming branch and moves the merge requests aimed at it. Everything that can be
14
+ * checked is checked before the first mutation, and the order of the mutations is chosen so a
15
+ * failure leaves the old branch and every merge request intact.
16
+ */
17
+ export declare const gitFlowRepair: (request: RepairRequest) => Promise<1 | 0>;
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gitFlowRepair = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const git_1 = require("./git");
6
+ const git_flow_1 = require("./git-flow");
7
+ const gitlab_1 = require("./gitlab");
8
+ const prompt_1 = require("./prompt");
9
+ const KEY_PLACEHOLDER = '<KEY>';
10
+ const resolveNewName = (options) => {
11
+ const { branch, to, key, config } = options;
12
+ if (to)
13
+ return to;
14
+ const parse = (0, git_flow_1.parseBranch)({ branch, config: config.gitFlow });
15
+ if (!parse.suggestedName) {
16
+ throw new Error(parse.ok
17
+ ? `${branch} already conforms — nothing to repair.`
18
+ : `No conforming name can be derived from ${branch}. Pass --to <branch>.`);
19
+ }
20
+ if (!parse.suggestedName.includes(KEY_PLACEHOLDER))
21
+ return parse.suggestedName;
22
+ if (!key) {
23
+ throw new Error(`${branch} carries no issue key, so the new name needs one: \`git-flow repair ${branch} --key FIP-1234\` (or --to <branch>).`);
24
+ }
25
+ return parse.suggestedName.replace(KEY_PLACEHOLDER, key.toUpperCase());
26
+ };
27
+ const readRemoteState = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
28
+ const { root, branch, skipMrCheck } = options;
29
+ const remote = (0, git_1.defaultRemote)(root);
30
+ if (!remote || !(0, git_1.remoteBranchExists)({ root, remote, branch }))
31
+ return { pushed: false };
32
+ if (skipMrCheck)
33
+ return { pushed: true, remote, retarget: [] };
34
+ const project = (0, gitlab_1.parseRemoteUrl)((0, git_1.remoteUrl)({ root, remote }));
35
+ const token = (0, gitlab_1.gitLabToken)();
36
+ if (!project || !token) {
37
+ throw new Error([
38
+ `${branch} is pushed to ${remote}, so open merge requests may point at it and must be retargeted.`,
39
+ project
40
+ ? 'Set GITLAB_TOKEN to a token with the "api" scope, or pass --no-mr-check if you know none do.'
41
+ : `The ${remote} URL is not a recognisable GitLab remote. Pass --no-mr-check if no merge request points at ${branch}.`,
42
+ ].join('\n'));
43
+ }
44
+ const mergeRequests = yield (0, gitlab_1.openMergeRequestsFor)({ project, token, branch });
45
+ const blocking = (0, gitlab_1.blockingMergeRequests)({ mergeRequests, branch });
46
+ if (blocking.length > 0) {
47
+ throw new Error([
48
+ `${branch} is the source branch of ${blocking.length} open merge request(s):`,
49
+ ...blocking.map((mr) => ` !${mr.iid} ${mr.title} ${mr.url}`),
50
+ 'GitLab cannot move a merge request to a different source branch, and closing it would lose its discussion.',
51
+ 'Merge or close it first, then repair the branch.',
52
+ ].join('\n'));
53
+ }
54
+ return {
55
+ pushed: true,
56
+ remote,
57
+ retarget: mergeRequests.filter((mr) => mr.targetBranch === branch),
58
+ api: { project, token },
59
+ };
60
+ });
61
+ const describeSteps = (options) => {
62
+ const { branch, newName, remote } = options;
63
+ const steps = [`git branch -m ${branch} ${newName}`];
64
+ if (remote.pushed) {
65
+ steps.push(`git push -u ${remote.remote} ${newName}`);
66
+ steps.push(...remote.retarget.map((mr) => `retarget !${mr.iid} to ${newName}`));
67
+ steps.push(`git push ${remote.remote} --delete ${branch}`);
68
+ }
69
+ return steps;
70
+ };
71
+ /**
72
+ * Renames a non-conforming branch and moves the merge requests aimed at it. Everything that can be
73
+ * checked is checked before the first mutation, and the order of the mutations is chosen so a
74
+ * failure leaves the old branch and every merge request intact.
75
+ */
76
+ const gitFlowRepair = (request) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
77
+ var _a;
78
+ const { root, config, dryRun } = request;
79
+ const branch = (_a = request.ref) !== null && _a !== void 0 ? _a : (0, git_1.currentBranch)(root);
80
+ const newName = resolveNewName({ branch, to: request.to, key: request.key, config });
81
+ const parsed = (0, git_flow_1.parseBranch)({ branch: newName, config: config.gitFlow });
82
+ if (!parsed.ok) {
83
+ console.error(`${newName} does not conform either:`);
84
+ parsed.findings.forEach((finding) => console.error(` ${finding.rule} ${finding.message}`));
85
+ return 1;
86
+ }
87
+ if (!(0, git_1.localBranchExists)({ root, branch })) {
88
+ console.error(`${branch} does not exist locally — check it out first, then repair it.`);
89
+ return 1;
90
+ }
91
+ if ((0, git_1.localBranchExists)({ root, branch: newName })) {
92
+ console.error(`${newName} already exists locally.`);
93
+ return 1;
94
+ }
95
+ const remote = yield readRemoteState({ root, branch, skipMrCheck: request.skipMrCheck });
96
+ if (remote.pushed && (0, git_1.remoteBranchExists)({ root, remote: remote.remote, branch: newName })) {
97
+ console.error(`${newName} already exists on ${remote.remote}.`);
98
+ return 1;
99
+ }
100
+ const steps = describeSteps({ branch, newName, remote });
101
+ console.log('Repair');
102
+ console.log(` from ${branch}`);
103
+ console.log(` to ${newName}`);
104
+ console.log(` remote ${remote.pushed ? `${remote.remote} (pushed)` : 'not pushed'}`);
105
+ if (remote.pushed && !remote.api)
106
+ console.log(' warn merge requests were not checked (--no-mr-check)');
107
+ if (remote.pushed) {
108
+ remote.retarget.forEach((mr) => console.log(` retarget !${mr.iid} ${mr.title}`));
109
+ }
110
+ console.log('\nSteps');
111
+ steps.forEach((step, index) => console.log(` ${index + 1}. ${step}`));
112
+ if (dryRun) {
113
+ console.log('\nDry run — nothing was changed.');
114
+ return 0;
115
+ }
116
+ if (!(yield (0, prompt_1.confirm)({ question: `\nRename ${branch} to ${newName}?`, assumeYes: request.assumeYes }))) {
117
+ console.log('Nothing was changed.');
118
+ return 1;
119
+ }
120
+ (0, git_1.git)({ root, args: ['branch', '-m', branch, newName] });
121
+ if (!remote.pushed) {
122
+ console.log(`\nRenamed to ${newName}.`);
123
+ return 0;
124
+ }
125
+ (0, git_1.gitLoud)({ root, args: ['push', '-u', remote.remote, newName] });
126
+ const { api } = remote;
127
+ for (const mergeRequest of remote.retarget) {
128
+ if (!api)
129
+ break;
130
+ try {
131
+ yield (0, gitlab_1.retargetMergeRequest)({ project: api.project, token: api.token, iid: mergeRequest.iid, target: newName });
132
+ console.log(`Retargeted !${mergeRequest.iid} to ${newName}.`);
133
+ }
134
+ catch (error) {
135
+ console.error(`\nFailed to retarget !${mergeRequest.iid}: ${error instanceof Error ? error.message : error}`);
136
+ console.error([
137
+ `${branch} still exists on ${remote.remote}, so nothing is broken — but the rename is half done.`,
138
+ `Retarget the remaining merge request(s) to ${newName} by hand, then run:`,
139
+ ` git push ${remote.remote} --delete ${branch}`,
140
+ `Or undo: git branch -m ${newName} ${branch} && git push ${remote.remote} --delete ${newName}`,
141
+ ].join('\n'));
142
+ return 1;
143
+ }
144
+ }
145
+ (0, git_1.gitLoud)({ root, args: ['push', remote.remote, '--delete', branch] });
146
+ console.log(`\nRenamed to ${newName} on ${remote.remote}.`);
147
+ return 0;
148
+ });
149
+ exports.gitFlowRepair = gitFlowRepair;
150
+ //# sourceMappingURL=git-flow-repair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-flow-repair.js","sourceRoot":"","sources":["../../../../../libs/agent-rules/src/lib/git-flow-repair.ts"],"names":[],"mappings":";;;;AACA,+BAAqH;AACrH,yCAAyC;AACzC,qCAQkB;AAClB,qCAAmC;AAanC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEhC,MAAM,cAAc,GAAG,CAAC,OAA0E,EAAE,EAAE;IACpG,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE5C,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IAElB,MAAM,KAAK,GAAG,IAAA,sBAAW,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IAE9D,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,KAAK,CAAC,EAAE;YACN,CAAC,CAAC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root: string;
4
+ config: SyncConfig;
5
+ key?: string;
6
+ subject?: string;
7
+ type?: string;
8
+ parent?: string;
9
+ hotfix: boolean;
10
+ releaseDate?: string;
11
+ push: boolean;
12
+ assumeYes: boolean;
13
+ dryRun: boolean;
14
+ };
15
+ /**
16
+ * The prospective flow: an issue key in, a correctly named branch off the correct base out. Shares
17
+ * `planStart` with `@ethlete/timetrack`'s ticket → branch flow, so the two cannot name a branch
18
+ * differently.
19
+ */
20
+ export declare const gitFlowStart: (request: StartRequest) => Promise<1 | 0>;