@webpieces/pr-gate 0.4.991 → 0.4.993
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 +6 -6
- package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -3
- package/src/scripts/commands/finish-upsert-pr-command.js +16 -12
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/human-post-pr-command.js +5 -3
- package/src/scripts/commands/human-post-pr-command.js.map +1 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.js +8 -5
- package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
- package/src/scripts/workflow/gated-pr-publisher.d.ts +37 -5
- package/src/scripts/workflow/gated-pr-publisher.js +75 -10
- package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/hotfix-pr-publisher.d.ts +2 -1
- package/src/scripts/workflow/hotfix-pr-publisher.js +4 -3
- package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/pr-number-predictor.d.ts +24 -0
- package/src/scripts/workflow/pr-number-predictor.js +80 -0
- package/src/scripts/workflow/pr-number-predictor.js.map +1 -0
|
@@ -16,6 +16,7 @@ const build_gate_log_1 = require("../workflow/build-gate-log");
|
|
|
16
16
|
const merge_state_1 = require("../workflow/merge-state");
|
|
17
17
|
const checklist_scanner_1 = require("../workflow/checklist-scanner");
|
|
18
18
|
const hotfix_pr_publisher_1 = require("../workflow/hotfix-pr-publisher");
|
|
19
|
+
const gated_pr_publisher_1 = require("../workflow/gated-pr-publisher");
|
|
19
20
|
const hotfix_redirect_1 = require("../workflow/hotfix-redirect");
|
|
20
21
|
const pr_comment_upserter_1 = require("../workflow/pr-comment-upserter");
|
|
21
22
|
const squash_settings_enforcer_1 = require("../workflow/squash-settings-enforcer");
|
|
@@ -146,22 +147,24 @@ let UpsertHotfixPrCommand = class UpsertHotfixPrCommand {
|
|
|
146
147
|
const input = await this.dashboardInput(repoRoot, summary, config);
|
|
147
148
|
const tokenSuffix = this.tokenSuffix(config.gateSalt, headSha);
|
|
148
149
|
const initial = await this.prRef(branch);
|
|
149
|
-
const
|
|
150
|
+
const render = (prUrl) => this.dashboard.renderPrBody(input, prUrl) + tokenSuffix;
|
|
151
|
+
const body = render(initial.url);
|
|
150
152
|
for (const warning of new issue_references_1.IssueReferences().closeWarnings(summary.addressesIssues))
|
|
151
153
|
process.stdout.write(`${warning}\n`);
|
|
152
154
|
const bodyFile = path.join(this.reviewJsonService.prDirFor(repoRoot, await this.aiBranchName.getFeatureName()), 'pr-body.md');
|
|
153
155
|
fs.mkdirSync(path.dirname(bodyFile), { recursive: true });
|
|
154
156
|
fs.writeFileSync(bodyFile, body + '\n');
|
|
155
157
|
process.stdout.write('\n' + SEP + '📋 Hotfix PR (bannered audit, never auto-merged)\n' + SEP + '\n');
|
|
156
|
-
const published = await this.publisher.publish(branch, this.titleFrom(summary, branch), bodyFile, hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND);
|
|
158
|
+
const published = await this.publisher.publish(branch, this.titleFrom(summary, branch), new gated_pr_publisher_1.PrBodyDraft(bodyFile, body, render), hotfix_redirect_1.UPSERT_HOTFIX_PR_COMMAND);
|
|
157
159
|
if (published.createFailed) {
|
|
158
160
|
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}.`);
|
|
159
161
|
}
|
|
160
162
|
const ref = await this.prRef(branch);
|
|
161
163
|
const resolved = new HotfixPrRef(ref.number !== '' ? ref.number : published.number, ref.url);
|
|
162
|
-
// A brand-new PR
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
// A brand-new PR went up with its PREDICTED link (#1418); back-fill only a wrong or missing guess.
|
|
165
|
+
this.publisher.reportPredictedLink(published, resolved.number);
|
|
166
|
+
const finalBody = render(resolved.url);
|
|
167
|
+
if (finalBody !== published.body && resolved.number !== '') {
|
|
165
168
|
fs.writeFileSync(bodyFile, finalBody + '\n');
|
|
166
169
|
if (!(await this.editPrBody(resolved.number, bodyFile))) {
|
|
167
170
|
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`);
|
|
@@ -1 +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,+CAAyB;AACzB,mDAA6B;AAC7B,sEAA+D;AAC/D,0DAAqK;AACrK,8DAA6D;AAC7D,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;AACzE,uEAAmE;AAEnE,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;IACA;IAlBrB,yDAAyD;IACzD,YACqB,cAA8B,EAC9B,cAA8B,EAC9B,YAA0B,EAC1B,OAAgB,EAChB,iBAAoC,EACpC,aAA4B,EAC5B,iBAAoC,EACpC,UAAsB,EACtB,gBAAkC,EAClC,SAA4B,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import * as fs from 'fs';\nimport * as path from 'path';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { CliExitError, GateTokenService, PrGateConfig, PrSummary, RepoRootFinder, ReviewJsonService, loadAndValidate, writeTemplate } from '@webpieces/rules-config';\nimport { NativeProcessApi } from '@webpieces/tooling-common';\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';\nimport { IssueReferences } from '../../dashboard/issue-references';\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 private readonly processes: NativeProcessApi,\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 await this.gitExec.assertCleanTree(repoRoot);\n await this.assertNoUnvalidatedMerge(repoRoot);\n\n const featureName = await 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 // FAIL FAST on a hand-written closing reference (issue #1310); renderPrBody re-judges the final body.\n new IssueReferences().assertNoStrayClosingReferences(summary.summary, summary.addressesIssues, UPSERT_HOTFIX_PR_COMMAND);\n\n // origin/main is READ (the build's merge-base and the dashboard's fork point) — never merged.\n await this.fetchMain(repoRoot);\n const headBefore = await 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 await this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n await this.gitExec.assertCleanTree(repoRoot);\n if (await 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 = await this.publish(repoRoot, branch, summary, headBefore);\n await this.postComments(repoRoot, featureName, ref, summary);\n await 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 async assertNoUnvalidatedMerge(repoRoot: string): Promise<void> {\n const home = this.mergeState.mergeDirFor(repoRoot, await 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 async publish(repoRoot: string, branch: string, summary: PrSummary, headSha: string): Promise<HotfixPrRef> {\n const config = this.prGateConfig(repoRoot);\n const input = await this.dashboardInput(repoRoot, summary, config);\n const tokenSuffix = this.tokenSuffix(config.gateSalt, headSha);\n const initial = await this.prRef(branch);\n const body = this.dashboard.renderPrBody(input, initial.url) + tokenSuffix;\n for (const warning of new IssueReferences().closeWarnings(summary.addressesIssues)) process.stdout.write(`${warning}\\n`);\n const bodyFile = path.join(this.reviewJsonService.prDirFor(repoRoot, await 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 = await 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 = await 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 (!(await 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 async dashboardInput(repoRoot: string, summary: PrSummary, config: PrGateConfig): Promise<DashboardInput> {\n const forkPoint = await this.git(repoRoot, ['merge-base', 'origin/main', 'HEAD']);\n const featureHead = await this.git(repoRoot, ['rev-parse', 'HEAD']);\n const mainHead = await this.git(repoRoot, ['rev-parse', 'origin/main']);\n const range = `${forkPoint}..${featureHead}`;\n const changedFiles = (await 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(await 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 async postComments(repoRoot: string, featureName: string, ref: HotfixPrRef, summary: PrSummary): Promise<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(await 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 await this.commentUpserter.upsert(detail);\n\n if (config.checklists.length === 0 || !config.checklistComments) return;\n const scan = await 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 await 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): Promise<string> {\n return this.git(repoRoot, ['rev-parse', 'HEAD']);\n }\n\n private git(repoRoot: string, args: string[]): Promise<string> {\n return this.gitExec.gitQuery(args, repoRoot, `git ${args.join(' ')} failed in ${repoRoot}`);\n }\n\n // ── seam, protected so the spec drives it with no webpieces.config.json ──\n\n protected prGateConfig(repoRoot: string): PrGateConfig {\n return loadAndValidate(repoRoot).prGate;\n }\n\n private async fetchMain(repoRoot: string): Promise<void> {\n const out = await 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 private async prRef(branch: string): Promise<HotfixPrRef> {\n const out = await this.processes.run('gh', ['pr', 'view', branch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"']);\n if (!out.ok) return new HotfixPrRef('', '');\n const parts = out.stdout.trim().split('\\t');\n return new HotfixPrRef(parts[0] ?? '', parts[1] ?? '');\n }\n\n private async editPrBody(prNumber: string, bodyFile: string): Promise<boolean> {\n return (await this.processes.passThrough('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile])).ok;\n }\n}\n"]}
|
|
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,+CAAyB;AACzB,mDAA6B;AAC7B,sEAA+D;AAC/D,0DAAqK;AACrK,8DAA6D;AAC7D,yCAA2D;AAC3D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E,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,0BAA0B,CAAC,CAAC,CAAC;QAC/H,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,OAAO,IAAI,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC5C,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5C,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAEO,KAAK,CAAC,UAAU,CAAC,QAAgB,EAAE,QAAgB;QACvD,OAAO,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1G,CAAC;CACJ,CAAA;AA7NY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIA,6BAAc;QACd,mCAAc;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;QACvB,iCAAgB;GAnBvC,qBAAqB,CA6NjC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { CliExitError, GateTokenService, PrGateConfig, PrSummary, RepoRootFinder, ReviewJsonService, loadAndValidate, writeTemplate } from '@webpieces/rules-config';\nimport { NativeProcessApi } from '@webpieces/tooling-common';\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 { PrBodyDraft } from '../workflow/gated-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';\nimport { IssueReferences } from '../../dashboard/issue-references';\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 private readonly processes: NativeProcessApi,\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 await this.gitExec.assertCleanTree(repoRoot);\n await this.assertNoUnvalidatedMerge(repoRoot);\n\n const featureName = await 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 // FAIL FAST on a hand-written closing reference (issue #1310); renderPrBody re-judges the final body.\n new IssueReferences().assertNoStrayClosingReferences(summary.summary, summary.addressesIssues, UPSERT_HOTFIX_PR_COMMAND);\n\n // origin/main is READ (the build's merge-base and the dashboard's fork point) — never merged.\n await this.fetchMain(repoRoot);\n const headBefore = await 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 await this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n await this.gitExec.assertCleanTree(repoRoot);\n if (await 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 = await this.publish(repoRoot, branch, summary, headBefore);\n await this.postComments(repoRoot, featureName, ref, summary);\n await 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 async assertNoUnvalidatedMerge(repoRoot: string): Promise<void> {\n const home = this.mergeState.mergeDirFor(repoRoot, await 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 async publish(repoRoot: string, branch: string, summary: PrSummary, headSha: string): Promise<HotfixPrRef> {\n const config = this.prGateConfig(repoRoot);\n const input = await this.dashboardInput(repoRoot, summary, config);\n const tokenSuffix = this.tokenSuffix(config.gateSalt, headSha);\n const initial = await this.prRef(branch);\n const render = (prUrl: string): string => this.dashboard.renderPrBody(input, prUrl) + tokenSuffix;\n const body = render(initial.url);\n for (const warning of new IssueReferences().closeWarnings(summary.addressesIssues)) process.stdout.write(`${warning}\\n`);\n const bodyFile = path.join(this.reviewJsonService.prDirFor(repoRoot, await 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 = await this.publisher.publish(branch, this.titleFrom(summary, branch), new PrBodyDraft(bodyFile, body, render), 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 = await this.prRef(branch);\n const resolved = new HotfixPrRef(ref.number !== '' ? ref.number : published.number, ref.url);\n // A brand-new PR went up with its PREDICTED link (#1418); back-fill only a wrong or missing guess.\n this.publisher.reportPredictedLink(published, resolved.number);\n const finalBody = render(resolved.url);\n if (finalBody !== published.body && resolved.number !== '') {\n fs.writeFileSync(bodyFile, finalBody + '\\n');\n if (!(await 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 async dashboardInput(repoRoot: string, summary: PrSummary, config: PrGateConfig): Promise<DashboardInput> {\n const forkPoint = await this.git(repoRoot, ['merge-base', 'origin/main', 'HEAD']);\n const featureHead = await this.git(repoRoot, ['rev-parse', 'HEAD']);\n const mainHead = await this.git(repoRoot, ['rev-parse', 'origin/main']);\n const range = `${forkPoint}..${featureHead}`;\n const changedFiles = (await 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(await 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 async postComments(repoRoot: string, featureName: string, ref: HotfixPrRef, summary: PrSummary): Promise<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(await 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 await this.commentUpserter.upsert(detail);\n\n if (config.checklists.length === 0 || !config.checklistComments) return;\n const scan = await 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 await 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): Promise<string> {\n return this.git(repoRoot, ['rev-parse', 'HEAD']);\n }\n\n private git(repoRoot: string, args: string[]): Promise<string> {\n return this.gitExec.gitQuery(args, repoRoot, `git ${args.join(' ')} failed in ${repoRoot}`);\n }\n\n // ── seam, protected so the spec drives it with no webpieces.config.json ──\n\n protected prGateConfig(repoRoot: string): PrGateConfig {\n return loadAndValidate(repoRoot).prGate;\n }\n\n private async fetchMain(repoRoot: string): Promise<void> {\n const out = await 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 private async prRef(branch: string): Promise<HotfixPrRef> {\n const out = await this.processes.run('gh', ['pr', 'view', branch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"']);\n if (!out.ok) return new HotfixPrRef('', '');\n const parts = out.stdout.trim().split('\\t');\n return new HotfixPrRef(parts[0] ?? '', parts[1] ?? '');\n }\n\n private async editPrBody(prNumber: string, bodyFile: string): Promise<boolean> {\n return (await this.processes.passThrough('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile])).ok;\n }\n}\n"]}
|
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
import { NativeProcessApi } from '@webpieces/tooling-common';
|
|
2
2
|
import { GitExec } from './git-exec';
|
|
3
|
+
import { PrNumberPredictor } from './pr-number-predictor';
|
|
4
|
+
/**
|
|
5
|
+
* The description a caller hands the publisher. `body` is ALREADY written to `bodyFile`, rendered with
|
|
6
|
+
* whatever URL was known before publishing ('' for a brand-new PR); `render` renders the same
|
|
7
|
+
* description for a given self-link URL, so the create path can re-render it with the PREDICTED URL just
|
|
8
|
+
* before `gh pr create` (issue #1418). Data-only.
|
|
9
|
+
*/
|
|
10
|
+
export declare class PrBodyDraft {
|
|
11
|
+
bodyFile: string;
|
|
12
|
+
body: string;
|
|
13
|
+
render: (prUrl: string) => string;
|
|
14
|
+
constructor(bodyFile: string, body: string, render: (prUrl: string) => string);
|
|
15
|
+
}
|
|
3
16
|
export declare class PublishedPr {
|
|
4
17
|
number: string;
|
|
5
18
|
createFailed: boolean;
|
|
6
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The description exactly as it went up (without the file's trailing newline). A caller compares its
|
|
21
|
+
* final render — with the REAL URL — against this, and back-fills only when they differ.
|
|
22
|
+
*/
|
|
23
|
+
body: string;
|
|
24
|
+
predictedNumber: string;
|
|
25
|
+
constructor(number: string, createFailed: boolean, body: string, predictedNumber: string);
|
|
7
26
|
}
|
|
8
27
|
/**
|
|
9
28
|
* Owns the ONE ordering constraint that lets the webpieces gate be a single required check: the PR body
|
|
@@ -21,6 +40,11 @@ export declare class PublishedPr {
|
|
|
21
40
|
* right token. A brand-new PR is unaffected either way — `gh pr create` composes the body after the push,
|
|
22
41
|
* so the `opened` event already sees the final body.
|
|
23
42
|
*
|
|
43
|
+
* A brand-new PR's description also wants its OWN link, which does not exist until GitHub assigns a
|
|
44
|
+
* number. Right before `gh pr create` (after the push, to keep the race window small) the publisher
|
|
45
|
+
* PREDICTS that number and renders the body with the predicted URL (issue #1418), so a correct guess
|
|
46
|
+
* creates the PR with its final description and fires one `opened` event instead of `opened` + `edited`.
|
|
47
|
+
*
|
|
24
48
|
* THIS IS THE ONLY PUSH IN THE PR FLOW. `wp-start-upsert-pr` used to push twice (its own `ensurePushed`,
|
|
25
49
|
* and the force-push inside the 3-point merge finalize), which put code on the remote before summary.json
|
|
26
50
|
* and the checklists had even run, and fired `synchronize` against a PR body still carrying the previous
|
|
@@ -33,13 +57,21 @@ export declare class PublishedPr {
|
|
|
33
57
|
export declare class GatedPrPublisher {
|
|
34
58
|
private readonly gitExec;
|
|
35
59
|
private readonly processes;
|
|
36
|
-
|
|
60
|
+
private readonly predictor;
|
|
61
|
+
constructor(gitExec: GitExec, processes: NativeProcessApi, predictor: PrNumberPredictor);
|
|
37
62
|
/**
|
|
38
|
-
* Land
|
|
63
|
+
* Land the draft's body on the PR for `baseBranch` and push, in the gate-safe order.
|
|
39
64
|
*
|
|
40
|
-
* @param
|
|
65
|
+
* @param draft the rendered dashboard ALREADY carrying the gate token for the LOCAL head sha
|
|
66
|
+
*/
|
|
67
|
+
publish(baseBranch: string, title: string, draft: PrBodyDraft, retryCommand?: string): Promise<PublishedPr>;
|
|
68
|
+
/**
|
|
69
|
+
* Say how the create path's predicted self-link turned out, given the number GitHub REALLY assigned.
|
|
70
|
+
* Silent on the update path and when there was no prediction (the predictor already warned). A miss
|
|
71
|
+
* costs exactly what every create cost before #1418: the caller back-fills the real link.
|
|
41
72
|
*/
|
|
42
|
-
|
|
73
|
+
reportPredictedLink(published: PublishedPr, realNumber: string): void;
|
|
74
|
+
private bodyFor;
|
|
43
75
|
private editPrOrAbort;
|
|
44
76
|
private findOpenPr;
|
|
45
77
|
private editPr;
|
|
@@ -1,20 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GatedPrPublisher = exports.PublishedPr = void 0;
|
|
3
|
+
exports.GatedPrPublisher = exports.PublishedPr = exports.PrBodyDraft = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
6
|
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
7
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
7
8
|
const inversify_1 = require("inversify");
|
|
8
9
|
const git_exec_1 = require("./git-exec");
|
|
10
|
+
const pr_number_predictor_1 = require("./pr-number-predictor");
|
|
11
|
+
/**
|
|
12
|
+
* The description a caller hands the publisher. `body` is ALREADY written to `bodyFile`, rendered with
|
|
13
|
+
* whatever URL was known before publishing ('' for a brand-new PR); `render` renders the same
|
|
14
|
+
* description for a given self-link URL, so the create path can re-render it with the PREDICTED URL just
|
|
15
|
+
* before `gh pr create` (issue #1418). Data-only.
|
|
16
|
+
*/
|
|
17
|
+
class PrBodyDraft {
|
|
18
|
+
bodyFile;
|
|
19
|
+
body;
|
|
20
|
+
render;
|
|
21
|
+
constructor(bodyFile, body, render) {
|
|
22
|
+
this.bodyFile = bodyFile;
|
|
23
|
+
this.body = body;
|
|
24
|
+
this.render = render;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.PrBodyDraft = PrBodyDraft;
|
|
9
28
|
// Which PR the gated body landed on. Data-only.
|
|
10
29
|
class PublishedPr {
|
|
11
30
|
// The PR that already existed and was edited; '' when this run had to create one.
|
|
12
31
|
number;
|
|
13
32
|
// True only on the create path, when `gh pr create` itself failed — there is no PR to merge.
|
|
14
33
|
createFailed;
|
|
15
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The description exactly as it went up (without the file's trailing newline). A caller compares its
|
|
36
|
+
* final render — with the REAL URL — against this, and back-fills only when they differ.
|
|
37
|
+
*/
|
|
38
|
+
body;
|
|
39
|
+
// The number the create path predicted ('' on the update path, or when the prediction failed).
|
|
40
|
+
predictedNumber;
|
|
41
|
+
constructor(number, createFailed, body, predictedNumber) {
|
|
16
42
|
this.number = number;
|
|
17
43
|
this.createFailed = createFailed;
|
|
44
|
+
this.body = body;
|
|
45
|
+
this.predictedNumber = predictedNumber;
|
|
18
46
|
}
|
|
19
47
|
}
|
|
20
48
|
exports.PublishedPr = PublishedPr;
|
|
@@ -34,6 +62,11 @@ exports.PublishedPr = PublishedPr;
|
|
|
34
62
|
* right token. A brand-new PR is unaffected either way — `gh pr create` composes the body after the push,
|
|
35
63
|
* so the `opened` event already sees the final body.
|
|
36
64
|
*
|
|
65
|
+
* A brand-new PR's description also wants its OWN link, which does not exist until GitHub assigns a
|
|
66
|
+
* number. Right before `gh pr create` (after the push, to keep the race window small) the publisher
|
|
67
|
+
* PREDICTS that number and renders the body with the predicted URL (issue #1418), so a correct guess
|
|
68
|
+
* creates the PR with its final description and fires one `opened` event instead of `opened` + `edited`.
|
|
69
|
+
*
|
|
37
70
|
* THIS IS THE ONLY PUSH IN THE PR FLOW. `wp-start-upsert-pr` used to push twice (its own `ensurePushed`,
|
|
38
71
|
* and the force-push inside the 3-point merge finalize), which put code on the remote before summary.json
|
|
39
72
|
* and the checklists had even run, and fired `synchronize` against a PR body still carrying the previous
|
|
@@ -46,16 +79,19 @@ exports.PublishedPr = PublishedPr;
|
|
|
46
79
|
let GatedPrPublisher = class GatedPrPublisher {
|
|
47
80
|
gitExec;
|
|
48
81
|
processes;
|
|
49
|
-
|
|
82
|
+
predictor;
|
|
83
|
+
constructor(gitExec, processes, predictor) {
|
|
50
84
|
this.gitExec = gitExec;
|
|
51
85
|
this.processes = processes;
|
|
86
|
+
this.predictor = predictor;
|
|
52
87
|
}
|
|
53
88
|
/**
|
|
54
|
-
* Land
|
|
89
|
+
* Land the draft's body on the PR for `baseBranch` and push, in the gate-safe order.
|
|
55
90
|
*
|
|
56
|
-
* @param
|
|
91
|
+
* @param draft the rendered dashboard ALREADY carrying the gate token for the LOCAL head sha
|
|
57
92
|
*/
|
|
58
|
-
async publish(baseBranch, title,
|
|
93
|
+
async publish(baseBranch, title, draft, retryCommand = 'pnpm wp-finish-upsert-pr') {
|
|
94
|
+
const bodyFile = draft.bodyFile;
|
|
59
95
|
const existing = await this.findOpenPr(baseBranch);
|
|
60
96
|
// 1. Body FIRST, so a `synchronize` read arriving the instant after the push finds the right token.
|
|
61
97
|
if (existing !== '') {
|
|
@@ -72,9 +108,37 @@ let GatedPrPublisher = class GatedPrPublisher {
|
|
|
72
108
|
await this.push(baseBranch);
|
|
73
109
|
// 3. Only a brand-new PR is created, and only after the push — `gh pr create` needs the remote ref.
|
|
74
110
|
if (existing !== '')
|
|
75
|
-
return new PublishedPr(existing, false);
|
|
76
|
-
|
|
77
|
-
|
|
111
|
+
return new PublishedPr(existing, false, draft.body, '');
|
|
112
|
+
// 4. Predict the new PR's number and render its self-link into the body BEFORE creating it, so a
|
|
113
|
+
// correct guess needs no follow-up `gh pr edit` (one `opened` event, no cancelled CI run).
|
|
114
|
+
const predicted = await this.predictor.predict();
|
|
115
|
+
const body = this.bodyFor(draft, predicted);
|
|
116
|
+
process.stdout.write(predicted.number === '' ? 'Creating PR...\n' : `Creating PR (predicted #${predicted.number})...\n`);
|
|
117
|
+
return new PublishedPr('', !(await this.createPr(baseBranch, title, bodyFile)), body, predicted.number);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Say how the create path's predicted self-link turned out, given the number GitHub REALLY assigned.
|
|
121
|
+
* Silent on the update path and when there was no prediction (the predictor already warned). A miss
|
|
122
|
+
* costs exactly what every create cost before #1418: the caller back-fills the real link.
|
|
123
|
+
*/
|
|
124
|
+
reportPredictedLink(published, realNumber) {
|
|
125
|
+
if (published.predictedNumber === '' || realNumber === '')
|
|
126
|
+
return;
|
|
127
|
+
if (published.predictedNumber === realNumber) {
|
|
128
|
+
process.stdout.write(` PR link predicted #${realNumber} ✓\n`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
process.stdout.write(` PR link predicted #${published.predictedNumber}, got #${realNumber}: back-filling the real link\n`);
|
|
132
|
+
}
|
|
133
|
+
// The body to create the PR with: re-rendered with the predicted URL when there is one, else the
|
|
134
|
+
// draft as the caller wrote it. Rewrites `bodyFile` only when the bytes change.
|
|
135
|
+
bodyFor(draft, predicted) {
|
|
136
|
+
if (predicted.url === '')
|
|
137
|
+
return draft.body;
|
|
138
|
+
const body = draft.render(predicted.url);
|
|
139
|
+
if (body !== draft.body)
|
|
140
|
+
fs.writeFileSync(draft.bodyFile, body + '\n');
|
|
141
|
+
return body;
|
|
78
142
|
}
|
|
79
143
|
// Edit the PR body/title, aborting BEFORE the push if `gh` failed. Warning-and-continuing here would
|
|
80
144
|
// push code that the PR body does not vouch for; aborting leaves the PR on its previous body, whose
|
|
@@ -120,6 +184,7 @@ exports.GatedPrPublisher = GatedPrPublisher;
|
|
|
120
184
|
exports.GatedPrPublisher = GatedPrPublisher = tslib_1.__decorate([
|
|
121
185
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
122
186
|
tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec,
|
|
123
|
-
tooling_common_1.NativeProcessApi
|
|
187
|
+
tooling_common_1.NativeProcessApi,
|
|
188
|
+
pr_number_predictor_1.PrNumberPredictor])
|
|
124
189
|
], GatedPrPublisher);
|
|
125
190
|
//# sourceMappingURL=gated-pr-publisher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gated-pr-publisher.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/gated-pr-publisher.ts"],"names":[],"mappings":";;;;AAAA,0DAAuD;AACvD,8DAA6D;AAC7D,yCAA2D;AAC3D,yCAAqC;AAErC,gDAAgD;AAChD,MAAa,WAAW;IACpB,kFAAkF;IAClF,MAAM,CAAS;IACf,6FAA6F;IAC7F,YAAY,CAAU;IAEtB,YAAY,MAAc,EAAE,YAAqB;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;CACJ;AAVD,kCAUC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAEJ;IACA;IAFrB,YACqB,OAAgB,EAChB,SAA2B;QAD3B,YAAO,GAAP,OAAO,CAAS;QAChB,cAAS,GAAT,SAAS,CAAkB;IAC7C,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,OAAO,CACT,UAAkB,EAClB,KAAa,EACb,QAAgB,EAChB,YAAY,GAAG,0BAA0B;QAEzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAEnD,oGAAoG;QACpG,IAAI,QAA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G,CACnC,IAAI,EACJ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,CAClF,CAAC;QACF,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,KAAa,EAAE,QAAgB;QAClE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAC3C,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,CAAC,CAC5E,CAAC;QACF,OAAO,MAAM,CAAC,EAAE,CAAC;IACrB,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,UAAkB,EAAE,KAAa,EAAE,QAAgB;QACtE,OAAO,CACH,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAC5B,IAAI,EACJ;YACI,IAAI;YACJ,QAAQ;YACR,QAAQ;YACR,UAAU;YACV,QAAQ;YACR,MAAM;YACN,SAAS;YACT,KAAK;YACL,aAAa;YACb,QAAQ;SACX,CACJ,CACJ,CAAC,EAAE,CAAC;IACT,CAAC;IAED,mGAAmG;IACnG,oGAAoG;IAC1F,IAAI,CAAC,UAAkB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IACjD,CAAC;CACJ,CAAA;AAxGY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGP,kBAAO;QACL,iCAAgB;GAHvC,gBAAgB,CAwG5B","sourcesContent":["import { CliExitError } from '@webpieces/rules-config';\nimport { NativeProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { GitExec } from './git-exec';\n\n// Which PR the gated body landed on. Data-only.\nexport class PublishedPr {\n // The PR that already existed and was edited; '' when this run had to create one.\n number: string;\n // True only on the create path, when `gh pr create` itself failed — there is no PR to merge.\n createFailed: boolean;\n\n constructor(number: string, createFailed: boolean) {\n this.number = number;\n this.createFailed = createFailed;\n }\n}\n\n/**\n * Owns the ONE ordering constraint that lets the webpieces gate be a single required check: the PR body\n * — which carries `HMAC(gateSalt, HEAD_sha)` — is written BEFORE the push.\n *\n * WHY the order matters. Pushing first fires `pull_request:synchronize`, and CI (`wp-check-pr`) reads the\n * PR body it finds at that instant. If the body edit has not landed yet, that read sees the PREVIOUS\n * run's token, which is bound to the parent sha, and the check goes red on a timing coin-flip. #485\n * papered over this by also posting a `webpieces/pr-gate` commit status, whose newest post supersedes an\n * older one — recovery rather than prevention, and it left consumers with two entries on every PR and no\n * way to tell which one to mark required.\n *\n * The sha is already known locally: nothing about minting `HMAC(gateSalt, git rev-parse HEAD)` needs the\n * remote to have the commit. So write the body first and the `synchronize` read can only ever see the\n * right token. A brand-new PR is unaffected either way — `gh pr create` composes the body after the push,\n * so the `opened` event already sees the final body.\n *\n * THIS IS THE ONLY PUSH IN THE PR FLOW. `wp-start-upsert-pr` used to push twice (its own `ensurePushed`,\n * and the force-push inside the 3-point merge finalize), which put code on the remote before summary.json\n * and the checklists had even run, and fired `synchronize` against a PR body still carrying the previous\n * run's token. Both are gone — the merge finalize now takes `MergeEndOptions.pushRemote=false` in the PR\n * flow. So the single `synchronize` of a cycle arrives strictly after the body edit below, and can only\n * ever read the correct token.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is drawn in the DI design and injected by type.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class GatedPrPublisher {\n constructor(\n private readonly gitExec: GitExec,\n private readonly processes: NativeProcessApi,\n ) {}\n\n /**\n * Land `bodyFile` on the PR for `baseBranch` and push, in the gate-safe order.\n *\n * @param bodyFile the rendered dashboard ALREADY carrying the gate token for the LOCAL head sha\n */\n async publish(\n baseBranch: string,\n title: string,\n bodyFile: string,\n retryCommand = 'pnpm wp-finish-upsert-pr',\n ): Promise<PublishedPr> {\n const existing = await this.findOpenPr(baseBranch);\n\n // 1. Body FIRST, so a `synchronize` read arriving the instant after the push finds the right token.\n if (existing !== '') {\n process.stdout.write(\n `Updating PR #${existing} (body before push, so CI cannot read a stale token)...\\n`,\n );\n await this.editPrOrAbort(existing, title, bodyFile, retryCommand);\n // Say the consequence BEFORE the push can fail: from here the PR advertises a token for the\n // local HEAD, so a failed push leaves the PR pointing at the old commit and the gate check goes\n // RED. That is the deliberate fail-CLOSED direction, and it self-corrects on the next good run.\n process.stdout.write(\n ' body updated. Pushing now — if this push FAILS, the PR advertises a token for a commit\\n' +\n ' the remote does not have, so the webpieces gate check goes RED (never falsely green)\\n' +\n ` until you fix the push and re-run ${retryCommand}.\\n`,\n );\n }\n\n // 2. THEN push. Nothing was pushed above, so an edit failure left the remote wholly untouched.\n await this.push(baseBranch);\n\n // 3. Only a brand-new PR is created, and only after the push — `gh pr create` needs the remote ref.\n if (existing !== '') return new PublishedPr(existing, false);\n process.stdout.write('Creating PR...\\n');\n return new PublishedPr('', !(await this.createPr(baseBranch, title, bodyFile)));\n }\n\n // Edit the PR body/title, aborting BEFORE the push if `gh` failed. Warning-and-continuing here would\n // push code that the PR body does not vouch for; aborting leaves the PR on its previous body, whose\n // token is still valid for the sha the remote still has. Nothing is half-done either way.\n private async editPrOrAbort(\n prNumber: string,\n title: string,\n bodyFile: string,\n retryCommand: string,\n ): Promise<void> {\n if (await this.editPr(prNumber, title, bodyFile)) return;\n throw new CliExitError(\n 1,\n `❌ gh pr edit failed on PR #${prNumber} — NOTHING was pushed, so the PR and the remote branch are\\n` +\n ` both unchanged and still consistent. Fix gh (auth / network / permissions) and re-run\\n` +\n ` ${retryCommand}. The new body is in:\\n ${bodyFile}`,\n );\n }\n\n // The open PR whose head is `baseBranch`, or '' when there is none (or `gh` failed — treated the same,\n // so the create path then fails loudly rather than silently editing the wrong PR).\n private async findOpenPr(baseBranch: string): Promise<string> {\n const result = await this.processes.run(\n 'gh',\n ['pr', 'list', '--head', baseBranch, '--json', 'number', '--jq', '.[0].number'],\n );\n return result.ok ? result.stdout.trim() : '';\n }\n\n private async editPr(prNumber: string, title: string, bodyFile: string): Promise<boolean> {\n const result = await this.processes.passThrough(\n 'gh', ['pr', 'edit', prNumber, '--title', title, '--body-file', bodyFile],\n );\n return result.ok;\n }\n\n private async createPr(baseBranch: string, title: string, bodyFile: string): Promise<boolean> {\n return (\n await this.processes.passThrough(\n 'gh',\n [\n 'pr',\n 'create',\n '--head',\n baseBranch,\n '--base',\n 'main',\n '--title',\n title,\n '--body-file',\n bodyFile,\n ],\n )\n ).ok;\n }\n\n // Throws (CliExitError, via runGitChecked) when the push fails — deliberately NOT caught here: the\n // consequence is already printed above, and swallowing it would report a PR that was never updated.\n protected push(baseBranch: string): Promise<void> {\n return this.gitExec.ensurePushed(baseBranch);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"gated-pr-publisher.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/gated-pr-publisher.ts"],"names":[],"mappings":";;;;AAAA,0DAAuD;AACvD,8DAA6D;AAC7D,+CAAyB;AACzB,yCAA2D;AAC3D,yCAAqC;AACrC,+DAAuE;AAEvE;;;;;GAKG;AACH,MAAa,WAAW;IACpB,QAAQ,CAAS;IACjB,IAAI,CAAS;IACb,MAAM,CAA4B;IAElC,YAAY,QAAgB,EAAE,IAAY,EAAE,MAAiC;QACzE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAVD,kCAUC;AAED,gDAAgD;AAChD,MAAa,WAAW;IACpB,kFAAkF;IAClF,MAAM,CAAS;IACf,6FAA6F;IAC7F,YAAY,CAAU;IACtB;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AAQ,CAAC,CAC5E,CAAC;QACF,OAAO,MAAM,CAAC,EAAE,CAAC;IACrB,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,UAAkB,EAAE,KAAa,EAAE,QAAgB;QACtE,OAAO,CACH,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAC5B,IAAI,EACJ;YACI,IAAI;YACJ,QAAQ;YACR,QAAQ;YACR,UAAU;YACV,QAAQ;YACR,MAAM;YACN,SAAS;YACT,KAAK;YACL,aAAa;YACb,QAAQ;SACX,CACJ,CACJ,CAAC,EAAE,CAAC;IACT,CAAC;IAED,mGAAmG;IACnG,oGAAoG;IAC1F,IAAI,CAAC,UAAkB;QAC7B,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IACjD,CAAC;CACJ,CAAA;AAtIY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGP,kBAAO;QACL,iCAAgB;QAChB,uCAAiB;GAJxC,gBAAgB,CAsI5B","sourcesContent":["import { CliExitError } from '@webpieces/rules-config';\nimport { NativeProcessApi } from '@webpieces/tooling-common';\nimport * as fs from 'fs';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { GitExec } from './git-exec';\nimport { PredictedPr, PrNumberPredictor } from './pr-number-predictor';\n\n/**\n * The description a caller hands the publisher. `body` is ALREADY written to `bodyFile`, rendered with\n * whatever URL was known before publishing ('' for a brand-new PR); `render` renders the same\n * description for a given self-link URL, so the create path can re-render it with the PREDICTED URL just\n * before `gh pr create` (issue #1418). Data-only.\n */\nexport class PrBodyDraft {\n bodyFile: string;\n body: string;\n render: (prUrl: string) => string;\n\n constructor(bodyFile: string, body: string, render: (prUrl: string) => string) {\n this.bodyFile = bodyFile;\n this.body = body;\n this.render = render;\n }\n}\n\n// Which PR the gated body landed on. Data-only.\nexport class PublishedPr {\n // The PR that already existed and was edited; '' when this run had to create one.\n number: string;\n // True only on the create path, when `gh pr create` itself failed — there is no PR to merge.\n createFailed: boolean;\n /**\n * The description exactly as it went up (without the file's trailing newline). A caller compares its\n * final render — with the REAL URL — against this, and back-fills only when they differ.\n */\n body: string;\n // The number the create path predicted ('' on the update path, or when the prediction failed).\n predictedNumber: string;\n\n constructor(number: string, createFailed: boolean, body: string, predictedNumber: string) {\n this.number = number;\n this.createFailed = createFailed;\n this.body = body;\n this.predictedNumber = predictedNumber;\n }\n}\n\n/**\n * Owns the ONE ordering constraint that lets the webpieces gate be a single required check: the PR body\n * — which carries `HMAC(gateSalt, HEAD_sha)` — is written BEFORE the push.\n *\n * WHY the order matters. Pushing first fires `pull_request:synchronize`, and CI (`wp-check-pr`) reads the\n * PR body it finds at that instant. If the body edit has not landed yet, that read sees the PREVIOUS\n * run's token, which is bound to the parent sha, and the check goes red on a timing coin-flip. #485\n * papered over this by also posting a `webpieces/pr-gate` commit status, whose newest post supersedes an\n * older one — recovery rather than prevention, and it left consumers with two entries on every PR and no\n * way to tell which one to mark required.\n *\n * The sha is already known locally: nothing about minting `HMAC(gateSalt, git rev-parse HEAD)` needs the\n * remote to have the commit. So write the body first and the `synchronize` read can only ever see the\n * right token. A brand-new PR is unaffected either way — `gh pr create` composes the body after the push,\n * so the `opened` event already sees the final body.\n *\n * A brand-new PR's description also wants its OWN link, which does not exist until GitHub assigns a\n * number. Right before `gh pr create` (after the push, to keep the race window small) the publisher\n * PREDICTS that number and renders the body with the predicted URL (issue #1418), so a correct guess\n * creates the PR with its final description and fires one `opened` event instead of `opened` + `edited`.\n *\n * THIS IS THE ONLY PUSH IN THE PR FLOW. `wp-start-upsert-pr` used to push twice (its own `ensurePushed`,\n * and the force-push inside the 3-point merge finalize), which put code on the remote before summary.json\n * and the checklists had even run, and fired `synchronize` against a PR body still carrying the previous\n * run's token. Both are gone — the merge finalize now takes `MergeEndOptions.pushRemote=false` in the PR\n * flow. So the single `synchronize` of a cycle arrives strictly after the body edit below, and can only\n * ever read the correct token.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is drawn in the DI design and injected by type.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class GatedPrPublisher {\n constructor(\n private readonly gitExec: GitExec,\n private readonly processes: NativeProcessApi,\n private readonly predictor: PrNumberPredictor,\n ) {}\n\n /**\n * Land the draft's body on the PR for `baseBranch` and push, in the gate-safe order.\n *\n * @param draft the rendered dashboard ALREADY carrying the gate token for the LOCAL head sha\n */\n async publish(\n baseBranch: string,\n title: string,\n draft: PrBodyDraft,\n retryCommand = 'pnpm wp-finish-upsert-pr',\n ): Promise<PublishedPr> {\n const bodyFile = draft.bodyFile;\n const existing = await this.findOpenPr(baseBranch);\n\n // 1. Body FIRST, so a `synchronize` read arriving the instant after the push finds the right token.\n if (existing !== '') {\n process.stdout.write(\n `Updating PR #${existing} (body before push, so CI cannot read a stale token)...\\n`,\n );\n await this.editPrOrAbort(existing, title, bodyFile, retryCommand);\n // Say the consequence BEFORE the push can fail: from here the PR advertises a token for the\n // local HEAD, so a failed push leaves the PR pointing at the old commit and the gate check goes\n // RED. That is the deliberate fail-CLOSED direction, and it self-corrects on the next good run.\n process.stdout.write(\n ' body updated. Pushing now — if this push FAILS, the PR advertises a token for a commit\\n' +\n ' the remote does not have, so the webpieces gate check goes RED (never falsely green)\\n' +\n ` until you fix the push and re-run ${retryCommand}.\\n`,\n );\n }\n\n // 2. THEN push. Nothing was pushed above, so an edit failure left the remote wholly untouched.\n await this.push(baseBranch);\n\n // 3. Only a brand-new PR is created, and only after the push — `gh pr create` needs the remote ref.\n if (existing !== '') return new PublishedPr(existing, false, draft.body, '');\n\n // 4. Predict the new PR's number and render its self-link into the body BEFORE creating it, so a\n // correct guess needs no follow-up `gh pr edit` (one `opened` event, no cancelled CI run).\n const predicted = await this.predictor.predict();\n const body = this.bodyFor(draft, predicted);\n process.stdout.write(predicted.number === '' ? 'Creating PR...\\n' : `Creating PR (predicted #${predicted.number})...\\n`);\n return new PublishedPr('', !(await this.createPr(baseBranch, title, bodyFile)), body, predicted.number);\n }\n\n /**\n * Say how the create path's predicted self-link turned out, given the number GitHub REALLY assigned.\n * Silent on the update path and when there was no prediction (the predictor already warned). A miss\n * costs exactly what every create cost before #1418: the caller back-fills the real link.\n */\n reportPredictedLink(published: PublishedPr, realNumber: string): void {\n if (published.predictedNumber === '' || realNumber === '') return;\n if (published.predictedNumber === realNumber) {\n process.stdout.write(` PR link predicted #${realNumber} ✓\\n`);\n return;\n }\n process.stdout.write(` PR link predicted #${published.predictedNumber}, got #${realNumber}: back-filling the real link\\n`);\n }\n\n // The body to create the PR with: re-rendered with the predicted URL when there is one, else the\n // draft as the caller wrote it. Rewrites `bodyFile` only when the bytes change.\n private bodyFor(draft: PrBodyDraft, predicted: PredictedPr): string {\n if (predicted.url === '') return draft.body;\n const body = draft.render(predicted.url);\n if (body !== draft.body) fs.writeFileSync(draft.bodyFile, body + '\\n');\n return body;\n }\n\n // Edit the PR body/title, aborting BEFORE the push if `gh` failed. Warning-and-continuing here would\n // push code that the PR body does not vouch for; aborting leaves the PR on its previous body, whose\n // token is still valid for the sha the remote still has. Nothing is half-done either way.\n private async editPrOrAbort(\n prNumber: string,\n title: string,\n bodyFile: string,\n retryCommand: string,\n ): Promise<void> {\n if (await this.editPr(prNumber, title, bodyFile)) return;\n throw new CliExitError(\n 1,\n `❌ gh pr edit failed on PR #${prNumber} — NOTHING was pushed, so the PR and the remote branch are\\n` +\n ` both unchanged and still consistent. Fix gh (auth / network / permissions) and re-run\\n` +\n ` ${retryCommand}. The new body is in:\\n ${bodyFile}`,\n );\n }\n\n // The open PR whose head is `baseBranch`, or '' when there is none (or `gh` failed — treated the same,\n // so the create path then fails loudly rather than silently editing the wrong PR).\n private async findOpenPr(baseBranch: string): Promise<string> {\n const result = await this.processes.run(\n 'gh',\n ['pr', 'list', '--head', baseBranch, '--json', 'number', '--jq', '.[0].number'],\n );\n return result.ok ? result.stdout.trim() : '';\n }\n\n private async editPr(prNumber: string, title: string, bodyFile: string): Promise<boolean> {\n const result = await this.processes.passThrough(\n 'gh', ['pr', 'edit', prNumber, '--title', title, '--body-file', bodyFile],\n );\n return result.ok;\n }\n\n private async createPr(baseBranch: string, title: string, bodyFile: string): Promise<boolean> {\n return (\n await this.processes.passThrough(\n 'gh',\n [\n 'pr',\n 'create',\n '--head',\n baseBranch,\n '--base',\n 'main',\n '--title',\n title,\n '--body-file',\n bodyFile,\n ],\n )\n ).ok;\n }\n\n // Throws (CliExitError, via runGitChecked) when the push fails — deliberately NOT caught here: the\n // consequence is already printed above, and swallowing it would report a PR that was never updated.\n protected push(baseBranch: string): Promise<void> {\n return this.gitExec.ensurePushed(baseBranch);\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NativeProcessApi } from '@webpieces/tooling-common';
|
|
2
2
|
import { GatedPrPublisher } from './gated-pr-publisher';
|
|
3
3
|
import { GitExec } from './git-exec';
|
|
4
|
+
import { PrNumberPredictor } from './pr-number-predictor';
|
|
4
5
|
/**
|
|
5
6
|
* The gated publisher for a `/hotfix/` branch: the same body-before-push ordering, with a push that can
|
|
6
7
|
* NEVER rewrite the remote branch.
|
|
@@ -15,7 +16,7 @@ import { GitExec } from './git-exec';
|
|
|
15
16
|
*/
|
|
16
17
|
export declare class HotfixPrPublisher extends GatedPrPublisher {
|
|
17
18
|
private readonly hotfixGit;
|
|
18
|
-
constructor(hotfixGit: GitExec, processes: NativeProcessApi);
|
|
19
|
+
constructor(hotfixGit: GitExec, processes: NativeProcessApi, predictor: PrNumberPredictor);
|
|
19
20
|
/** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */
|
|
20
21
|
pushFastForward(cwd: string, branch: string): Promise<void>;
|
|
21
22
|
protected push(baseBranch: string): Promise<void>;
|
|
@@ -7,6 +7,7 @@ const tooling_common_1 = require("@webpieces/tooling-common");
|
|
|
7
7
|
const inversify_1 = require("inversify");
|
|
8
8
|
const gated_pr_publisher_1 = require("./gated-pr-publisher");
|
|
9
9
|
const git_exec_1 = require("./git-exec");
|
|
10
|
+
const pr_number_predictor_1 = require("./pr-number-predictor");
|
|
10
11
|
/**
|
|
11
12
|
* The gated publisher for a `/hotfix/` branch: the same body-before-push ordering, with a push that can
|
|
12
13
|
* NEVER rewrite the remote branch.
|
|
@@ -21,8 +22,8 @@ const git_exec_1 = require("./git-exec");
|
|
|
21
22
|
*/
|
|
22
23
|
let HotfixPrPublisher = class HotfixPrPublisher extends gated_pr_publisher_1.GatedPrPublisher {
|
|
23
24
|
hotfixGit;
|
|
24
|
-
constructor(hotfixGit, processes) {
|
|
25
|
-
super(hotfixGit, processes);
|
|
25
|
+
constructor(hotfixGit, processes, predictor) {
|
|
26
|
+
super(hotfixGit, processes, predictor);
|
|
26
27
|
this.hotfixGit = hotfixGit;
|
|
27
28
|
}
|
|
28
29
|
/** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */
|
|
@@ -42,6 +43,6 @@ let HotfixPrPublisher = class HotfixPrPublisher extends gated_pr_publisher_1.Gat
|
|
|
42
43
|
exports.HotfixPrPublisher = HotfixPrPublisher;
|
|
43
44
|
exports.HotfixPrPublisher = HotfixPrPublisher = tslib_1.__decorate([
|
|
44
45
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
45
|
-
tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec, tooling_common_1.NativeProcessApi])
|
|
46
|
+
tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec, tooling_common_1.NativeProcessApi, pr_number_predictor_1.PrNumberPredictor])
|
|
46
47
|
], HotfixPrPublisher);
|
|
47
48
|
//# sourceMappingURL=hotfix-pr-publisher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hotfix-pr-publisher.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-pr-publisher.ts"],"names":[],"mappings":";;;;AAAA,0DAAuD;AACvD,8DAA6D;AAC7D,yCAA2D;AAC3D,6DAAwD;AACxD,yCAAqC;
|
|
1
|
+
{"version":3,"file":"hotfix-pr-publisher.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-pr-publisher.ts"],"names":[],"mappings":";;;;AAAA,0DAAuD;AACvD,8DAA6D;AAC7D,yCAA2D;AAC3D,6DAAwD;AACxD,yCAAqC;AACrC,+DAA0D;AAE1D;;;;;;;;;;;GAWG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,qCAAgB;IACtB;IAA7B,YAA6B,SAAkB,EAAE,SAA2B,EAAE,SAA4B;QACtG,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;QADd,cAAS,GAAT,SAAS,CAAS;IAE/C,CAAC;IAED,8FAA8F;IAC9F,KAAK,CAAC,eAAe,CAAC,GAAW,EAAE,MAAc;QAC7C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;QACzF,IAAI,GAAG,CAAC,EAAE;YAAE,OAAO;QACnB,MAAM,IAAI,2BAAY,CAClB,CAAC,EACD,oCAAoC,MAAM,kBAAkB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,uBAAuB;YACjG,mGAAmG;YACnG,wBAAwB;YACxB,gBAAgB,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CACrE,CAAC;IACN,CAAC;IAEkB,IAAI,CAAC,UAAkB;QACtC,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AArBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEG,kBAAO,EAAa,iCAAgB,EAAa,uCAAiB;GADjG,iBAAiB,CAqB7B","sourcesContent":["import { CliExitError } from '@webpieces/rules-config';\nimport { NativeProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { GatedPrPublisher } from './gated-pr-publisher';\nimport { GitExec } from './git-exec';\nimport { PrNumberPredictor } from './pr-number-predictor';\n\n/**\n * The gated publisher for a `/hotfix/` branch: the same body-before-push ordering, with a push that can\n * NEVER rewrite the remote branch.\n *\n * The normal flow pushes with `--force-with-lease`, because its 3-point squash rewrites history on every\n * update. A hotfix branch is never rewritten — it only ever grows by the fix commits added on top of the\n * production sha — so its push is a plain fast-forward. If the remote branch has diverged (somebody else\n * pushed to it), the push FAILS instead of overwriting their commits, and nothing is lost.\n *\n * The push runs as a CHILD PROCESS of `wp-upsert-hotfix-pr`, which the PreToolUse hook never sees, so\n * `pr-creation-or-push-guard` keeps refusing every hand-typed `git push` exactly as before.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class HotfixPrPublisher extends GatedPrPublisher {\n constructor(private readonly hotfixGit: GitExec, processes: NativeProcessApi, predictor: PrNumberPredictor) {\n super(hotfixGit, processes, predictor);\n }\n\n /** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */\n async pushFastForward(cwd: string, branch: string): Promise<void> {\n const out = await this.hotfixGit.tryGit(['push', '-u', 'origin', `HEAD:${branch}`], cwd);\n if (out.ok) return;\n throw new CliExitError(\n 1,\n `❌ git push of the hotfix branch '${branch}' failed (exit ${String(out.status)}). A hotfix push is\\n` +\n ' fast-forward only — it never forces — so a remote branch that has diverged is refused rather\\n' +\n ' than overwritten.\\n' +\n ` git said: ${out.stderr === '' ? '(nothing)' : out.stderr}`,\n );\n }\n\n protected override push(baseBranch: string): Promise<void> {\n return this.pushFastForward(process.cwd(), baseBranch);\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NativeProcessApi } from '@webpieces/tooling-common';
|
|
2
|
+
export declare class PredictedPr {
|
|
3
|
+
number: string;
|
|
4
|
+
url: string;
|
|
5
|
+
constructor(number: string, url: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Predicts the number GitHub will assign to the PR about to be created (issue #1418), so its description
|
|
9
|
+
* can carry its own link the FIRST time it goes up. Without it, creating a PR fires `opened` and then,
|
|
10
|
+
* two seconds later, `edited` (the self-link back-fill) — and a consumer workflow with
|
|
11
|
+
* `cancel-in-progress` cancels the `opened` run on every new PR.
|
|
12
|
+
*
|
|
13
|
+
* A number cannot be reserved, only predicted, so the caller always compares the prediction with the
|
|
14
|
+
* number GitHub really assigned and back-fills on a miss — exactly today's behaviour, never worse.
|
|
15
|
+
*
|
|
16
|
+
* A failed query (network, permissions, a GitHub Enterprise Server without discussions) is NOT a failure
|
|
17
|
+
* of the run: the prediction is simply absent, the caller creates the PR without its own link and
|
|
18
|
+
* back-fills it afterwards. The warning says so, because the cost is one extra `edited` event.
|
|
19
|
+
*/
|
|
20
|
+
export declare class PrNumberPredictor {
|
|
21
|
+
private readonly processes;
|
|
22
|
+
constructor(processes: NativeProcessApi);
|
|
23
|
+
predict(): Promise<PredictedPr>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrNumberPredictor = exports.PredictedPr = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
|
+
const inversify_1 = require("inversify");
|
|
7
|
+
// The number and web URL GitHub will most likely assign to the next PR. Both '' when no prediction
|
|
8
|
+
// could be made. Data-only.
|
|
9
|
+
class PredictedPr {
|
|
10
|
+
number;
|
|
11
|
+
url;
|
|
12
|
+
constructor(number, url) {
|
|
13
|
+
this.number = number;
|
|
14
|
+
this.url = url;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.PredictedPr = PredictedPr;
|
|
18
|
+
/*
|
|
19
|
+
* Issues, PRs and discussions share ONE per-repo number counter, so the newest of the three, plus one, is
|
|
20
|
+
* the number the next PR gets unless something else is created in the same few seconds. Each connection
|
|
21
|
+
* is ordered explicitly (newest first) rather than relying on a connection's default order.
|
|
22
|
+
*/
|
|
23
|
+
const PREDICT_QUERY = 'query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { url ' +
|
|
24
|
+
'issues(first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { number } } ' +
|
|
25
|
+
'pullRequests(first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { number } } ' +
|
|
26
|
+
'discussions(first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { number } } } }';
|
|
27
|
+
// The newest number of the three (0 for an empty repo) and the repo's web URL, as one tab-separated line,
|
|
28
|
+
// so nothing here parses JSON. A connection with no nodes contributes nothing.
|
|
29
|
+
const PREDICT_JQ = '"\\(([.data.repository.issues.nodes[0].number, .data.repository.pullRequests.nodes[0].number, ' +
|
|
30
|
+
'.data.repository.discussions.nodes[0].number] | map(select(. != null)) + [0]) | max)\\t\\(.data.repository.url)"';
|
|
31
|
+
/**
|
|
32
|
+
* Predicts the number GitHub will assign to the PR about to be created (issue #1418), so its description
|
|
33
|
+
* can carry its own link the FIRST time it goes up. Without it, creating a PR fires `opened` and then,
|
|
34
|
+
* two seconds later, `edited` (the self-link back-fill) — and a consumer workflow with
|
|
35
|
+
* `cancel-in-progress` cancels the `opened` run on every new PR.
|
|
36
|
+
*
|
|
37
|
+
* A number cannot be reserved, only predicted, so the caller always compares the prediction with the
|
|
38
|
+
* number GitHub really assigned and back-fills on a miss — exactly today's behaviour, never worse.
|
|
39
|
+
*
|
|
40
|
+
* A failed query (network, permissions, a GitHub Enterprise Server without discussions) is NOT a failure
|
|
41
|
+
* of the run: the prediction is simply absent, the caller creates the PR without its own link and
|
|
42
|
+
* back-fills it afterwards. The warning says so, because the cost is one extra `edited` event.
|
|
43
|
+
*/
|
|
44
|
+
let PrNumberPredictor = class PrNumberPredictor {
|
|
45
|
+
processes;
|
|
46
|
+
constructor(processes) {
|
|
47
|
+
this.processes = processes;
|
|
48
|
+
}
|
|
49
|
+
async predict() {
|
|
50
|
+
const result = await this.processes.run('gh', [
|
|
51
|
+
'api',
|
|
52
|
+
'graphql',
|
|
53
|
+
'-F',
|
|
54
|
+
'owner={owner}',
|
|
55
|
+
'-F',
|
|
56
|
+
'name={repo}',
|
|
57
|
+
'-f',
|
|
58
|
+
`query=${PREDICT_QUERY}`,
|
|
59
|
+
'--jq',
|
|
60
|
+
PREDICT_JQ,
|
|
61
|
+
]);
|
|
62
|
+
const parts = result.ok ? result.stdout.trim().split('\t') : [];
|
|
63
|
+
const latest = parts[0] ?? '';
|
|
64
|
+
const repoUrl = parts[1] ?? '';
|
|
65
|
+
if (!/^\d+$/.test(latest) || !repoUrl.startsWith('http')) {
|
|
66
|
+
const why = result.ok ? `unexpected answer '${result.stdout.trim()}'` : (result.stderr.trim() || `exit ${String(result.code)}`);
|
|
67
|
+
process.stderr.write(`⚠️ Could not predict the new PR's number (${why}). Creating it without its own link and\n` +
|
|
68
|
+
" back-filling the link afterwards (one extra 'edited' event).\n");
|
|
69
|
+
return new PredictedPr('', '');
|
|
70
|
+
}
|
|
71
|
+
const next = String(Number(latest) + 1);
|
|
72
|
+
return new PredictedPr(next, `${repoUrl}/pull/${next}`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.PrNumberPredictor = PrNumberPredictor;
|
|
76
|
+
exports.PrNumberPredictor = PrNumberPredictor = tslib_1.__decorate([
|
|
77
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
78
|
+
tslib_1.__metadata("design:paramtypes", [tooling_common_1.NativeProcessApi])
|
|
79
|
+
], PrNumberPredictor);
|
|
80
|
+
//# sourceMappingURL=pr-number-predictor.js.map
|