@webpieces/pr-gate 0.4.828 → 0.4.830
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/package.json +4 -3
- package/src/dashboard/dashboard.js +8 -5
- package/src/dashboard/dashboard.js.map +1 -1
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -7
- package/src/scripts/commands/finish-upsert-pr-command.js +11 -29
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/review-upsert-pr-command.d.ts +4 -5
- package/src/scripts/commands/review-upsert-pr-command.js +7 -13
- package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/start-upsert-pr-command.d.ts +4 -6
- package/src/scripts/commands/start-upsert-pr-command.js +12 -24
- package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +73 -0
- package/src/scripts/commands/upsert-hotfix-pr-command.js +277 -0
- package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -0
- package/src/scripts/pr-gate-app.d.ts +8 -1
- package/src/scripts/pr-gate-app.js +13 -1
- package/src/scripts/pr-gate-app.js.map +1 -1
- package/src/scripts/workflow/hotfix-pr-publisher.d.ts +21 -0
- package/src/scripts/workflow/hotfix-pr-publisher.js +46 -0
- package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -0
- package/src/scripts/workflow/hotfix-redirect.d.ts +20 -0
- package/src/scripts/workflow/hotfix-redirect.js +53 -0
- package/src/scripts/workflow/hotfix-redirect.js.map +1 -0
- package/src/scripts/workflow/push-dev-state.js +1 -0
- package/src/scripts/workflow/push-dev-state.js.map +1 -1
- package/src/scripts/wp-upsert-hotfix-pr.d.ts +2 -0
- package/src/scripts/wp-upsert-hotfix-pr.js +17 -0
- package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -0
- package/src/scripts/workflow/hotfix-finish-preparer.d.ts +0 -38
- package/src/scripts/workflow/hotfix-finish-preparer.js +0 -114
- package/src/scripts/workflow/hotfix-finish-preparer.js.map +0 -1
- package/src/scripts/workflow/hotfix-instructions.d.ts +0 -5
- package/src/scripts/workflow/hotfix-instructions.js +0 -46
- package/src/scripts/workflow/hotfix-instructions.js.map +0 -1
|
@@ -10,7 +10,7 @@ const diff_basis_1 = require("../workflow/diff-basis");
|
|
|
10
10
|
const git_exec_1 = require("../workflow/git-exec");
|
|
11
11
|
const pr_context_writer_1 = require("../workflow/pr-context-writer");
|
|
12
12
|
const run_update_1 = require("../workflow/run-update");
|
|
13
|
-
const
|
|
13
|
+
const hotfix_redirect_1 = require("../workflow/hotfix-redirect");
|
|
14
14
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
15
15
|
// STAGE ① of the AI-first PR flow: the deterministic setup — update from main / drive the 3-point merge —
|
|
16
16
|
// then hand the AI ONE next command, `wp-review-upsert-pr`.
|
|
@@ -31,9 +31,8 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
|
|
|
31
31
|
runUpdate;
|
|
32
32
|
diffBasisResolver;
|
|
33
33
|
prContextWriter;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
constructor(repoRootFinder, aiBranchName, branchNaming, gitExec, runUpdate, diffBasisResolver, prContextWriter, branchIdentity, hotfixInstructions) {
|
|
34
|
+
hotfixRedirect;
|
|
35
|
+
constructor(repoRootFinder, aiBranchName, branchNaming, gitExec, runUpdate, diffBasisResolver, prContextWriter, hotfixRedirect) {
|
|
37
36
|
this.repoRootFinder = repoRootFinder;
|
|
38
37
|
this.aiBranchName = aiBranchName;
|
|
39
38
|
this.branchNaming = branchNaming;
|
|
@@ -41,10 +40,11 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
|
|
|
41
40
|
this.runUpdate = runUpdate;
|
|
42
41
|
this.diffBasisResolver = diffBasisResolver;
|
|
43
42
|
this.prContextWriter = prContextWriter;
|
|
44
|
-
this.
|
|
45
|
-
this.hotfixInstructions = hotfixInstructions;
|
|
43
|
+
this.hotfixRedirect = hotfixRedirect;
|
|
46
44
|
}
|
|
47
45
|
async run() {
|
|
46
|
+
// FIRST, before anything is written or merged: a /hotfix/ branch must never take main (issue #1057).
|
|
47
|
+
this.hotfixRedirect.assertNotHotfix('wp-start-upsert-pr');
|
|
48
48
|
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
49
49
|
// Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.
|
|
50
50
|
(0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
|
|
@@ -59,19 +59,10 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
|
|
|
59
59
|
// Nothing here pushes. This command reviews; wp-finish-upsert-pr pushes ONCE, after summary.json,
|
|
60
60
|
// every BLOCK checklist, and the authoritative build gate — so no unreviewed commit reaches the
|
|
61
61
|
// remote, and there is no early `synchronize` firing against a PR body with a stale gate token.
|
|
62
|
-
|
|
63
|
-
await this.updateBranchFromMain(repoRoot, hotfix);
|
|
62
|
+
await this.updateBranchFromMain(repoRoot);
|
|
64
63
|
// No build gate here — a conflicted merge may still be unresolved, so there is nothing worth
|
|
65
64
|
// building. Stage ② finalizes the merge FIRST, then builds; see the class comment.
|
|
66
|
-
|
|
67
|
-
this.handOffHotfixToFinish(repoRoot);
|
|
68
|
-
else
|
|
69
|
-
this.handOffToReview(repoRoot);
|
|
70
|
-
}
|
|
71
|
-
handOffHotfixToFinish(repoRoot) {
|
|
72
|
-
const featureName = this.aiBranchName.getFeatureName();
|
|
73
|
-
const context = this.prContextWriter.ensure(repoRoot, featureName, this.diffBasisResolver.resolve(repoRoot), 'stage1-start');
|
|
74
|
-
process.stdout.write(this.hotfixInstructions.afterStart((0, rules_config_1.summaryJsonPath)(repoRoot, featureName), this.contextLines(context)));
|
|
65
|
+
this.handOffToReview(repoRoot);
|
|
75
66
|
}
|
|
76
67
|
/**
|
|
77
68
|
* Hand the AI its ONE next step: `wp-review-upsert-pr`.
|
|
@@ -108,14 +99,12 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
|
|
|
108
99
|
// Bring the branch up to date with main via the shared 3-point engine (in-process). On conflict the
|
|
109
100
|
// merge process doc it writes names `wp-review-upsert-pr` as the finish command — that is the command
|
|
110
101
|
// that now validates and commits a conflict resolution, so it is what the doc must send the AI to.
|
|
111
|
-
async updateBranchFromMain(repoRoot
|
|
102
|
+
async updateBranchFromMain(repoRoot) {
|
|
112
103
|
process.stdout.write('\n' + SEP + '① Updating branch from main\n' + SEP + '\n');
|
|
113
104
|
// pushRemote=false — finish owns the single push (see MergeEndOptions).
|
|
114
|
-
const
|
|
115
|
-
const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', next, false);
|
|
105
|
+
const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', 'wp-review-upsert-pr', false);
|
|
116
106
|
if (outcome === 'conflict' || outcome === 'unvalidatedResume') {
|
|
117
|
-
|
|
118
|
-
throw new rules_config_1.CliExitError(2, `\n⏸️ Conflicts — resolve them, then run ${command} ` + (hotfix ? '(it validates the merge, requires the summary, then runs compilation and tests).' : '(it validates the merge, builds it, and only then briefs the reviewers).'));
|
|
107
|
+
throw new rules_config_1.CliExitError(2, '\n⏸️ Conflicts — resolve them, then run pnpm wp-review-upsert-pr (it validates the merge, builds it, and only then briefs the reviewers).');
|
|
119
108
|
}
|
|
120
109
|
}
|
|
121
110
|
};
|
|
@@ -129,7 +118,6 @@ exports.StartUpsertPrCommand = StartUpsertPrCommand = tslib_1.__decorate([
|
|
|
129
118
|
run_update_1.RunUpdate,
|
|
130
119
|
diff_basis_1.DiffBasisResolver,
|
|
131
120
|
pr_context_writer_1.PrContextWriter,
|
|
132
|
-
|
|
133
|
-
hotfix_instructions_1.HotfixInstructions])
|
|
121
|
+
hotfix_redirect_1.HotfixRedirect])
|
|
134
122
|
], StartUpsertPrCommand);
|
|
135
123
|
//# sourceMappingURL=start-upsert-pr-command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/start-upsert-pr-command.ts"],"names":[],"mappings":";;;;AACA,0DAA+I;AAC/I,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,uDAA2D;AAC3D,mDAA+C;AAC/C,qEAAgE;AAChE,uDAAmD;AACnD,yEAAqE;AAErE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,0GAA0G;AAC1G,4DAA4D;AAC5D,EAAE;AACF,4GAA4G;AAC5G,2GAA2G;AAC3G,0GAA0G;AAC1G,0GAA0G;AAC1G,2GAA2G;AAC3G,EAAE;AACF,sGAAsG;AACtG,iEAAiE;AAE1D,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAER;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IATrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,OAAgB,EAChB,SAAoB,EACpB,iBAAoC,EACpC,eAAgC,EAChC,cAA8B,EAC9B,kBAAsC;QARtC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAS;QAChB,cAAS,GAAT,SAAS,CAAW;QACpB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,oBAAe,GAAf,eAAe,CAAiB;QAChC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,uBAAkB,GAAlB,kBAAkB,CAAoB;IACxD,CAAC;IAEJ,KAAK,CAAC,GAAG;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,gGAAgG;QAChG,IAAA,4BAAa,EA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AAC;QACpG,IAAI,OAAO,KAAK,UAAU,IAAI,OAAO,KAAK,mBAAmB,EAAE,CAAC;YAC5D,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,0BAA0B,CAAC;YACjF,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,4CAA4C,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,kFAAkF,CAAC,CAAC,CAAC,0EAA0E,CAAC,CAAC,CAAC;QACnQ,CAAC;IACL,CAAC;CACJ,CAAA;AA7FY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACZ,4BAAY;QACjB,kBAAO;QACL,sBAAS;QACD,8BAAiB;QACnB,mCAAe;QAChB,6BAAc;QACV,wCAAkB;GAVlD,oBAAoB,CA6FhC","sourcesContent":["import { execSync } from 'child_process';\nimport { writeTemplate, CliExitError, RepoRootFinder, ChecklistReviewContext, BranchIdentity, summaryJsonPath } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { DiffBasisResolver } from '../workflow/diff-basis';\nimport { GitExec } from '../workflow/git-exec';\nimport { PrContextWriter } from '../workflow/pr-context-writer';\nimport { RunUpdate } from '../workflow/run-update';\nimport { HotfixInstructions } from '../workflow/hotfix-instructions';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// STAGE ① of the AI-first PR flow: the deterministic setup — update from main / drive the 3-point merge —\n// then hand the AI ONE next command, `wp-review-upsert-pr`.\n//\n// It runs NO build gate, and that is still deliberate, but the reason has changed. It is not that the build\n// belongs only at the end: it is that at THIS point a conflicted 3-point merge may still be unresolved, so\n// there is nothing worth building yet. The gate moved FORWARD, not away — stage ② finalizes the merge and\n// then builds, so reviewers never judge a branch that does not compile, and wp-finish-upsert-pr skips the\n// rebuild when HEAD has not moved since. `pr-gate.buildCommand` is therefore no longer a finish-only knob.\n//\n// This command NEVER creates/updates a PR and NEVER pushes: all `gh` posting and the ONE push live in\n// finish, behind summary.json + the checklists + the build gate.\n@injectable(bindingScopeValues.Singleton)\nexport class StartUpsertPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly gitExec: GitExec,\n private readonly runUpdate: RunUpdate,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n private readonly branchIdentity: BranchIdentity,\n private readonly hotfixInstructions: HotfixInstructions,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n // NOTE: the server-side CI gate is NOT scaffolded here any more — `wp-install-ai-hooks` owns it.\n // This printed copy-to-.github + branch-protection instructions on EVERY run, at an agent doing\n // feature work that could not act on them: marking a check required needs a repo admin. Setup\n // belongs in the setup command; see templates/webpieces.ci-gate-setup.md.\n\n // Precondition: a fully-committed tree. This flow squash-updates the branch and builds it — the\n // tooling must not commit your work for you, and building a dirty working tree would let an\n // uncommitted change build green over a different commit than the one that ships. Fail if dirty.\n this.gitExec.assertCleanTree(repoRoot);\n\n // Nothing here pushes. This command reviews; wp-finish-upsert-pr pushes ONCE, after summary.json,\n // every BLOCK checklist, and the authoritative build gate — so no unreviewed commit reaches the\n // remote, and there is no early `synchronize` firing against a PR body with a stale gate token.\n const hotfix = this.branchIdentity.isHotfix();\n await this.updateBranchFromMain(repoRoot, hotfix);\n\n // No build gate here — a conflicted merge may still be unresolved, so there is nothing worth\n // building. Stage ② finalizes the merge FIRST, then builds; see the class comment.\n if (hotfix) this.handOffHotfixToFinish(repoRoot);\n else this.handOffToReview(repoRoot);\n }\n\n private handOffHotfixToFinish(repoRoot: string): void {\n const featureName = this.aiBranchName.getFeatureName();\n const context = this.prContextWriter.ensure(repoRoot, featureName, this.diffBasisResolver.resolve(repoRoot), 'stage1-start');\n process.stdout.write(this.hotfixInstructions.afterStart(summaryJsonPath(repoRoot, featureName), this.contextLines(context)));\n }\n\n /**\n * Hand the AI its ONE next step: `wp-review-upsert-pr`.\n *\n * This prints exactly one command on purpose. It used to print three (run the checklist, write\n * summary.json, then finish), and a three-item list is a list with a step to skip. Stage ② now owns all\n * of it — it validates the 3-point merge, builds, materializes the diff, briefs the reviewers, AND\n * prints the summary.json schema — so there is nothing here to enumerate. Notably summary.json is NOT\n * requested here any more: asking for a written PR summary before the branch is known to compile invites\n * one that describes code that does not build.\n */\n private handOffToReview(repoRoot: string): void {\n // Persist the review-format + process instructions where any failure message can cite them.\n writeTemplate(repoRoot, 'webpieces.review-checklists.md');\n // Persist the PR diff context (base sha + the full changed-file set) so it exists even if the AI\n // stops here. Stage ② rewrites it with the materialized-diff dir once it has one.\n const context = this.prContextWriter.ensure(repoRoot, this.aiBranchName.getFeatureName(), this.diffBasisResolver.resolve(repoRoot), 'stage1-start');\n process.stdout.write('\\n' + SEP + '② Brief the reviewers and write the PR summary, then finish\\n' + SEP + '\\n');\n process.stdout.write(\n `Branch is updated (nothing pushed yet — finish does the one push, behind the build gate).\\n` +\n `${this.contextLines(context)}\\n` +\n `▶ NEXT run: pnpm wp-review-upsert-pr\\n` +\n ` It validates the 3-point merge, runs the build gate, extracts this branch's diff for the\\n` +\n ` reviewers, and prints what to spawn plus the summary.json schema. Everything else waits on it —\\n` +\n ` wp-finish-upsert-pr refuses to open a PR until it has run.\\n\\n`,\n );\n }\n\n // The diff facts, stated where the instruction to use them is — not in a separate block above it. The\n // command comes from the resolved basis; hand-writing `<base> HEAD` here is empty on a dirty tree.\n private contextLines(context: ChecklistReviewContext): string {\n if (context.baseSha.trim() === '') return '';\n const cmd = context.fileDiffCommand.replace(' -- <file>', '');\n return `${cmd === '' ? '' : `Your diff: ${cmd}\\n`}` + `Full changed-file set + base/head sha: ${context.prContextPath}\\n`;\n }\n\n // Bring the branch up to date with main via the shared 3-point engine (in-process). On conflict the\n // merge process doc it writes names `wp-review-upsert-pr` as the finish command — that is the command\n // that now validates and commits a conflict resolution, so it is what the doc must send the AI to.\n private async updateBranchFromMain(repoRoot: string, hotfix: boolean): Promise<void> {\n process.stdout.write('\\n' + SEP + '① Updating branch from main\\n' + SEP + '\\n');\n // pushRemote=false — finish owns the single push (see MergeEndOptions).\n const next = hotfix ? 'wp-finish-upsert-pr' : 'wp-review-upsert-pr';\n const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', next, false);\n if (outcome === 'conflict' || outcome === 'unvalidatedResume') {\n const command = hotfix ? 'pnpm wp-finish-upsert-pr' : 'pnpm wp-review-upsert-pr';\n throw new CliExitError(2, `\\n⏸️ Conflicts — resolve them, then run ${command} ` + (hotfix ? '(it validates the merge, requires the summary, then runs compilation and tests).' : '(it validates the merge, builds it, and only then briefs the reviewers).'));\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"start-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/start-upsert-pr-command.ts"],"names":[],"mappings":";;;;AACA,0DAA8G;AAC9G,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,uDAA2D;AAC3D,mDAA+C;AAC/C,qEAAgE;AAChE,uDAAmD;AACnD,iEAA6D;AAE7D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,0GAA0G;AAC1G,4DAA4D;AAC5D,EAAE;AACF,4GAA4G;AAC5G,2GAA2G;AAC3G,0GAA0G;AAC1G,0GAA0G;AAC1G,2GAA2G;AAC3G,EAAE;AACF,sGAAsG;AACtG,iEAAiE;AAE1D,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAER;IAC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AO,KAAK,mBAAmB,EAAE,CAAC;YAC5D,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,4IAA4I,CAAC,CAAC;QAC5K,CAAC;IACL,CAAC;CACJ,CAAA;AApFY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACZ,4BAAY;QACjB,kBAAO;QACL,sBAAS;QACD,8BAAiB;QACnB,mCAAe;QAChB,gCAAc;GAT1C,oBAAoB,CAoFhC","sourcesContent":["import { execSync } from 'child_process';\nimport { writeTemplate, CliExitError, RepoRootFinder, ChecklistReviewContext } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { DiffBasisResolver } from '../workflow/diff-basis';\nimport { GitExec } from '../workflow/git-exec';\nimport { PrContextWriter } from '../workflow/pr-context-writer';\nimport { RunUpdate } from '../workflow/run-update';\nimport { HotfixRedirect } from '../workflow/hotfix-redirect';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// STAGE ① of the AI-first PR flow: the deterministic setup — update from main / drive the 3-point merge —\n// then hand the AI ONE next command, `wp-review-upsert-pr`.\n//\n// It runs NO build gate, and that is still deliberate, but the reason has changed. It is not that the build\n// belongs only at the end: it is that at THIS point a conflicted 3-point merge may still be unresolved, so\n// there is nothing worth building yet. The gate moved FORWARD, not away — stage ② finalizes the merge and\n// then builds, so reviewers never judge a branch that does not compile, and wp-finish-upsert-pr skips the\n// rebuild when HEAD has not moved since. `pr-gate.buildCommand` is therefore no longer a finish-only knob.\n//\n// This command NEVER creates/updates a PR and NEVER pushes: all `gh` posting and the ONE push live in\n// finish, behind summary.json + the checklists + the build gate.\n@injectable(bindingScopeValues.Singleton)\nexport class StartUpsertPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly gitExec: GitExec,\n private readonly runUpdate: RunUpdate,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n private readonly hotfixRedirect: HotfixRedirect,\n ) {}\n\n async run(): Promise<void> {\n // FIRST, before anything is written or merged: a /hotfix/ branch must never take main (issue #1057).\n this.hotfixRedirect.assertNotHotfix('wp-start-upsert-pr');\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n // NOTE: the server-side CI gate is NOT scaffolded here any more — `wp-install-ai-hooks` owns it.\n // This printed copy-to-.github + branch-protection instructions on EVERY run, at an agent doing\n // feature work that could not act on them: marking a check required needs a repo admin. Setup\n // belongs in the setup command; see templates/webpieces.ci-gate-setup.md.\n\n // Precondition: a fully-committed tree. This flow squash-updates the branch and builds it — the\n // tooling must not commit your work for you, and building a dirty working tree would let an\n // uncommitted change build green over a different commit than the one that ships. Fail if dirty.\n this.gitExec.assertCleanTree(repoRoot);\n\n // Nothing here pushes. This command reviews; wp-finish-upsert-pr pushes ONCE, after summary.json,\n // every BLOCK checklist, and the authoritative build gate — so no unreviewed commit reaches the\n // remote, and there is no early `synchronize` firing against a PR body with a stale gate token.\n await this.updateBranchFromMain(repoRoot);\n\n // No build gate here — a conflicted merge may still be unresolved, so there is nothing worth\n // building. Stage ② finalizes the merge FIRST, then builds; see the class comment.\n this.handOffToReview(repoRoot);\n }\n\n /**\n * Hand the AI its ONE next step: `wp-review-upsert-pr`.\n *\n * This prints exactly one command on purpose. It used to print three (run the checklist, write\n * summary.json, then finish), and a three-item list is a list with a step to skip. Stage ② now owns all\n * of it — it validates the 3-point merge, builds, materializes the diff, briefs the reviewers, AND\n * prints the summary.json schema — so there is nothing here to enumerate. Notably summary.json is NOT\n * requested here any more: asking for a written PR summary before the branch is known to compile invites\n * one that describes code that does not build.\n */\n private handOffToReview(repoRoot: string): void {\n // Persist the review-format + process instructions where any failure message can cite them.\n writeTemplate(repoRoot, 'webpieces.review-checklists.md');\n // Persist the PR diff context (base sha + the full changed-file set) so it exists even if the AI\n // stops here. Stage ② rewrites it with the materialized-diff dir once it has one.\n const context = this.prContextWriter.ensure(repoRoot, this.aiBranchName.getFeatureName(), this.diffBasisResolver.resolve(repoRoot), 'stage1-start');\n process.stdout.write('\\n' + SEP + '② Brief the reviewers and write the PR summary, then finish\\n' + SEP + '\\n');\n process.stdout.write(\n `Branch is updated (nothing pushed yet — finish does the one push, behind the build gate).\\n` +\n `${this.contextLines(context)}\\n` +\n `▶ NEXT run: pnpm wp-review-upsert-pr\\n` +\n ` It validates the 3-point merge, runs the build gate, extracts this branch's diff for the\\n` +\n ` reviewers, and prints what to spawn plus the summary.json schema. Everything else waits on it —\\n` +\n ` wp-finish-upsert-pr refuses to open a PR until it has run.\\n\\n`,\n );\n }\n\n // The diff facts, stated where the instruction to use them is — not in a separate block above it. The\n // command comes from the resolved basis; hand-writing `<base> HEAD` here is empty on a dirty tree.\n private contextLines(context: ChecklistReviewContext): string {\n if (context.baseSha.trim() === '') return '';\n const cmd = context.fileDiffCommand.replace(' -- <file>', '');\n return `${cmd === '' ? '' : `Your diff: ${cmd}\\n`}` + `Full changed-file set + base/head sha: ${context.prContextPath}\\n`;\n }\n\n // Bring the branch up to date with main via the shared 3-point engine (in-process). On conflict the\n // merge process doc it writes names `wp-review-upsert-pr` as the finish command — that is the command\n // that now validates and commits a conflict resolution, so it is what the doc must send the AI to.\n private async updateBranchFromMain(repoRoot: string): Promise<void> {\n process.stdout.write('\\n' + SEP + '① Updating branch from main\\n' + SEP + '\\n');\n // pushRemote=false — finish owns the single push (see MergeEndOptions).\n const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', 'wp-review-upsert-pr', false);\n if (outcome === 'conflict' || outcome === 'unvalidatedResume') {\n throw new CliExitError(2, '\\n⏸️ Conflicts — resolve them, then run pnpm wp-review-upsert-pr (it validates the merge, builds it, and only then briefs the reviewers).');\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BranchIdentity, GateTokenService, PrGateConfig, RepoRootFinder, ReviewJsonService } from '@webpieces/rules-config';
|
|
2
|
+
import { AiBranchName } from '../workflow/git-readAiBranchName';
|
|
3
|
+
import { GitExec } from '../workflow/git-exec';
|
|
4
|
+
import { BuildAffected } from '../workflow/build-affected';
|
|
5
|
+
import { BuildArtifactGate } from '../workflow/build-artifact-gate';
|
|
6
|
+
import { MergeState } from '../workflow/merge-state';
|
|
7
|
+
import { ChecklistScanner } from '../workflow/checklist-scanner';
|
|
8
|
+
import { HotfixPrPublisher } from '../workflow/hotfix-pr-publisher';
|
|
9
|
+
import { PrCommentUpserter } from '../workflow/pr-comment-upserter';
|
|
10
|
+
import { SquashSettingsEnforcer } from '../workflow/squash-settings-enforcer';
|
|
11
|
+
import { Dashboard } from '../../dashboard/dashboard';
|
|
12
|
+
import { ChecklistCommentRenderer } from '../../dashboard/checklist-comment-renderer';
|
|
13
|
+
import { AuthorIdentityResolver } from '../../dashboard/author-identity';
|
|
14
|
+
/** The PR this run landed on. Both '' when it could not be resolved. Data-only, per CLAUDE.md. */
|
|
15
|
+
export declare class HotfixPrRef {
|
|
16
|
+
number: string;
|
|
17
|
+
url: string;
|
|
18
|
+
constructor(number: string, url: string);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `wp-upsert-hotfix-pr` — the ONE command that publishes a `/hotfix/` branch (issue #1057).
|
|
22
|
+
*
|
|
23
|
+
* A hotfix branch is cut from the exact sha running in production, so that what ships is production plus
|
|
24
|
+
* the fix and nothing else. The three-stage PR flow cannot publish it: stage ① merges main into the branch,
|
|
25
|
+
* which turns "prod + fix" into "main + fix" and ships every commit that has landed but has not been
|
|
26
|
+
* promoted. And a hotfix runs no reviewers, so the stages have nothing to do between them. This is the
|
|
27
|
+
* whole flow, in one command, in this order:
|
|
28
|
+
*
|
|
29
|
+
* 1. refuse unless the branch carries the exact, case-sensitive `/hotfix/` segment;
|
|
30
|
+
* 2. require a clean tree and summary.json — a missing one prints its path and schema and exits;
|
|
31
|
+
* 3. run ONLY the `hotfix-ci` gate (build + test). Red means nothing is pushed;
|
|
32
|
+
* 4. NEVER merge main into the branch, never squash it, never rewrite it — HEAD is checked unchanged;
|
|
33
|
+
* 5. push ONCE, fast-forward only, as a child process (pr-creation-or-push-guard stays intact);
|
|
34
|
+
* 6. create or update the audit-bannered PR to main, and NEVER enable auto-merge — the consumer merges
|
|
35
|
+
* after it has deployed and verified the hotfix. Re-running after another commit pushes again and
|
|
36
|
+
* updates the same PR.
|
|
37
|
+
*/
|
|
38
|
+
export declare class UpsertHotfixPrCommand {
|
|
39
|
+
private readonly repoRootFinder;
|
|
40
|
+
private readonly branchIdentity;
|
|
41
|
+
private readonly aiBranchName;
|
|
42
|
+
private readonly gitExec;
|
|
43
|
+
private readonly reviewJsonService;
|
|
44
|
+
private readonly buildAffected;
|
|
45
|
+
private readonly buildArtifactGate;
|
|
46
|
+
private readonly mergeState;
|
|
47
|
+
private readonly checklistScanner;
|
|
48
|
+
private readonly publisher;
|
|
49
|
+
private readonly dashboard;
|
|
50
|
+
private readonly authorIdentity;
|
|
51
|
+
private readonly checklistComment;
|
|
52
|
+
private readonly commentUpserter;
|
|
53
|
+
private readonly squashSettings;
|
|
54
|
+
private readonly gateTokenService;
|
|
55
|
+
constructor(repoRootFinder: RepoRootFinder, branchIdentity: BranchIdentity, aiBranchName: AiBranchName, gitExec: GitExec, reviewJsonService: ReviewJsonService, buildAffected: BuildAffected, buildArtifactGate: BuildArtifactGate, mergeState: MergeState, checklistScanner: ChecklistScanner, publisher: HotfixPrPublisher, dashboard: Dashboard, authorIdentity: AuthorIdentityResolver, checklistComment: ChecklistCommentRenderer, commentUpserter: PrCommentUpserter, squashSettings: SquashSettingsEnforcer, gateTokenService: GateTokenService);
|
|
56
|
+
run(): Promise<void>;
|
|
57
|
+
private assertHotfixBranch;
|
|
58
|
+
private assertNoUnvalidatedMerge;
|
|
59
|
+
/** Body before push (GatedPrPublisher's ordering), fast-forward push, then create or edit — never merge. */
|
|
60
|
+
private publish;
|
|
61
|
+
private dashboardInput;
|
|
62
|
+
/** The 1st comment (full dashboard) and, when the repo defines checklists, the bypassed-roster 2nd. */
|
|
63
|
+
private postComments;
|
|
64
|
+
private closingBlock;
|
|
65
|
+
private tokenSuffix;
|
|
66
|
+
private titleFrom;
|
|
67
|
+
private headSha;
|
|
68
|
+
private git;
|
|
69
|
+
protected prGateConfig(repoRoot: string): PrGateConfig;
|
|
70
|
+
protected fetchMain(repoRoot: string): void;
|
|
71
|
+
protected prRef(branch: string): HotfixPrRef;
|
|
72
|
+
protected editPrBody(prNumber: string, bodyFile: string): boolean;
|
|
73
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpsertHotfixPrCommand = exports.HotfixPrRef = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
+
const path = tslib_1.__importStar(require("path"));
|
|
8
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
9
|
+
const inversify_1 = require("inversify");
|
|
10
|
+
const git_readAiBranchName_1 = require("../workflow/git-readAiBranchName");
|
|
11
|
+
const git_exec_1 = require("../workflow/git-exec");
|
|
12
|
+
const build_affected_1 = require("../workflow/build-affected");
|
|
13
|
+
const build_artifact_gate_1 = require("../workflow/build-artifact-gate");
|
|
14
|
+
const build_gate_log_1 = require("../workflow/build-gate-log");
|
|
15
|
+
const merge_state_1 = require("../workflow/merge-state");
|
|
16
|
+
const checklist_scanner_1 = require("../workflow/checklist-scanner");
|
|
17
|
+
const hotfix_pr_publisher_1 = require("../workflow/hotfix-pr-publisher");
|
|
18
|
+
const hotfix_redirect_1 = require("../workflow/hotfix-redirect");
|
|
19
|
+
const pr_comment_upserter_1 = require("../workflow/pr-comment-upserter");
|
|
20
|
+
const squash_settings_enforcer_1 = require("../workflow/squash-settings-enforcer");
|
|
21
|
+
const dashboard_1 = require("../../dashboard/dashboard");
|
|
22
|
+
const checklist_comment_renderer_1 = require("../../dashboard/checklist-comment-renderer");
|
|
23
|
+
const checklist_comment_row_1 = require("../../dashboard/checklist-comment-row");
|
|
24
|
+
const author_identity_1 = require("../../dashboard/author-identity");
|
|
25
|
+
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
26
|
+
/** The PR this run landed on. Both '' when it could not be resolved. Data-only, per CLAUDE.md. */
|
|
27
|
+
class HotfixPrRef {
|
|
28
|
+
number;
|
|
29
|
+
url;
|
|
30
|
+
constructor(number, url) {
|
|
31
|
+
this.number = number;
|
|
32
|
+
this.url = url;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.HotfixPrRef = HotfixPrRef;
|
|
36
|
+
/**
|
|
37
|
+
* `wp-upsert-hotfix-pr` — the ONE command that publishes a `/hotfix/` branch (issue #1057).
|
|
38
|
+
*
|
|
39
|
+
* A hotfix branch is cut from the exact sha running in production, so that what ships is production plus
|
|
40
|
+
* the fix and nothing else. The three-stage PR flow cannot publish it: stage ① merges main into the branch,
|
|
41
|
+
* which turns "prod + fix" into "main + fix" and ships every commit that has landed but has not been
|
|
42
|
+
* promoted. And a hotfix runs no reviewers, so the stages have nothing to do between them. This is the
|
|
43
|
+
* whole flow, in one command, in this order:
|
|
44
|
+
*
|
|
45
|
+
* 1. refuse unless the branch carries the exact, case-sensitive `/hotfix/` segment;
|
|
46
|
+
* 2. require a clean tree and summary.json — a missing one prints its path and schema and exits;
|
|
47
|
+
* 3. run ONLY the `hotfix-ci` gate (build + test). Red means nothing is pushed;
|
|
48
|
+
* 4. NEVER merge main into the branch, never squash it, never rewrite it — HEAD is checked unchanged;
|
|
49
|
+
* 5. push ONCE, fast-forward only, as a child process (pr-creation-or-push-guard stays intact);
|
|
50
|
+
* 6. create or update the audit-bannered PR to main, and NEVER enable auto-merge — the consumer merges
|
|
51
|
+
* after it has deployed and verified the hotfix. Re-running after another commit pushes again and
|
|
52
|
+
* updates the same PR.
|
|
53
|
+
*/
|
|
54
|
+
let UpsertHotfixPrCommand = class UpsertHotfixPrCommand {
|
|
55
|
+
repoRootFinder;
|
|
56
|
+
branchIdentity;
|
|
57
|
+
aiBranchName;
|
|
58
|
+
gitExec;
|
|
59
|
+
reviewJsonService;
|
|
60
|
+
buildAffected;
|
|
61
|
+
buildArtifactGate;
|
|
62
|
+
mergeState;
|
|
63
|
+
checklistScanner;
|
|
64
|
+
publisher;
|
|
65
|
+
dashboard;
|
|
66
|
+
authorIdentity;
|
|
67
|
+
checklistComment;
|
|
68
|
+
commentUpserter;
|
|
69
|
+
squashSettings;
|
|
70
|
+
gateTokenService;
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
72
|
+
constructor(repoRootFinder, branchIdentity, aiBranchName, gitExec, reviewJsonService, buildAffected, buildArtifactGate, mergeState, checklistScanner, publisher, dashboard, authorIdentity, checklistComment, commentUpserter, squashSettings, gateTokenService) {
|
|
73
|
+
this.repoRootFinder = repoRootFinder;
|
|
74
|
+
this.branchIdentity = branchIdentity;
|
|
75
|
+
this.aiBranchName = aiBranchName;
|
|
76
|
+
this.gitExec = gitExec;
|
|
77
|
+
this.reviewJsonService = reviewJsonService;
|
|
78
|
+
this.buildAffected = buildAffected;
|
|
79
|
+
this.buildArtifactGate = buildArtifactGate;
|
|
80
|
+
this.mergeState = mergeState;
|
|
81
|
+
this.checklistScanner = checklistScanner;
|
|
82
|
+
this.publisher = publisher;
|
|
83
|
+
this.dashboard = dashboard;
|
|
84
|
+
this.authorIdentity = authorIdentity;
|
|
85
|
+
this.checklistComment = checklistComment;
|
|
86
|
+
this.commentUpserter = commentUpserter;
|
|
87
|
+
this.squashSettings = squashSettings;
|
|
88
|
+
this.gateTokenService = gateTokenService;
|
|
89
|
+
}
|
|
90
|
+
async run() {
|
|
91
|
+
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
92
|
+
const branch = this.branchIdentity.current();
|
|
93
|
+
// FIRST, before any write: a non-hotfix branch gets nothing from this command, not even a template.
|
|
94
|
+
this.assertHotfixBranch(branch);
|
|
95
|
+
(0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
|
|
96
|
+
this.gitExec.assertCleanTree(repoRoot);
|
|
97
|
+
this.assertNoUnvalidatedMerge(repoRoot);
|
|
98
|
+
const featureName = this.aiBranchName.getFeatureName();
|
|
99
|
+
const summaryPath = this.reviewJsonService.summaryJsonPath(repoRoot, featureName);
|
|
100
|
+
// Throws InformAiError carrying the path and the schema when summary.json is missing or invalid.
|
|
101
|
+
const summary = this.reviewJsonService.loadSummaryJson(summaryPath, [], '', {}, hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND);
|
|
102
|
+
// origin/main is READ (the build's merge-base and the dashboard's fork point) — never merged.
|
|
103
|
+
this.fetchMain(repoRoot);
|
|
104
|
+
const headBefore = this.headSha(repoRoot);
|
|
105
|
+
await this.buildAffected.runBuildGate(repoRoot, new build_affected_1.BuildGateOptions('🛠️ Hotfix build gate (hotfix-ci: build + test only)', hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND, 'Hotfix build failed — nothing was pushed and no PR was created or updated.', build_gate_log_1.FINISH_STAGE));
|
|
106
|
+
this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);
|
|
107
|
+
this.gitExec.assertCleanTree(repoRoot);
|
|
108
|
+
if (this.headSha(repoRoot) !== headBefore) {
|
|
109
|
+
throw new rules_config_1.CliExitError(1, `❌ HEAD moved while the hotfix build ran, so the build does not cover the commit that would be pushed. Nothing was pushed. Re-run ${hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND}.`);
|
|
110
|
+
}
|
|
111
|
+
const ref = this.publish(repoRoot, branch, summary, headBefore);
|
|
112
|
+
this.postComments(repoRoot, featureName, ref, summary);
|
|
113
|
+
this.squashSettings.ensure();
|
|
114
|
+
const archived = this.reviewJsonService.archiveSummaryJson(summaryPath);
|
|
115
|
+
if (archived !== '')
|
|
116
|
+
process.stdout.write(` archived this run's summary.json → ${archived} (audit only) ✓\n`);
|
|
117
|
+
process.stdout.write(this.closingBlock(ref, summary.title, branch));
|
|
118
|
+
}
|
|
119
|
+
assertHotfixBranch(branch) {
|
|
120
|
+
if (this.branchIdentity.isHotfix(branch))
|
|
121
|
+
return;
|
|
122
|
+
throw new rules_config_1.CliExitError(1, `wp-upsert-hotfix-pr only runs on a branch containing the exact, case-sensitive /hotfix/ segment; '${branch}' does not.\n` +
|
|
123
|
+
'Nothing was changed. A normal branch is published with the three-stage flow:\n' +
|
|
124
|
+
' pnpm wp-start-upsert-pr\n pnpm wp-review-upsert-pr\n pnpm wp-finish-upsert-pr');
|
|
125
|
+
}
|
|
126
|
+
// A hotfix flow never STARTS a merge, but a branch somebody ran wp-start-update on can carry one.
|
|
127
|
+
assertNoUnvalidatedMerge(repoRoot) {
|
|
128
|
+
const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());
|
|
129
|
+
const active = this.mergeState.findActiveMergeRunDir(home);
|
|
130
|
+
const marker = active === null ? null : this.mergeState.readMergeMarker(active);
|
|
131
|
+
if (marker === null || marker.validated)
|
|
132
|
+
return;
|
|
133
|
+
throw new rules_config_1.CliExitError(1, 'wp-upsert-hotfix-pr refuses a branch with an active, unvalidated 3-point merge. A hotfix branch must\n' +
|
|
134
|
+
'not take main at all: abort that merge and return the branch to the production sha plus your fix\n' +
|
|
135
|
+
`commits, then re-run ${hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND}. Nothing was pushed.`);
|
|
136
|
+
}
|
|
137
|
+
/** Body before push (GatedPrPublisher's ordering), fast-forward push, then create or edit — never merge. */
|
|
138
|
+
publish(repoRoot, branch, summary, headSha) {
|
|
139
|
+
const config = this.prGateConfig(repoRoot);
|
|
140
|
+
const input = this.dashboardInput(repoRoot, summary, config);
|
|
141
|
+
const tokenSuffix = this.tokenSuffix(config.gateSalt, headSha);
|
|
142
|
+
const initial = this.prRef(branch);
|
|
143
|
+
const body = this.dashboard.renderPrBody(input, initial.url) + tokenSuffix;
|
|
144
|
+
const bodyFile = path.join(this.reviewJsonService.prDirFor(repoRoot, this.aiBranchName.getFeatureName()), 'pr-body.md');
|
|
145
|
+
fs.mkdirSync(path.dirname(bodyFile), { recursive: true });
|
|
146
|
+
fs.writeFileSync(bodyFile, body + '\n');
|
|
147
|
+
process.stdout.write('\n' + SEP + '📋 Hotfix PR (bannered audit, never auto-merged)\n' + SEP + '\n');
|
|
148
|
+
const published = this.publisher.publish(branch, this.titleFrom(summary, branch), bodyFile, hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND);
|
|
149
|
+
if (published.createFailed) {
|
|
150
|
+
throw new rules_config_1.CliExitError(1, `❌ gh pr create failed after the push. The rendered body is in ${bodyFile}; summary.json was kept. Re-run ${hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND}.`);
|
|
151
|
+
}
|
|
152
|
+
const ref = this.prRef(branch);
|
|
153
|
+
const resolved = new HotfixPrRef(ref.number !== '' ? ref.number : published.number, ref.url);
|
|
154
|
+
// A brand-new PR had no URL to self-link until `gh pr create` returned one.
|
|
155
|
+
const finalBody = this.dashboard.renderPrBody(input, resolved.url) + tokenSuffix;
|
|
156
|
+
if (finalBody !== body && resolved.number !== '') {
|
|
157
|
+
fs.writeFileSync(bodyFile, finalBody + '\n');
|
|
158
|
+
if (!this.editPrBody(resolved.number, bodyFile)) {
|
|
159
|
+
process.stderr.write(`⚠️ Could not add the PR's own link to its description (non-fatal — the PR and the gate token are up).\n`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return resolved;
|
|
163
|
+
}
|
|
164
|
+
dashboardInput(repoRoot, summary, config) {
|
|
165
|
+
const forkPoint = this.git(repoRoot, ['merge-base', 'origin/main', 'HEAD']);
|
|
166
|
+
const featureHead = this.git(repoRoot, ['rev-parse', 'HEAD']);
|
|
167
|
+
const mainHead = this.git(repoRoot, ['rev-parse', 'origin/main']);
|
|
168
|
+
const range = `${forkPoint}..${featureHead}`;
|
|
169
|
+
const changedFiles = this.git(repoRoot, ['diff', range, '--name-only'])
|
|
170
|
+
.split('\n')
|
|
171
|
+
.filter((f) => f.trim() !== '');
|
|
172
|
+
const gateResults = this.dashboard.computeGateResults(config.gates, changedFiles);
|
|
173
|
+
const disables = this.dashboard.countAddedDisables(this.git(repoRoot, ['diff', range]));
|
|
174
|
+
const buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);
|
|
175
|
+
const title = this.titleFrom(summary, this.branchIdentity.current());
|
|
176
|
+
return new dashboard_1.DashboardInput(title, gateResults, disables, true, forkPoint, featureHead, mainHead, summary, [], buildCommand, 0, this.authorIdentity.resolve(summary.model), true);
|
|
177
|
+
}
|
|
178
|
+
/** The 1st comment (full dashboard) and, when the repo defines checklists, the bypassed-roster 2nd. */
|
|
179
|
+
postComments(repoRoot, featureName, ref, summary) {
|
|
180
|
+
if (ref.number === '') {
|
|
181
|
+
process.stderr.write(`⚠️ Could not resolve the PR number after the push, so the audit comments were not posted. The PR body\n still carries the hotfix banner. Re-run ${hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND} to post them.\n`);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const config = this.prGateConfig(repoRoot);
|
|
185
|
+
const prDir = this.reviewJsonService.prDirFor(repoRoot, featureName);
|
|
186
|
+
const detail = new pr_comment_upserter_1.PrCommentRequest();
|
|
187
|
+
detail.prNumber = ref.number;
|
|
188
|
+
detail.marker = dashboard_1.DETAIL_COMMENT_MARKER;
|
|
189
|
+
// The audit banner must be the FIRST thing on the comment, so the marker goes last.
|
|
190
|
+
detail.body = this.dashboard.renderDetailComment(this.dashboardInput(repoRoot, summary, config)) + '\n\n' + dashboard_1.DETAIL_COMMENT_MARKER;
|
|
191
|
+
detail.payloadDir = prDir;
|
|
192
|
+
detail.payloadName = 'detail-comment.json';
|
|
193
|
+
detail.label = 'full dashboard comment';
|
|
194
|
+
this.commentUpserter.upsert(detail);
|
|
195
|
+
if (config.checklists.length === 0 || !config.checklistComments)
|
|
196
|
+
return;
|
|
197
|
+
const scan = this.checklistScanner.scan(repoRoot, config.checklists, new checklist_scanner_1.ChecklistScanOptions(config.maxReviewerRounds, false, ''));
|
|
198
|
+
const rows = scan.roster.entries.map((entry) => new checklist_comment_row_1.ChecklistCommentRow('none', 'none', entry.def.id, '', '', entry.matchedFiles.length > 0, entry.def.patterns, entry.matchedPatterns, entry.matchedFiles, scan.roster.changedFileCount));
|
|
199
|
+
const roster = new pr_comment_upserter_1.PrCommentRequest();
|
|
200
|
+
roster.prNumber = ref.number;
|
|
201
|
+
roster.marker = checklist_comment_renderer_1.CHECKLIST_COMMENT_MARKER;
|
|
202
|
+
roster.body = this.checklistComment.render(rows, false, scan.roster.baseResolved, 0, true);
|
|
203
|
+
roster.payloadDir = prDir;
|
|
204
|
+
roster.payloadName = 'checklist-comment.json';
|
|
205
|
+
roster.label = 'checklist review comment';
|
|
206
|
+
this.commentUpserter.upsert(roster);
|
|
207
|
+
}
|
|
208
|
+
closingBlock(ref, title, branch) {
|
|
209
|
+
const link = ref.url === '' ? '(PR URL unresolved — see the gh output above)' : ref.url;
|
|
210
|
+
return ('\n' +
|
|
211
|
+
SEP +
|
|
212
|
+
`✅ Hotfix PR ${ref.number === '' ? '' : `#${ref.number} `}is up — NOT merged, and auto-merge was NOT enabled\n` +
|
|
213
|
+
SEP +
|
|
214
|
+
'\n' +
|
|
215
|
+
' 1. ran hotfix-ci (build + test only); lint, validators and reviewers are bypassed and bannered\n' +
|
|
216
|
+
` 2. pushed ${branch} fast-forward only — main was never merged in and the branch was not rewritten\n` +
|
|
217
|
+
` 3. wrote the audit-bannered body to the PR titled: "${title}"\n\n` +
|
|
218
|
+
' A hotfix PR is never auto-merged. Deploy and verify the hotfix first; the merge to main is then a\n' +
|
|
219
|
+
' deliberate step (pnpm wp-land-pr). Another commit on this branch? Commit it and re-run\n' +
|
|
220
|
+
` ${hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND} — it pushes again and updates this same PR.\n\n` +
|
|
221
|
+
`🔗 ${link}\n`);
|
|
222
|
+
}
|
|
223
|
+
tokenSuffix(gateSalt, headSha) {
|
|
224
|
+
const marker = this.gateTokenService.gateTokenMarker(gateSalt, headSha);
|
|
225
|
+
return marker === '' ? '' : `\n\n${marker}\n`;
|
|
226
|
+
}
|
|
227
|
+
titleFrom(summary, branch) {
|
|
228
|
+
return summary.title !== '' ? summary.title : branch.replace(/[-/]+/g, ' ').trim();
|
|
229
|
+
}
|
|
230
|
+
headSha(repoRoot) {
|
|
231
|
+
return this.git(repoRoot, ['rev-parse', 'HEAD']);
|
|
232
|
+
}
|
|
233
|
+
git(repoRoot, args) {
|
|
234
|
+
return this.gitExec.gitQuery(args, repoRoot, `git ${args.join(' ')} failed in ${repoRoot}`);
|
|
235
|
+
}
|
|
236
|
+
// ── seams, protected so the spec drives them with no network, no gh and no webpieces.config.json ──
|
|
237
|
+
prGateConfig(repoRoot) {
|
|
238
|
+
return (0, rules_config_1.loadAndValidate)(repoRoot).prGate;
|
|
239
|
+
}
|
|
240
|
+
fetchMain(repoRoot) {
|
|
241
|
+
const out = this.gitExec.tryGit(['fetch', 'origin', 'main'], repoRoot);
|
|
242
|
+
if (out.ok)
|
|
243
|
+
return;
|
|
244
|
+
throw new rules_config_1.CliExitError(1, `❌ Could not fetch origin/main (needed to READ the fork point — it is never merged). Nothing was pushed.\n git said: ${out.stderr}`);
|
|
245
|
+
}
|
|
246
|
+
prRef(branch) {
|
|
247
|
+
const out = (0, child_process_1.spawnSync)('gh', ['pr', 'view', branch, '--json', 'number,url', '--jq', '"\\(.number)\\t\\(.url)"'], { encoding: 'utf8' });
|
|
248
|
+
if (out.status !== 0)
|
|
249
|
+
return new HotfixPrRef('', '');
|
|
250
|
+
const parts = (out.stdout ?? '').trim().split('\t');
|
|
251
|
+
return new HotfixPrRef(parts[0] ?? '', parts[1] ?? '');
|
|
252
|
+
}
|
|
253
|
+
editPrBody(prNumber, bodyFile) {
|
|
254
|
+
return (0, child_process_1.spawnSync)('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile], { stdio: 'inherit' }).status === 0;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
exports.UpsertHotfixPrCommand = UpsertHotfixPrCommand;
|
|
258
|
+
exports.UpsertHotfixPrCommand = UpsertHotfixPrCommand = tslib_1.__decorate([
|
|
259
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
260
|
+
tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
|
|
261
|
+
rules_config_1.BranchIdentity,
|
|
262
|
+
git_readAiBranchName_1.AiBranchName,
|
|
263
|
+
git_exec_1.GitExec,
|
|
264
|
+
rules_config_1.ReviewJsonService,
|
|
265
|
+
build_affected_1.BuildAffected,
|
|
266
|
+
build_artifact_gate_1.BuildArtifactGate,
|
|
267
|
+
merge_state_1.MergeState,
|
|
268
|
+
checklist_scanner_1.ChecklistScanner,
|
|
269
|
+
hotfix_pr_publisher_1.HotfixPrPublisher,
|
|
270
|
+
dashboard_1.Dashboard,
|
|
271
|
+
author_identity_1.AuthorIdentityResolver,
|
|
272
|
+
checklist_comment_renderer_1.ChecklistCommentRenderer,
|
|
273
|
+
pr_comment_upserter_1.PrCommentUpserter,
|
|
274
|
+
squash_settings_enforcer_1.SquashSettingsEnforcer,
|
|
275
|
+
rules_config_1.GateTokenService])
|
|
276
|
+
], UpsertHotfixPrCommand);
|
|
277
|
+
//# sourceMappingURL=upsert-hotfix-pr-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsert-hotfix-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/upsert-hotfix-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AAC7B,0DAUiC;AACjC,yCAA2D;AAC3D,2EAAgE;AAChE,mDAA+C;AAC/C,+DAA6E;AAC7E,yEAAoE;AACpE,+DAA0D;AAC1D,yDAAqD;AACrD,qEAAuF;AAEvF,yEAAoE;AACpE,iEAAuE;AACvE,yEAAsF;AACtF,mFAA8E;AAC9E,yDAA6F;AAC7F,2FAAgH;AAChH,iFAA4E;AAC5E,qEAAyE;AAEzE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,kGAAkG;AAClG,MAAa,WAAW;IACpB,MAAM,CAAS;IACf,GAAG,CAAS;IAEZ,YAAY,MAAc,EAAE,GAAW;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AARD,kCAQC;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAGT;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAjBrB,yDAAyD;IACzD,YACqB,cAA8B,EAC9B,cAA8B,EAC9B,YAA0B,EAC1B,OAAgB,EAChB,iBAAoC,EACpC,aAA4B,EAC5B,iBAAoC,EACpC,UAAsB,EACtB,gBAAkC,EAClC,SAA4B,EAC5B,SAAoB,EACpB,cAAsC,EACtC,gBAA0C,EAC1C,eAAkC,EAClC,cAAsC,EACtC,gBAAkC;QAflC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAS;QAChB,sBAAiB,GAAjB,i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,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACjH,CAAC;CACJ,CAAA;AAvNY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIA,6BAAc;QACd,6BAAc;QAChB,mCAAY;QACjB,kBAAO;QACG,gCAAiB;QACrB,8BAAa;QACT,uCAAiB;QACxB,wBAAU;QACJ,oCAAgB;QACvB,uCAAiB;QACjB,qBAAS;QACJ,wCAAsB;QACpB,qDAAwB;QACzB,uCAAiB;QAClB,iDAAsB;QACpB,+BAAgB;GAlB9C,qBAAqB,CAuNjC","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n BranchIdentity,\n CliExitError,\n GateTokenService,\n PrGateConfig,\n PrSummary,\n RepoRootFinder,\n ReviewJsonService,\n loadAndValidate,\n writeTemplate,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { GitExec } from '../workflow/git-exec';\nimport { BuildAffected, BuildGateOptions } from '../workflow/build-affected';\nimport { BuildArtifactGate } from '../workflow/build-artifact-gate';\nimport { FINISH_STAGE } from '../workflow/build-gate-log';\nimport { MergeState } from '../workflow/merge-state';\nimport { ChecklistScanOptions, ChecklistScanner } from '../workflow/checklist-scanner';\nimport { TriggeredChecklist } from '../workflow/checklist-detector';\nimport { HotfixPrPublisher } from '../workflow/hotfix-pr-publisher';\nimport { UPSERT_HOTFIX_PR_COMMAND } from '../workflow/hotfix-redirect';\nimport { PrCommentRequest, PrCommentUpserter } from '../workflow/pr-comment-upserter';\nimport { SquashSettingsEnforcer } from '../workflow/squash-settings-enforcer';\nimport { Dashboard, DashboardInput, DETAIL_COMMENT_MARKER } from '../../dashboard/dashboard';\nimport { ChecklistCommentRenderer, CHECKLIST_COMMENT_MARKER } from '../../dashboard/checklist-comment-renderer';\nimport { ChecklistCommentRow } from '../../dashboard/checklist-comment-row';\nimport { AuthorIdentityResolver } from '../../dashboard/author-identity';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** The PR this run landed on. Both '' when it could not be resolved. Data-only, per CLAUDE.md. */\nexport class HotfixPrRef {\n number: string;\n url: string;\n\n constructor(number: string, url: string) {\n this.number = number;\n this.url = url;\n }\n}\n\n/**\n * `wp-upsert-hotfix-pr` — the ONE command that publishes a `/hotfix/` branch (issue #1057).\n *\n * A hotfix branch is cut from the exact sha running in production, so that what ships is production plus\n * the fix and nothing else. The three-stage PR flow cannot publish it: stage ① merges main into the branch,\n * which turns \"prod + fix\" into \"main + fix\" and ships every commit that has landed but has not been\n * promoted. And a hotfix runs no reviewers, so the stages have nothing to do between them. This is the\n * whole flow, in one command, in this order:\n *\n * 1. refuse unless the branch carries the exact, case-sensitive `/hotfix/` segment;\n * 2. require a clean tree and summary.json — a missing one prints its path and schema and exits;\n * 3. run ONLY the `hotfix-ci` gate (build + test). Red means nothing is pushed;\n * 4. NEVER merge main into the branch, never squash it, never rewrite it — HEAD is checked unchanged;\n * 5. push ONCE, fast-forward only, as a child process (pr-creation-or-push-guard stays intact);\n * 6. create or update the audit-bannered PR to main, and NEVER enable auto-merge — the consumer merges\n * after it has deployed and verified the hotfix. Re-running after another commit pushes again and\n * updates the same PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class UpsertHotfixPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly branchIdentity: BranchIdentity,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly buildAffected: BuildAffected,\n private readonly buildArtifactGate: BuildArtifactGate,\n private readonly mergeState: MergeState,\n private readonly checklistScanner: ChecklistScanner,\n private readonly publisher: HotfixPrPublisher,\n private readonly dashboard: Dashboard,\n private readonly authorIdentity: AuthorIdentityResolver,\n private readonly checklistComment: ChecklistCommentRenderer,\n private readonly commentUpserter: PrCommentUpserter,\n private readonly squashSettings: SquashSettingsEnforcer,\n private readonly gateTokenService: GateTokenService,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const branch = this.branchIdentity.current();\n // FIRST, before any write: a non-hotfix branch gets nothing from this command, not even a template.\n this.assertHotfixBranch(branch);\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n this.gitExec.assertCleanTree(repoRoot);\n this.assertNoUnvalidatedMerge(repoRoot);\n\n const featureName = this.aiBranchName.getFeatureName();\n const summaryPath = this.reviewJsonService.summaryJsonPath(repoRoot, featureName);\n // Throws InformAiError carrying the path and the schema when summary.json is missing or invalid.\n const summary = this.reviewJsonService.loadSummaryJson(summaryPath, [], '', {}, UPSERT_HOTFIX_PR_COMMAND);\n\n // origin/main is READ (the build's merge-base and the dashboard's fork point) — never merged.\n this.fetchMain(repoRoot);\n const headBefore = this.headSha(repoRoot);\n await this.buildAffected.runBuildGate(\n repoRoot,\n new BuildGateOptions('🛠️ Hotfix build gate (hotfix-ci: build + test only)', UPSERT_HOTFIX_PR_COMMAND, 'Hotfix build failed — nothing was pushed and no PR was created or updated.', FINISH_STAGE),\n );\n this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n if (this.headSha(repoRoot) !== headBefore) {\n throw new CliExitError(1, `❌ HEAD moved while the hotfix build ran, so the build does not cover the commit that would be pushed. Nothing was pushed. Re-run ${UPSERT_HOTFIX_PR_COMMAND}.`);\n }\n\n const ref = this.publish(repoRoot, branch, summary, headBefore);\n this.postComments(repoRoot, featureName, ref, summary);\n this.squashSettings.ensure();\n const archived = this.reviewJsonService.archiveSummaryJson(summaryPath);\n if (archived !== '') process.stdout.write(` archived this run's summary.json → ${archived} (audit only) ✓\\n`);\n process.stdout.write(this.closingBlock(ref, summary.title, branch));\n }\n\n private assertHotfixBranch(branch: string): void {\n if (this.branchIdentity.isHotfix(branch)) return;\n throw new CliExitError(\n 1,\n `wp-upsert-hotfix-pr only runs on a branch containing the exact, case-sensitive /hotfix/ segment; '${branch}' does not.\\n` +\n 'Nothing was changed. A normal branch is published with the three-stage flow:\\n' +\n ' pnpm wp-start-upsert-pr\\n pnpm wp-review-upsert-pr\\n pnpm wp-finish-upsert-pr',\n );\n }\n\n // A hotfix flow never STARTS a merge, but a branch somebody ran wp-start-update on can carry one.\n private assertNoUnvalidatedMerge(repoRoot: string): void {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const active = this.mergeState.findActiveMergeRunDir(home);\n const marker = active === null ? null : this.mergeState.readMergeMarker(active);\n if (marker === null || marker.validated) return;\n throw new CliExitError(\n 1,\n 'wp-upsert-hotfix-pr refuses a branch with an active, unvalidated 3-point merge. A hotfix branch must\\n' +\n 'not take main at all: abort that merge and return the branch to the production sha plus your fix\\n' +\n `commits, then re-run ${UPSERT_HOTFIX_PR_COMMAND}. Nothing was pushed.`,\n );\n }\n\n /** Body before push (GatedPrPublisher's ordering), fast-forward push, then create or edit — never merge. */\n private publish(repoRoot: string, branch: string, summary: PrSummary, headSha: string): HotfixPrRef {\n const config = this.prGateConfig(repoRoot);\n const input = this.dashboardInput(repoRoot, summary, config);\n const tokenSuffix = this.tokenSuffix(config.gateSalt, headSha);\n const initial = this.prRef(branch);\n const body = this.dashboard.renderPrBody(input, initial.url) + tokenSuffix;\n const bodyFile = path.join(this.reviewJsonService.prDirFor(repoRoot, this.aiBranchName.getFeatureName()), 'pr-body.md');\n fs.mkdirSync(path.dirname(bodyFile), { recursive: true });\n fs.writeFileSync(bodyFile, body + '\\n');\n\n process.stdout.write('\\n' + SEP + '📋 Hotfix PR (bannered audit, never auto-merged)\\n' + SEP + '\\n');\n const published = this.publisher.publish(branch, this.titleFrom(summary, branch), bodyFile, UPSERT_HOTFIX_PR_COMMAND);\n if (published.createFailed) {\n throw new CliExitError(1, `❌ gh pr create failed after the push. The rendered body is in ${bodyFile}; summary.json was kept. Re-run ${UPSERT_HOTFIX_PR_COMMAND}.`);\n }\n const ref = this.prRef(branch);\n const resolved = new HotfixPrRef(ref.number !== '' ? ref.number : published.number, ref.url);\n // A brand-new PR had no URL to self-link until `gh pr create` returned one.\n const finalBody = this.dashboard.renderPrBody(input, resolved.url) + tokenSuffix;\n if (finalBody !== body && resolved.number !== '') {\n fs.writeFileSync(bodyFile, finalBody + '\\n');\n if (!this.editPrBody(resolved.number, bodyFile)) {\n process.stderr.write(`⚠️ Could not add the PR's own link to its description (non-fatal — the PR and the gate token are up).\\n`);\n }\n }\n return resolved;\n }\n\n private dashboardInput(repoRoot: string, summary: PrSummary, config: PrGateConfig): DashboardInput {\n const forkPoint = this.git(repoRoot, ['merge-base', 'origin/main', 'HEAD']);\n const featureHead = this.git(repoRoot, ['rev-parse', 'HEAD']);\n const mainHead = this.git(repoRoot, ['rev-parse', 'origin/main']);\n const range = `${forkPoint}..${featureHead}`;\n const changedFiles = this.git(repoRoot, ['diff', range, '--name-only'])\n .split('\\n')\n .filter((f: string): boolean => f.trim() !== '');\n const gateResults = this.dashboard.computeGateResults(config.gates, changedFiles);\n const disables = this.dashboard.countAddedDisables(this.git(repoRoot, ['diff', range]));\n const buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);\n const title = this.titleFrom(summary, this.branchIdentity.current());\n return new DashboardInput(title, gateResults, disables, true, forkPoint, featureHead, mainHead, summary, [], buildCommand, 0, this.authorIdentity.resolve(summary.model), true);\n }\n\n /** The 1st comment (full dashboard) and, when the repo defines checklists, the bypassed-roster 2nd. */\n private postComments(repoRoot: string, featureName: string, ref: HotfixPrRef, summary: PrSummary): void {\n if (ref.number === '') {\n process.stderr.write(`⚠️ Could not resolve the PR number after the push, so the audit comments were not posted. The PR body\\n still carries the hotfix banner. Re-run ${UPSERT_HOTFIX_PR_COMMAND} to post them.\\n`);\n return;\n }\n const config = this.prGateConfig(repoRoot);\n const prDir = this.reviewJsonService.prDirFor(repoRoot, featureName);\n const detail = new PrCommentRequest();\n detail.prNumber = ref.number;\n detail.marker = DETAIL_COMMENT_MARKER;\n // The audit banner must be the FIRST thing on the comment, so the marker goes last.\n detail.body = this.dashboard.renderDetailComment(this.dashboardInput(repoRoot, summary, config)) + '\\n\\n' + DETAIL_COMMENT_MARKER;\n detail.payloadDir = prDir;\n detail.payloadName = 'detail-comment.json';\n detail.label = 'full dashboard comment';\n this.commentUpserter.upsert(detail);\n\n if (config.checklists.length === 0 || !config.checklistComments) return;\n const scan = this.checklistScanner.scan(repoRoot, config.checklists, new ChecklistScanOptions(config.maxReviewerRounds, false, ''));\n const rows = scan.roster.entries.map(\n (entry: TriggeredChecklist): ChecklistCommentRow =>\n new ChecklistCommentRow('none', 'none', entry.def.id, '', '', entry.matchedFiles.length > 0, entry.def.patterns, entry.matchedPatterns, entry.matchedFiles, scan.roster.changedFileCount),\n );\n const roster = new PrCommentRequest();\n roster.prNumber = ref.number;\n roster.marker = CHECKLIST_COMMENT_MARKER;\n roster.body = this.checklistComment.render(rows, false, scan.roster.baseResolved, 0, true);\n roster.payloadDir = prDir;\n roster.payloadName = 'checklist-comment.json';\n roster.label = 'checklist review comment';\n this.commentUpserter.upsert(roster);\n }\n\n private closingBlock(ref: HotfixPrRef, title: string, branch: string): string {\n const link = ref.url === '' ? '(PR URL unresolved — see the gh output above)' : ref.url;\n return (\n '\\n' +\n SEP +\n `✅ Hotfix PR ${ref.number === '' ? '' : `#${ref.number} `}is up — NOT merged, and auto-merge was NOT enabled\\n` +\n SEP +\n '\\n' +\n ' 1. ran hotfix-ci (build + test only); lint, validators and reviewers are bypassed and bannered\\n' +\n ` 2. pushed ${branch} fast-forward only — main was never merged in and the branch was not rewritten\\n` +\n ` 3. wrote the audit-bannered body to the PR titled: \"${title}\"\\n\\n` +\n ' A hotfix PR is never auto-merged. Deploy and verify the hotfix first; the merge to main is then a\\n' +\n ' deliberate step (pnpm wp-land-pr). Another commit on this branch? Commit it and re-run\\n' +\n ` ${UPSERT_HOTFIX_PR_COMMAND} — it pushes again and updates this same PR.\\n\\n` +\n `🔗 ${link}\\n`\n );\n }\n\n private tokenSuffix(gateSalt: string, headSha: string): string {\n const marker = this.gateTokenService.gateTokenMarker(gateSalt, headSha);\n return marker === '' ? '' : `\\n\\n${marker}\\n`;\n }\n\n private titleFrom(summary: PrSummary, branch: string): string {\n return summary.title !== '' ? summary.title : branch.replace(/[-/]+/g, ' ').trim();\n }\n\n private headSha(repoRoot: string): string {\n return this.git(repoRoot, ['rev-parse', 'HEAD']);\n }\n\n private git(repoRoot: string, args: string[]): string {\n return this.gitExec.gitQuery(args, repoRoot, `git ${args.join(' ')} failed in ${repoRoot}`);\n }\n\n // ── seams, protected so the spec drives them with no network, no gh and no webpieces.config.json ──\n\n protected prGateConfig(repoRoot: string): PrGateConfig {\n return loadAndValidate(repoRoot).prGate;\n }\n\n protected fetchMain(repoRoot: string): void {\n const out = this.gitExec.tryGit(['fetch', 'origin', 'main'], repoRoot);\n if (out.ok) return;\n throw new CliExitError(1, `❌ Could not fetch origin/main (needed to READ the fork point — it is never merged). Nothing was pushed.\\n git said: ${out.stderr}`);\n }\n\n protected prRef(branch: string): HotfixPrRef {\n const out = spawnSync('gh', ['pr', 'view', branch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"'], { encoding: 'utf8' });\n if (out.status !== 0) return new HotfixPrRef('', '');\n const parts = (out.stdout ?? '').trim().split('\\t');\n return new HotfixPrRef(parts[0] ?? '', parts[1] ?? '');\n }\n\n protected editPrBody(prNumber: string, bodyFile: string): boolean {\n return spawnSync('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile], { stdio: 'inherit' }).status === 0;\n }\n}\n"]}
|
|
@@ -17,6 +17,7 @@ import { AwaitChecksCommand, AwaitChecksOptions } from './commands/await-checks-
|
|
|
17
17
|
import { PushDevCommand, PushDevOptions } from './commands/push-dev-command';
|
|
18
18
|
import { FinishPushDevCommand, FinishPushDevOptions } from './commands/finish-push-dev-command';
|
|
19
19
|
import { HumanPostPrCommand } from './commands/human-post-pr-command';
|
|
20
|
+
import { UpsertHotfixPrCommand } from './commands/upsert-hotfix-pr-command';
|
|
20
21
|
import { PushDevStateStore } from './workflow/push-dev-state';
|
|
21
22
|
import { RepoRootFinder } from '@webpieces/rules-config';
|
|
22
23
|
/**
|
|
@@ -44,9 +45,10 @@ export declare class PrGateApp {
|
|
|
44
45
|
private readonly pushDevCommand;
|
|
45
46
|
private readonly finishPushDevCommand;
|
|
46
47
|
private readonly humanPostPrCommand;
|
|
48
|
+
private readonly upsertHotfixPrCommand;
|
|
47
49
|
private readonly pushDevStateStore;
|
|
48
50
|
private readonly repoRootFinder;
|
|
49
|
-
constructor(startUpdateCommand: StartUpdateCommand, finishUpdateCommand: FinishUpdateCommand, startUpsertPrCommand: StartUpsertPrCommand, finishUpsertPrCommand: FinishUpsertPrCommand, cleanupCommand: CleanupCommand, syncMainCommand: SyncMainCommand, landPrCommand: LandPrCommand, checkPrCommand: CheckPrCommand, reviewUpsertPrCommand: ReviewUpsertPrCommand, reapWorktreeCommand: ReapWorktreeCommand, buildCommand: BuildCommand, awaitReviewsCommand: AwaitReviewsCommand, writeReviewCommand: WriteReviewCommand, writeReviewFixesCommand: WriteReviewFixesCommand, awaitChecksCommand: AwaitChecksCommand, pushDevCommand: PushDevCommand, finishPushDevCommand: FinishPushDevCommand, humanPostPrCommand: HumanPostPrCommand, pushDevStateStore: PushDevStateStore, repoRootFinder: RepoRootFinder);
|
|
51
|
+
constructor(startUpdateCommand: StartUpdateCommand, finishUpdateCommand: FinishUpdateCommand, startUpsertPrCommand: StartUpsertPrCommand, finishUpsertPrCommand: FinishUpsertPrCommand, cleanupCommand: CleanupCommand, syncMainCommand: SyncMainCommand, landPrCommand: LandPrCommand, checkPrCommand: CheckPrCommand, reviewUpsertPrCommand: ReviewUpsertPrCommand, reapWorktreeCommand: ReapWorktreeCommand, buildCommand: BuildCommand, awaitReviewsCommand: AwaitReviewsCommand, writeReviewCommand: WriteReviewCommand, writeReviewFixesCommand: WriteReviewFixesCommand, awaitChecksCommand: AwaitChecksCommand, pushDevCommand: PushDevCommand, finishPushDevCommand: FinishPushDevCommand, humanPostPrCommand: HumanPostPrCommand, upsertHotfixPrCommand: UpsertHotfixPrCommand, pushDevStateStore: PushDevStateStore, repoRootFinder: RepoRootFinder);
|
|
50
52
|
/**
|
|
51
53
|
* Refuse `command` while a `wp-push-dev --resolve` is half-finished.
|
|
52
54
|
*
|
|
@@ -101,6 +103,11 @@ export declare class PrGateApp {
|
|
|
101
103
|
finishUpsertPr(): Promise<void>;
|
|
102
104
|
/** `wp-human-post-pr`: human-attested post with optional local build and no automated review. */
|
|
103
105
|
humanPostPr(): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* `wp-upsert-hotfix-pr`: the one command for a `/hotfix/` branch — `hotfix-ci` gate, no merge from
|
|
108
|
+
* main, one fast-forward push, upsert the bannered PR, never auto-merge (issue #1057).
|
|
109
|
+
*/
|
|
110
|
+
upsertHotfixPr(): Promise<void>;
|
|
104
111
|
/**
|
|
105
112
|
* `wp-cleanup`: reap what is provably merged AND every zero-commit husk, then report the rest with
|
|
106
113
|
* the exact flags that take it. `options` carries what argv said — see CleanupOptions.
|