@webpieces/pr-gate 0.4.453 → 0.4.455
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/scripts/commands/finish-upsert-pr-command.js +4 -1
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/land-pr-command.d.ts +28 -0
- package/src/scripts/commands/land-pr-command.js +107 -0
- package/src/scripts/commands/land-pr-command.js.map +1 -0
- package/src/scripts/pr-gate-app.d.ts +7 -3
- package/src/scripts/pr-gate-app.js +12 -4
- package/src/scripts/pr-gate-app.js.map +1 -1
- package/src/scripts/workflow/pr-merger.d.ts +9 -1
- package/src/scripts/workflow/pr-merger.js +25 -7
- package/src/scripts/workflow/pr-merger.js.map +1 -1
- package/src/scripts/wp-land-pr.d.ts +2 -0
- package/src/scripts/wp-land-pr.js +16 -0
- package/src/scripts/wp-land-pr.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/pr-gate",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.455",
|
|
4
4
|
"description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"wp-start-upsert-pr": "./src/scripts/wp-start-upsert-pr.js",
|
|
10
10
|
"wp-start-update": "./src/scripts/wp-start-update.js",
|
|
11
11
|
"wp-finish-update": "./src/scripts/wp-finish-update.js",
|
|
12
|
-
"wp-cleanup": "./src/scripts/wp-cleanup.js"
|
|
12
|
+
"wp-cleanup": "./src/scripts/wp-cleanup.js",
|
|
13
|
+
"wp-land-pr": "./src/scripts/wp-land-pr.js"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"src/**/*"
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
"directory": "packages/tooling/pr-gate"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@webpieces/rules-config": "0.4.
|
|
26
|
+
"@webpieces/rules-config": "0.4.455",
|
|
26
27
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
27
28
|
"inversify": "7.10.4",
|
|
28
29
|
"reflect-metadata": "0.2.2"
|
|
@@ -150,7 +150,10 @@ let FinishUpsertPrCommand = class FinishUpsertPrCommand {
|
|
|
150
150
|
fs.writeFileSync(mergeBodyFile, this.dashboard.renderCommitBody(input, ref.url) + '\n');
|
|
151
151
|
// PrMerger owns the direct-merge / auto-merge-fallback decision AND checks every gh status, so a
|
|
152
152
|
// merge that did not happen is reported as such instead of being swallowed (see pr-merger.ts).
|
|
153
|
-
|
|
153
|
+
// REQUIRED config — no default here on purpose. A missing value (an older published
|
|
154
|
+
// rules-config that has no such field) reaches PrMerger as '' and is treated as "do not merge".
|
|
155
|
+
const mergeMode = (0, rules_config_1.loadAndValidate)(repoRoot).prGate.mergeMode ?? '';
|
|
156
|
+
const outcome = this.prMerger.merge(baseBranch, subject, mergeBodyFile, mergeMode);
|
|
154
157
|
return new UpsertResult(ref.number !== '' ? ref.number : num, outcome);
|
|
155
158
|
}
|
|
156
159
|
// The PR's number + web URL (for the merge subject `(#N)` and the commit-body back-link). Both ''
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finish-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/finish-upsert-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAEiC;AACjC,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,mDAA+C;AAC/C,+DAA6E;AAC7E,yDAAqD;AACrD,qDAAiD;AACjD,yDAAuD;AACvD,qDAA+D;AAC/D,yDAAsE;AAEtE,MAAM,GAA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ync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n loadAndValidate, loadReviewJson, prDirFor, reviewJsonPath, ReviewJson, writeTemplate, RepoRootFinder,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { GitExec } from '../workflow/git-exec';\nimport { BuildAffected, BuildGateOptions } from '../workflow/build-affected';\nimport { MergeState } from '../workflow/merge-state';\nimport { MergeEnd } from '../workflow/merge-end';\nimport { MergeContext } from '../workflow/merge-start';\nimport { PrMerger, MergeOutcome } from '../workflow/pr-merger';\nimport { Dashboard, DashboardInput } from '../../dashboard/dashboard';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// A resolved PR's number + web URL. Both '' when the PR can't be resolved (e.g. create failed).\nclass PrRef {\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// The outcome of the whole upsert: the PR number ('' when it could not be resolved) plus what actually\n// happened to the merge, so the final summary reports the REAL result rather than assuming success.\nclass UpsertResult {\n prNumber: string;\n merge: MergeOutcome;\n\n constructor(prNumber: string, merge: MergeOutcome) {\n this.prNumber = prNumber;\n this.merge = merge;\n }\n}\n\n// FINISH of the AI-first PR flow. Runs after the AI wrote review.json. In order: (1) if a 3-point merge\n// was in progress, validate + commit + FINALIZE via merge-END; (2) REQUIRE review.json; (3) run the\n// authoritative build gate; (4) render the dashboard; (5) create/update the PR via `gh`. The ONLY\n// command that posts PRs.\n@injectable(bindingScopeValues.Singleton)\nexport class FinishUpsertPrCommand {\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 buildAffected: BuildAffected,\n private readonly mergeState: MergeState,\n private readonly mergeEnd: MergeEnd,\n private readonly prMerger: PrMerger,\n private readonly dashboard: Dashboard,\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 const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n\n // 1. Finish any in-progress conflict resolution: validate + commit + finalize the branch swap.\n const activeDir = this.mergeState.findActiveMergeRunDir(home);\n const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;\n if (activeDir && marker && !marker.validated) {\n await this.mergeEnd.mergeEnd(\n repoRoot, 'wp-finish-upsert-pr', activeDir,\n new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber),\n marker.conflictedFiles,\n );\n }\n\n // 2. REQUIRE the AI-authored review.json (throws InformAiError with the schema if missing/invalid).\n const review = loadReviewJson(reviewJsonPath(repoRoot, this.aiBranchName.getFeatureName()));\n\n // 2b. The build gate validates the WORKING TREE but we push HEAD — so they MUST be identical.\n this.gitExec.assertCleanTree(repoRoot);\n\n // 3. Authoritative build gate, then push, then post.\n this.buildAffected.runBuildGate(repoRoot, new BuildGateOptions(\n '🛠️ Build gate (authoritative)', 'pnpm wp-finish-upsert-pr', 'Build failed — no PR created/updated.',\n ));\n const base = this.branchNaming.baseBranchName(execSync('git branch --show-current', { encoding: 'utf8' }).trim());\n this.gitExec.ensurePushed(base);\n\n process.stdout.write('\\n' + SEP + '📋 Dashboard + PR\\n' + SEP + '\\n');\n const title = this.prTitleFrom(review);\n const input = this.computeDashboardInput(repoRoot, true, review, title);\n const body = this.dashboard.renderDashboard(input);\n const result = this.upsertPr(repoRoot, base, body, title, input);\n const prNum = result.prNumber;\n\n process.stdout.write(\n '\\n' + SEP + '✅ PR finished — here is exactly what I did\\n' + SEP + '\\n' +\n ` 1. validated the build gate (authoritative)\\n` +\n ` 2. force-pushed your work to origin/${base}\\n` +\n ` 3. ${prNum ? `updated/created PR #${prNum}` : 'created the PR'} titled: \"${title}\"\\n` +\n ` 4. ${result.merge.message}\\n` +\n ` You are on ${base} — same name as the remote branch and the PR head.\\n\\n`,\n );\n }\n\n private gitOut(args: string[]): string {\n const result = spawnSync('git', args, { encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n\n // The user-facing PR title: the AI-authored review.title, or — if omitted — a readable fallback\n // derived from the stable feature name (NEVER the internal `Squash merge of <branch>` commit subject).\n private prTitleFrom(review: ReviewJson): string {\n if (review.title !== '') return review.title;\n return this.aiBranchName.getFeatureName().replace(/[-/]+/g, ' ').trim();\n }\n\n private computeDashboardInput(repoRoot: string, buildPassed: boolean, review: ReviewJson, title: string): DashboardInput {\n const config = loadAndValidate(repoRoot).prGate;\n const forkPoint = this.gitOut(['merge-base', 'origin/main', 'HEAD']);\n const featureHead = this.gitOut(['rev-parse', 'HEAD']);\n const mainHead = this.gitOut(['rev-parse', 'origin/main']);\n const range = `${forkPoint}..${featureHead}`;\n const changedFiles = this.gitOut(['diff', range, '--name-only']).split('\\n').filter((f: string): boolean => f.trim() !== '');\n const patch = this.gitOut(['diff', range]);\n\n const gateResults = this.dashboard.computeGateResults(config.gates, changedFiles);\n const disables = this.dashboard.countAddedDisables(patch);\n return new DashboardInput(title, gateResults, disables, buildPassed, forkPoint, featureHead, mainHead, review);\n }\n\n // The PR, the remote branch, and the local branch all share the one stable feature name. Look up /\n // create / merge against `baseBranch` (baseBranchName tolerates a leftover `…wpN` mid-transition).\n private upsertPr(repoRoot: string, baseBranch: string, body: string, title: string, input: DashboardInput): UpsertResult {\n const prDir = prDirFor(repoRoot, this.aiBranchName.getFeatureName());\n fs.mkdirSync(prDir, { recursive: true });\n const bodyFile = path.join(prDir, 'pr-body.md');\n fs.writeFileSync(bodyFile, body + '\\n');\n\n const prNumber = spawnSync(\n 'gh', ['pr', 'list', '--head', baseBranch, '--json', 'number', '--jq', '.[0].number'],\n { encoding: 'utf8' },\n );\n const num = prNumber.status === 0 ? (prNumber.stdout ?? '').trim() : '';\n\n if (num === '') {\n process.stdout.write('Creating PR...\\n');\n const create = spawnSync('gh', ['pr', 'create', '--head', baseBranch, '--base', 'main', '--title', title, '--body-file', bodyFile], { stdio: 'inherit' });\n if (create.status !== 0) {\n process.stderr.write('⚠️ gh pr create failed — create the PR manually with the body in:\\n ' + bodyFile + '\\n');\n return new UpsertResult('', new MergeOutcome(false, false,\n '⚠️ did NOT merge — there is no PR to merge (gh pr create failed above)'));\n }\n } else {\n process.stdout.write(`Updating PR #${num}...\\n`);\n const edit = spawnSync('gh', ['pr', 'edit', num, '--title', title, '--body-file', bodyFile], { stdio: 'inherit' });\n if (edit.status !== 0) {\n process.stderr.write(`⚠️ gh pr edit failed — PR #${num} still shows its OLD title/body. The new body is in:\\n ` + bodyFile + '\\n');\n }\n }\n\n // Set the squash-merge SUBJECT to the PR title (+ the `(#N)` GitHub normally appends, which an\n // explicit --subject would otherwise drop) and the BODY to the compact commit summary, so main's\n // history carries the PR title + risk/flags/link — NOT the internal `Squash merge of <branch>`\n // subject GitHub would inherit from the single squash commit on the branch.\n const ref = this.prRef(baseBranch);\n const subject = ref.number !== '' ? `${title} (#${ref.number})` : title;\n const mergeBodyFile = path.join(prDir, 'merge-commit-body.md');\n fs.writeFileSync(mergeBodyFile, this.dashboard.renderCommitBody(input, ref.url) + '\\n');\n // PrMerger owns the direct-merge / auto-merge-fallback decision AND checks every gh status, so a\n // merge that did not happen is reported as such instead of being swallowed (see pr-merger.ts).\n const outcome = this.prMerger.merge(baseBranch, subject, mergeBodyFile);\n return new UpsertResult(ref.number !== '' ? ref.number : num, outcome);\n }\n\n // The PR's number + web URL (for the merge subject `(#N)` and the commit-body back-link). Both ''\n // if it can't be resolved. Rendered via jq into one tab-separated line so no JSON parsing is needed.\n private prRef(baseBranch: string): PrRef {\n const result = spawnSync(\n 'gh', ['pr', 'view', baseBranch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) {\n return new PrRef('', '');\n }\n const parts = (result.stdout ?? '').trim().split('\\t');\n return new PrRef(parts[0] ?? '', parts[1] ?? '');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"finish-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/finish-upsert-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAEiC;AACjC,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,mDAA+C;AAC/C,+DAA6E;AAC7E,yDAAqD;AACrD,qDAAiD;AACjD,yDAAuD;AACvD,qDAA+D;AAC/D,yDAAsE;AAEtE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,gGAAgG;AAChG,MAAM,KAAK;IACP,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;AAED,uGAAuG;AACvG,oGAAoG;AACpG,MAAM,YAAY;IACd,QAAQ,CAAS;IACjB,KAAK,CAAe;IAEpB,YAAY,QAAgB,EAAE,KAAmB;QAC7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAED,wGAAwG;AACxG,oGAAoG;AACpG,kGAAkG;AAClG,0BAA0B;AAEnB,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAET;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IATrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,OAAgB,EAChB,aAA4B,EAC5B,UAAsB,EACtB,QAAkB,EAClB,QAAkB,EAClB,SAAoB;QAR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M,EAAE,CACvB,CAAC;QACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,IAAI,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC7B,CAAC;QACD,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACvD,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACrD,CAAC;CACJ,CAAA;AAlJY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACZ,4BAAY;QACjB,kBAAO;QACD,8BAAa;QAChB,wBAAU;QACZ,oBAAQ;QACR,oBAAQ;QACP,qBAAS;GAVhC,qBAAqB,CAkJjC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n loadAndValidate, loadReviewJson, prDirFor, reviewJsonPath, ReviewJson, writeTemplate, RepoRootFinder,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { GitExec } from '../workflow/git-exec';\nimport { BuildAffected, BuildGateOptions } from '../workflow/build-affected';\nimport { MergeState } from '../workflow/merge-state';\nimport { MergeEnd } from '../workflow/merge-end';\nimport { MergeContext } from '../workflow/merge-start';\nimport { PrMerger, MergeOutcome } from '../workflow/pr-merger';\nimport { Dashboard, DashboardInput } from '../../dashboard/dashboard';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// A resolved PR's number + web URL. Both '' when the PR can't be resolved (e.g. create failed).\nclass PrRef {\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// The outcome of the whole upsert: the PR number ('' when it could not be resolved) plus what actually\n// happened to the merge, so the final summary reports the REAL result rather than assuming success.\nclass UpsertResult {\n prNumber: string;\n merge: MergeOutcome;\n\n constructor(prNumber: string, merge: MergeOutcome) {\n this.prNumber = prNumber;\n this.merge = merge;\n }\n}\n\n// FINISH of the AI-first PR flow. Runs after the AI wrote review.json. In order: (1) if a 3-point merge\n// was in progress, validate + commit + FINALIZE via merge-END; (2) REQUIRE review.json; (3) run the\n// authoritative build gate; (4) render the dashboard; (5) create/update the PR via `gh`. The ONLY\n// command that posts PRs.\n@injectable(bindingScopeValues.Singleton)\nexport class FinishUpsertPrCommand {\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 buildAffected: BuildAffected,\n private readonly mergeState: MergeState,\n private readonly mergeEnd: MergeEnd,\n private readonly prMerger: PrMerger,\n private readonly dashboard: Dashboard,\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 const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n\n // 1. Finish any in-progress conflict resolution: validate + commit + finalize the branch swap.\n const activeDir = this.mergeState.findActiveMergeRunDir(home);\n const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;\n if (activeDir && marker && !marker.validated) {\n await this.mergeEnd.mergeEnd(\n repoRoot, 'wp-finish-upsert-pr', activeDir,\n new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber),\n marker.conflictedFiles,\n );\n }\n\n // 2. REQUIRE the AI-authored review.json (throws InformAiError with the schema if missing/invalid).\n const review = loadReviewJson(reviewJsonPath(repoRoot, this.aiBranchName.getFeatureName()));\n\n // 2b. The build gate validates the WORKING TREE but we push HEAD — so they MUST be identical.\n this.gitExec.assertCleanTree(repoRoot);\n\n // 3. Authoritative build gate, then push, then post.\n this.buildAffected.runBuildGate(repoRoot, new BuildGateOptions(\n '🛠️ Build gate (authoritative)', 'pnpm wp-finish-upsert-pr', 'Build failed — no PR created/updated.',\n ));\n const base = this.branchNaming.baseBranchName(execSync('git branch --show-current', { encoding: 'utf8' }).trim());\n this.gitExec.ensurePushed(base);\n\n process.stdout.write('\\n' + SEP + '📋 Dashboard + PR\\n' + SEP + '\\n');\n const title = this.prTitleFrom(review);\n const input = this.computeDashboardInput(repoRoot, true, review, title);\n const body = this.dashboard.renderDashboard(input);\n const result = this.upsertPr(repoRoot, base, body, title, input);\n const prNum = result.prNumber;\n\n process.stdout.write(\n '\\n' + SEP + '✅ PR finished — here is exactly what I did\\n' + SEP + '\\n' +\n ` 1. validated the build gate (authoritative)\\n` +\n ` 2. force-pushed your work to origin/${base}\\n` +\n ` 3. ${prNum ? `updated/created PR #${prNum}` : 'created the PR'} titled: \"${title}\"\\n` +\n ` 4. ${result.merge.message}\\n` +\n ` You are on ${base} — same name as the remote branch and the PR head.\\n\\n`,\n );\n }\n\n private gitOut(args: string[]): string {\n const result = spawnSync('git', args, { encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n\n // The user-facing PR title: the AI-authored review.title, or — if omitted — a readable fallback\n // derived from the stable feature name (NEVER the internal `Squash merge of <branch>` commit subject).\n private prTitleFrom(review: ReviewJson): string {\n if (review.title !== '') return review.title;\n return this.aiBranchName.getFeatureName().replace(/[-/]+/g, ' ').trim();\n }\n\n private computeDashboardInput(repoRoot: string, buildPassed: boolean, review: ReviewJson, title: string): DashboardInput {\n const config = loadAndValidate(repoRoot).prGate;\n const forkPoint = this.gitOut(['merge-base', 'origin/main', 'HEAD']);\n const featureHead = this.gitOut(['rev-parse', 'HEAD']);\n const mainHead = this.gitOut(['rev-parse', 'origin/main']);\n const range = `${forkPoint}..${featureHead}`;\n const changedFiles = this.gitOut(['diff', range, '--name-only']).split('\\n').filter((f: string): boolean => f.trim() !== '');\n const patch = this.gitOut(['diff', range]);\n\n const gateResults = this.dashboard.computeGateResults(config.gates, changedFiles);\n const disables = this.dashboard.countAddedDisables(patch);\n return new DashboardInput(title, gateResults, disables, buildPassed, forkPoint, featureHead, mainHead, review);\n }\n\n // The PR, the remote branch, and the local branch all share the one stable feature name. Look up /\n // create / merge against `baseBranch` (baseBranchName tolerates a leftover `…wpN` mid-transition).\n private upsertPr(repoRoot: string, baseBranch: string, body: string, title: string, input: DashboardInput): UpsertResult {\n const prDir = prDirFor(repoRoot, this.aiBranchName.getFeatureName());\n fs.mkdirSync(prDir, { recursive: true });\n const bodyFile = path.join(prDir, 'pr-body.md');\n fs.writeFileSync(bodyFile, body + '\\n');\n\n const prNumber = spawnSync(\n 'gh', ['pr', 'list', '--head', baseBranch, '--json', 'number', '--jq', '.[0].number'],\n { encoding: 'utf8' },\n );\n const num = prNumber.status === 0 ? (prNumber.stdout ?? '').trim() : '';\n\n if (num === '') {\n process.stdout.write('Creating PR...\\n');\n const create = spawnSync('gh', ['pr', 'create', '--head', baseBranch, '--base', 'main', '--title', title, '--body-file', bodyFile], { stdio: 'inherit' });\n if (create.status !== 0) {\n process.stderr.write('⚠️ gh pr create failed — create the PR manually with the body in:\\n ' + bodyFile + '\\n');\n return new UpsertResult('', new MergeOutcome(false, false,\n '⚠️ did NOT merge — there is no PR to merge (gh pr create failed above)'));\n }\n } else {\n process.stdout.write(`Updating PR #${num}...\\n`);\n const edit = spawnSync('gh', ['pr', 'edit', num, '--title', title, '--body-file', bodyFile], { stdio: 'inherit' });\n if (edit.status !== 0) {\n process.stderr.write(`⚠️ gh pr edit failed — PR #${num} still shows its OLD title/body. The new body is in:\\n ` + bodyFile + '\\n');\n }\n }\n\n // Set the squash-merge SUBJECT to the PR title (+ the `(#N)` GitHub normally appends, which an\n // explicit --subject would otherwise drop) and the BODY to the compact commit summary, so main's\n // history carries the PR title + risk/flags/link — NOT the internal `Squash merge of <branch>`\n // subject GitHub would inherit from the single squash commit on the branch.\n const ref = this.prRef(baseBranch);\n const subject = ref.number !== '' ? `${title} (#${ref.number})` : title;\n const mergeBodyFile = path.join(prDir, 'merge-commit-body.md');\n fs.writeFileSync(mergeBodyFile, this.dashboard.renderCommitBody(input, ref.url) + '\\n');\n // PrMerger owns the direct-merge / auto-merge-fallback decision AND checks every gh status, so a\n // merge that did not happen is reported as such instead of being swallowed (see pr-merger.ts).\n // REQUIRED config — no default here on purpose. A missing value (an older published\n // rules-config that has no such field) reaches PrMerger as '' and is treated as \"do not merge\".\n const mergeMode = loadAndValidate(repoRoot).prGate.mergeMode ?? '';\n const outcome = this.prMerger.merge(baseBranch, subject, mergeBodyFile, mergeMode);\n return new UpsertResult(ref.number !== '' ? ref.number : num, outcome);\n }\n\n // The PR's number + web URL (for the merge subject `(#N)` and the commit-body back-link). Both ''\n // if it can't be resolved. Rendered via jq into one tab-separated line so no JSON parsing is needed.\n private prRef(baseBranch: string): PrRef {\n const result = spawnSync(\n 'gh', ['pr', 'view', baseBranch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) {\n return new PrRef('', '');\n }\n const parts = (result.stdout ?? '').trim().split('\\t');\n return new PrRef(parts[0] ?? '', parts[1] ?? '');\n }\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RepoRootFinder } from '@webpieces/rules-config';
|
|
2
|
+
import { AiBranchName } from '../workflow/git-readAiBranchName';
|
|
3
|
+
import { BranchNaming } from '../workflow/branch-naming';
|
|
4
|
+
import { PrMerger } from '../workflow/pr-merger';
|
|
5
|
+
/**
|
|
6
|
+
* `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.
|
|
7
|
+
*
|
|
8
|
+
* It exists because a merge clicked in the GitHub UI cannot produce that body. A UI merge is limited
|
|
9
|
+
* to the repo's squash_merge_commit_title/message settings, and none of their values yields the
|
|
10
|
+
* shortened risk/flags summary — only an explicit `gh pr merge --subject --body-file` does. So when a
|
|
11
|
+
* merge has to happen outside `wp-finish-upsert-pr` (a mergeMode=NONE repo, or a PR whose checks were
|
|
12
|
+
* still running when finish ran), this is the command that keeps main's history consistent.
|
|
13
|
+
*
|
|
14
|
+
* It deliberately does NOT re-run the build gate or re-render the dashboard: `wp-finish-upsert-pr`
|
|
15
|
+
* already did both and left `merge-commit-body.md` on disk. Landing is a separate, later act, and
|
|
16
|
+
* rebuilding here would mean a second authoritative gate whose result nobody reads. If that file is
|
|
17
|
+
* missing, the honest answer is that finish has not run — so this fails and says so, rather than
|
|
18
|
+
* inventing a body that would not match the PR.
|
|
19
|
+
*/
|
|
20
|
+
export declare class LandPrCommand {
|
|
21
|
+
private readonly repoRootFinder;
|
|
22
|
+
private readonly aiBranchName;
|
|
23
|
+
private readonly branchNaming;
|
|
24
|
+
private readonly prMerger;
|
|
25
|
+
constructor(repoRootFinder: RepoRootFinder, aiBranchName: AiBranchName, branchNaming: BranchNaming, prMerger: PrMerger);
|
|
26
|
+
run(): Promise<void>;
|
|
27
|
+
private prNumberAndTitle;
|
|
28
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LandPrCommand = 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 branch_naming_1 = require("../workflow/branch-naming");
|
|
12
|
+
const pr_merger_1 = require("../workflow/pr-merger");
|
|
13
|
+
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
14
|
+
/**
|
|
15
|
+
* `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.
|
|
16
|
+
*
|
|
17
|
+
* It exists because a merge clicked in the GitHub UI cannot produce that body. A UI merge is limited
|
|
18
|
+
* to the repo's squash_merge_commit_title/message settings, and none of their values yields the
|
|
19
|
+
* shortened risk/flags summary — only an explicit `gh pr merge --subject --body-file` does. So when a
|
|
20
|
+
* merge has to happen outside `wp-finish-upsert-pr` (a mergeMode=NONE repo, or a PR whose checks were
|
|
21
|
+
* still running when finish ran), this is the command that keeps main's history consistent.
|
|
22
|
+
*
|
|
23
|
+
* It deliberately does NOT re-run the build gate or re-render the dashboard: `wp-finish-upsert-pr`
|
|
24
|
+
* already did both and left `merge-commit-body.md` on disk. Landing is a separate, later act, and
|
|
25
|
+
* rebuilding here would mean a second authoritative gate whose result nobody reads. If that file is
|
|
26
|
+
* missing, the honest answer is that finish has not run — so this fails and says so, rather than
|
|
27
|
+
* inventing a body that would not match the PR.
|
|
28
|
+
*/
|
|
29
|
+
let LandPrCommand = class LandPrCommand {
|
|
30
|
+
repoRootFinder;
|
|
31
|
+
aiBranchName;
|
|
32
|
+
branchNaming;
|
|
33
|
+
prMerger;
|
|
34
|
+
constructor(repoRootFinder, aiBranchName, branchNaming, prMerger) {
|
|
35
|
+
this.repoRootFinder = repoRootFinder;
|
|
36
|
+
this.aiBranchName = aiBranchName;
|
|
37
|
+
this.branchNaming = branchNaming;
|
|
38
|
+
this.prMerger = prMerger;
|
|
39
|
+
}
|
|
40
|
+
async run() {
|
|
41
|
+
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
42
|
+
const base = this.branchNaming.baseBranchName((0, child_process_1.execSync)('git branch --show-current', { encoding: 'utf8' }).trim());
|
|
43
|
+
const prDir = (0, rules_config_1.prDirFor)(repoRoot, this.aiBranchName.getFeatureName());
|
|
44
|
+
const mergeBodyFile = path.join(prDir, 'merge-commit-body.md');
|
|
45
|
+
if (!fs.existsSync(mergeBodyFile)) {
|
|
46
|
+
throw new rules_config_1.InformAiError('\n' + SEP + '❌ Nothing to land — no rendered merge body\n' + SEP + '\n' +
|
|
47
|
+
`Expected the compact squash-commit body at:\n ${mergeBodyFile}\n\n` +
|
|
48
|
+
'That file is written by `pnpm wp-finish-upsert-pr`, which is also what posts the PR.\n' +
|
|
49
|
+
'Its absence means finish has not run on this branch, so there is no reviewed PR to\n' +
|
|
50
|
+
'land. Run the gated flow first:\n\n' +
|
|
51
|
+
' pnpm wp-start-upsert-pr # update from main, push, build gate\n' +
|
|
52
|
+
' # write .webpieces/review.json\n' +
|
|
53
|
+
' pnpm wp-finish-upsert-pr # build gate, dashboard, create/update the PR\n\n' +
|
|
54
|
+
'Then re-run `pnpm wp-land-pr` if the PR still needs landing.\n' + SEP);
|
|
55
|
+
}
|
|
56
|
+
const ref = this.prNumberAndTitle(base);
|
|
57
|
+
if (ref === null) {
|
|
58
|
+
throw new rules_config_1.InformAiError('\n' + SEP + '❌ No open PR found for this branch\n' + SEP + '\n' +
|
|
59
|
+
`No open PR has head branch "${base}". Nothing to land.\n` +
|
|
60
|
+
'If the PR is already merged, run `pnpm wp-cleanup`.\n' + SEP);
|
|
61
|
+
}
|
|
62
|
+
process.stdout.write('\n' + SEP + `🚀 Landing PR #${ref.number}\n` + SEP + '\n');
|
|
63
|
+
// Reuse the SAME merge logic wp-finish-upsert-pr uses, so a PR lands identically whichever
|
|
64
|
+
// command lands it — including the auto-merge fallback when the checks are still running.
|
|
65
|
+
// MERGE_MODE_AUTO is passed explicitly: running this command IS the intent to merge, so it is
|
|
66
|
+
// not gated on pr-gate.mergeMode (a NONE repo runs this precisely to land one PR by hand).
|
|
67
|
+
const outcome = this.prMerger.merge(base, `${ref.title} (#${ref.number})`, mergeBodyFile, rules_config_1.MERGE_MODE_AUTO);
|
|
68
|
+
const policy = (0, rules_config_1.loadAndValidate)(repoRoot).prGate.mergeMode;
|
|
69
|
+
process.stdout.write('\n' + SEP + (outcome.merged ? '✅ Landed\n' : 'ℹ️ Not landed yet\n') + SEP + '\n' +
|
|
70
|
+
` ${outcome.message}\n` +
|
|
71
|
+
(outcome.merged ? ' Next: `pnpm wp-cleanup` to delete the merged branch.\n' : '') +
|
|
72
|
+
(policy === rules_config_1.MERGE_MODE_AUTO
|
|
73
|
+
? ''
|
|
74
|
+
: ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr will keep leaving PRs for a human.)\n`) +
|
|
75
|
+
'\n');
|
|
76
|
+
}
|
|
77
|
+
// The open PR's number + title for this head branch, or null when there is none. The TITLE comes
|
|
78
|
+
// from the PR itself, not review.json, so the squash subject matches what a reviewer approved even
|
|
79
|
+
// if review.json was edited afterwards.
|
|
80
|
+
prNumberAndTitle(baseBranch) {
|
|
81
|
+
const result = (0, child_process_1.spawnSync)('gh', ['pr', 'view', baseBranch, '--json', 'number,title', '--jq', '"\\(.number)\\t\\(.title)"'], { encoding: 'utf8' });
|
|
82
|
+
if (result.status !== 0)
|
|
83
|
+
return null;
|
|
84
|
+
const parts = (result.stdout ?? '').trim().split('\t');
|
|
85
|
+
if ((parts[0] ?? '') === '')
|
|
86
|
+
return null;
|
|
87
|
+
return new PrIdentity(parts[0] ?? '', parts[1] ?? '');
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
exports.LandPrCommand = LandPrCommand;
|
|
91
|
+
exports.LandPrCommand = LandPrCommand = tslib_1.__decorate([
|
|
92
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
93
|
+
tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
|
|
94
|
+
git_readAiBranchName_1.AiBranchName,
|
|
95
|
+
branch_naming_1.BranchNaming,
|
|
96
|
+
pr_merger_1.PrMerger])
|
|
97
|
+
], LandPrCommand);
|
|
98
|
+
// The open PR's number + title, as read back from GitHub.
|
|
99
|
+
class PrIdentity {
|
|
100
|
+
number;
|
|
101
|
+
title;
|
|
102
|
+
constructor(number, title) {
|
|
103
|
+
this.number = number;
|
|
104
|
+
this.title = title;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=land-pr-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"land-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/land-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAoH;AACpH,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,qDAAiD;AAEjD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;GAcG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;IAED;IACA;IACA;IACA;IAJrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,QAAkB;QAHlB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAU;IACpC,CAAC;IAEJ,KAAK,CAAC,GAAG;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,IAAA,wBAAQ,EAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAClH,MAAM,KAAK,GAAG,IAAA,uBAAQ,EAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,CAAC,CAAC;QACrE,MAAM,aAAa,GAAG,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Ed,YAAY,MAAc,EAAE,KAAa;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { prDirFor, InformAiError, RepoRootFinder, MERGE_MODE_AUTO, loadAndValidate } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { PrMerger } from '../workflow/pr-merger';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.\n *\n * It exists because a merge clicked in the GitHub UI cannot produce that body. A UI merge is limited\n * to the repo's squash_merge_commit_title/message settings, and none of their values yields the\n * shortened risk/flags summary — only an explicit `gh pr merge --subject --body-file` does. So when a\n * merge has to happen outside `wp-finish-upsert-pr` (a mergeMode=NONE repo, or a PR whose checks were\n * still running when finish ran), this is the command that keeps main's history consistent.\n *\n * It deliberately does NOT re-run the build gate or re-render the dashboard: `wp-finish-upsert-pr`\n * already did both and left `merge-commit-body.md` on disk. Landing is a separate, later act, and\n * rebuilding here would mean a second authoritative gate whose result nobody reads. If that file is\n * missing, the honest answer is that finish has not run — so this fails and says so, rather than\n * inventing a body that would not match the PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class LandPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly prMerger: PrMerger,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const base = this.branchNaming.baseBranchName(execSync('git branch --show-current', { encoding: 'utf8' }).trim());\n const prDir = prDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const mergeBodyFile = path.join(prDir, 'merge-commit-body.md');\n\n if (!fs.existsSync(mergeBodyFile)) {\n throw new InformAiError(\n '\\n' + SEP + '❌ Nothing to land — no rendered merge body\\n' + SEP + '\\n' +\n `Expected the compact squash-commit body at:\\n ${mergeBodyFile}\\n\\n` +\n 'That file is written by `pnpm wp-finish-upsert-pr`, which is also what posts the PR.\\n' +\n 'Its absence means finish has not run on this branch, so there is no reviewed PR to\\n' +\n 'land. Run the gated flow first:\\n\\n' +\n ' pnpm wp-start-upsert-pr # update from main, push, build gate\\n' +\n ' # write .webpieces/review.json\\n' +\n ' pnpm wp-finish-upsert-pr # build gate, dashboard, create/update the PR\\n\\n' +\n 'Then re-run `pnpm wp-land-pr` if the PR still needs landing.\\n' + SEP,\n );\n }\n\n const ref = this.prNumberAndTitle(base);\n if (ref === null) {\n throw new InformAiError(\n '\\n' + SEP + '❌ No open PR found for this branch\\n' + SEP + '\\n' +\n `No open PR has head branch \"${base}\". Nothing to land.\\n` +\n 'If the PR is already merged, run `pnpm wp-cleanup`.\\n' + SEP,\n );\n }\n\n process.stdout.write('\\n' + SEP + `🚀 Landing PR #${ref.number}\\n` + SEP + '\\n');\n // Reuse the SAME merge logic wp-finish-upsert-pr uses, so a PR lands identically whichever\n // command lands it — including the auto-merge fallback when the checks are still running.\n // MERGE_MODE_AUTO is passed explicitly: running this command IS the intent to merge, so it is\n // not gated on pr-gate.mergeMode (a NONE repo runs this precisely to land one PR by hand).\n const outcome = this.prMerger.merge(base, `${ref.title} (#${ref.number})`, mergeBodyFile, MERGE_MODE_AUTO);\n\n const policy = loadAndValidate(repoRoot).prGate.mergeMode;\n process.stdout.write(\n '\\n' + SEP + (outcome.merged ? '✅ Landed\\n' : 'ℹ️ Not landed yet\\n') + SEP + '\\n' +\n ` ${outcome.message}\\n` +\n (outcome.merged ? ' Next: `pnpm wp-cleanup` to delete the merged branch.\\n' : '') +\n (policy === MERGE_MODE_AUTO\n ? ''\n : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr will keep leaving PRs for a human.)\\n`) +\n '\\n',\n );\n }\n\n // The open PR's number + title for this head branch, or null when there is none. The TITLE comes\n // from the PR itself, not review.json, so the squash subject matches what a reviewer approved even\n // if review.json was edited afterwards.\n private prNumberAndTitle(baseBranch: string): PrIdentity | null {\n const result = spawnSync(\n 'gh', ['pr', 'view', baseBranch, '--json', 'number,title', '--jq', '\"\\\\(.number)\\\\t\\\\(.title)\"'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) return null;\n const parts = (result.stdout ?? '').trim().split('\\t');\n if ((parts[0] ?? '') === '') return null;\n return new PrIdentity(parts[0] ?? '', parts[1] ?? '');\n }\n}\n\n// The open PR's number + title, as read back from GitHub.\nclass PrIdentity {\n number: string;\n title: string;\n\n constructor(number: string, title: string) {\n this.number = number;\n this.title = title;\n }\n}\n"]}
|
|
@@ -3,9 +3,10 @@ import { FinishUpdateCommand } from './commands/finish-update-command';
|
|
|
3
3
|
import { StartUpsertPrCommand } from './commands/start-upsert-pr-command';
|
|
4
4
|
import { FinishUpsertPrCommand } from './commands/finish-upsert-pr-command';
|
|
5
5
|
import { CleanupCommand } from './commands/cleanup-command';
|
|
6
|
+
import { LandPrCommand } from './commands/land-pr-command';
|
|
6
7
|
/**
|
|
7
|
-
* The pr-gate application root. `container.get(PrGateApp)` resolves the entire workflow DAG (the
|
|
8
|
-
*
|
|
8
|
+
* The pr-gate application root. `container.get(PrGateApp)` resolves the entire workflow DAG (the command
|
|
9
|
+
* classes → the injected git/merge/dashboard services). `@DocumentDesign` marks it the
|
|
9
10
|
* top-of-DAG the DI-design analyzer roots on, so `role:app` pr-gate draws its design. Each `bin/*`
|
|
10
11
|
* entry resolves THIS and calls the matching command method.
|
|
11
12
|
*/
|
|
@@ -15,7 +16,8 @@ export declare class PrGateApp {
|
|
|
15
16
|
private readonly startUpsertPrCommand;
|
|
16
17
|
private readonly finishUpsertPrCommand;
|
|
17
18
|
private readonly cleanupCommand;
|
|
18
|
-
|
|
19
|
+
private readonly landPrCommand;
|
|
20
|
+
constructor(startUpdateCommand: StartUpdateCommand, finishUpdateCommand: FinishUpdateCommand, startUpsertPrCommand: StartUpsertPrCommand, finishUpsertPrCommand: FinishUpsertPrCommand, cleanupCommand: CleanupCommand, landPrCommand: LandPrCommand);
|
|
19
21
|
/** `wp-start-update`: 3-point squash-update from main (no PR). */
|
|
20
22
|
startUpdate(): Promise<void>;
|
|
21
23
|
/** `wp-finish-update`: validate + finalize a resolved 3-point merge (no PR). */
|
|
@@ -26,4 +28,6 @@ export declare class PrGateApp {
|
|
|
26
28
|
finishUpsertPr(): Promise<void>;
|
|
27
29
|
/** `wp-cleanup`: delete local branches whose PR is already merged (or that hold no commits). */
|
|
28
30
|
cleanup(): Promise<void>;
|
|
31
|
+
/** `wp-land-pr`: squash-merge this branch's PR into main with the compact commit body. */
|
|
32
|
+
landPr(): Promise<void>;
|
|
29
33
|
}
|
|
@@ -9,9 +9,10 @@ const finish_update_command_1 = require("./commands/finish-update-command");
|
|
|
9
9
|
const start_upsert_pr_command_1 = require("./commands/start-upsert-pr-command");
|
|
10
10
|
const finish_upsert_pr_command_1 = require("./commands/finish-upsert-pr-command");
|
|
11
11
|
const cleanup_command_1 = require("./commands/cleanup-command");
|
|
12
|
+
const land_pr_command_1 = require("./commands/land-pr-command");
|
|
12
13
|
/**
|
|
13
|
-
* The pr-gate application root. `container.get(PrGateApp)` resolves the entire workflow DAG (the
|
|
14
|
-
*
|
|
14
|
+
* The pr-gate application root. `container.get(PrGateApp)` resolves the entire workflow DAG (the command
|
|
15
|
+
* classes → the injected git/merge/dashboard services). `@DocumentDesign` marks it the
|
|
15
16
|
* top-of-DAG the DI-design analyzer roots on, so `role:app` pr-gate draws its design. Each `bin/*`
|
|
16
17
|
* entry resolves THIS and calls the matching command method.
|
|
17
18
|
*/
|
|
@@ -21,12 +22,14 @@ let PrGateApp = class PrGateApp {
|
|
|
21
22
|
startUpsertPrCommand;
|
|
22
23
|
finishUpsertPrCommand;
|
|
23
24
|
cleanupCommand;
|
|
24
|
-
|
|
25
|
+
landPrCommand;
|
|
26
|
+
constructor(startUpdateCommand, finishUpdateCommand, startUpsertPrCommand, finishUpsertPrCommand, cleanupCommand, landPrCommand) {
|
|
25
27
|
this.startUpdateCommand = startUpdateCommand;
|
|
26
28
|
this.finishUpdateCommand = finishUpdateCommand;
|
|
27
29
|
this.startUpsertPrCommand = startUpsertPrCommand;
|
|
28
30
|
this.finishUpsertPrCommand = finishUpsertPrCommand;
|
|
29
31
|
this.cleanupCommand = cleanupCommand;
|
|
32
|
+
this.landPrCommand = landPrCommand;
|
|
30
33
|
}
|
|
31
34
|
/** `wp-start-update`: 3-point squash-update from main (no PR). */
|
|
32
35
|
startUpdate() {
|
|
@@ -48,6 +51,10 @@ let PrGateApp = class PrGateApp {
|
|
|
48
51
|
cleanup() {
|
|
49
52
|
return this.cleanupCommand.run();
|
|
50
53
|
}
|
|
54
|
+
/** `wp-land-pr`: squash-merge this branch's PR into main with the compact commit body. */
|
|
55
|
+
landPr() {
|
|
56
|
+
return this.landPrCommand.run();
|
|
57
|
+
}
|
|
51
58
|
};
|
|
52
59
|
exports.PrGateApp = PrGateApp;
|
|
53
60
|
exports.PrGateApp = PrGateApp = tslib_1.__decorate([
|
|
@@ -57,6 +64,7 @@ exports.PrGateApp = PrGateApp = tslib_1.__decorate([
|
|
|
57
64
|
finish_update_command_1.FinishUpdateCommand,
|
|
58
65
|
start_upsert_pr_command_1.StartUpsertPrCommand,
|
|
59
66
|
finish_upsert_pr_command_1.FinishUpsertPrCommand,
|
|
60
|
-
cleanup_command_1.CleanupCommand
|
|
67
|
+
cleanup_command_1.CleanupCommand,
|
|
68
|
+
land_pr_command_1.LandPrCommand])
|
|
61
69
|
], PrGateApp);
|
|
62
70
|
//# sourceMappingURL=pr-gate-app.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pr-gate-app.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/pr-gate-app.ts"],"names":[],"mappings":";;;;AAAA,0DAAyD;AACzD,yCAA2D;AAC3D,0EAAqE;AACrE,4EAAuE;AACvE,gFAA0E;AAC1E,kFAA4E;AAC5E,gEAA4D;
|
|
1
|
+
{"version":3,"file":"pr-gate-app.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/pr-gate-app.ts"],"names":[],"mappings":";;;;AAAA,0DAAyD;AACzD,yCAA2D;AAC3D,0EAAqE;AACrE,4EAAuE;AACvE,gFAA0E;AAC1E,kFAA4E;AAC5E,gEAA4D;AAC5D,gEAA2D;AAE3D;;;;;GAKG;AAGI,IAAM,SAAS,GAAf,MAAM,SAAS;IAEG;IACA;IACA;IACA;IACA;IACA;IANrB,YACqB,kBAAsC,EACtC,mBAAwC,EACxC,oBAA0C,EAC1C,qBAA4C,EAC5C,cAA8B,EAC9B,aAA4B;QAL5B,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,mBAAc,GAAd,cAAc,CAAgB;QAC9B,kBAAa,GAAb,aAAa,CAAe;IAC9C,CAAC;IAEJ,kEAAkE;IAClE,WAAW;QACP,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,EAAE,CAAC;IACzC,CAAC;IAED,gFAAgF;IAChF,YAAY;QACR,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC;IAC1C,CAAC;IAED,+FAA+F;IAC/F,aAAa;QACT,OAAO,IAAI,CAAC,oBAAoB,CAAC,GAAG,EAAE,CAAC;IAC3C,CAAC;IAED,oGAAoG;IACpG,cAAc;QACV,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE,CAAC;IAC5C,CAAC;IAED,gGAAgG;IAChG,OAAO;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;IACrC,CAAC;IAED,0FAA0F;IAC1F,MAAM;QACF,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC;IACpC,CAAC;CACJ,CAAA;AAvCY,8BAAS;oBAAT,SAAS;IAFrB,IAAA,6BAAc,GAAE;IAChB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGI,yCAAkB;QACjB,2CAAmB;QAClB,8CAAoB;QACnB,gDAAqB;QAC5B,gCAAc;QACf,+BAAa;GAPxC,SAAS,CAuCrB","sourcesContent":["import { DocumentDesign } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { StartUpdateCommand } from './commands/start-update-command';\nimport { FinishUpdateCommand } from './commands/finish-update-command';\nimport { StartUpsertPrCommand } from './commands/start-upsert-pr-command';\nimport { FinishUpsertPrCommand } from './commands/finish-upsert-pr-command';\nimport { CleanupCommand } from './commands/cleanup-command';\nimport { LandPrCommand } from './commands/land-pr-command';\n\n/**\n * The pr-gate application root. `container.get(PrGateApp)` resolves the entire workflow DAG (the command\n * classes → the injected git/merge/dashboard services). `@DocumentDesign` marks it the\n * top-of-DAG the DI-design analyzer roots on, so `role:app` pr-gate draws its design. Each `bin/*`\n * entry resolves THIS and calls the matching command method.\n */\n@DocumentDesign()\n@injectable(bindingScopeValues.Singleton)\nexport class PrGateApp {\n constructor(\n private readonly startUpdateCommand: StartUpdateCommand,\n private readonly finishUpdateCommand: FinishUpdateCommand,\n private readonly startUpsertPrCommand: StartUpsertPrCommand,\n private readonly finishUpsertPrCommand: FinishUpsertPrCommand,\n private readonly cleanupCommand: CleanupCommand,\n private readonly landPrCommand: LandPrCommand,\n ) {}\n\n /** `wp-start-update`: 3-point squash-update from main (no PR). */\n startUpdate(): Promise<void> {\n return this.startUpdateCommand.run();\n }\n\n /** `wp-finish-update`: validate + finalize a resolved 3-point merge (no PR). */\n finishUpdate(): Promise<void> {\n return this.finishUpdateCommand.run();\n }\n\n /** `wp-start-upsert-pr`: update from main, push, advisory build gate, hand off review.json. */\n startUpsertPr(): Promise<void> {\n return this.startUpsertPrCommand.run();\n }\n\n /** `wp-finish-upsert-pr`: finalize merge, authoritative build gate, dashboard, create/update PR. */\n finishUpsertPr(): Promise<void> {\n return this.finishUpsertPrCommand.run();\n }\n\n /** `wp-cleanup`: delete local branches whose PR is already merged (or that hold no commits). */\n cleanup(): Promise<void> {\n return this.cleanupCommand.run();\n }\n\n /** `wp-land-pr`: squash-merge this branch's PR into main with the compact commit body. */\n landPr(): Promise<void> {\n return this.landPrCommand.run();\n }\n}\n"]}
|
|
@@ -14,14 +14,22 @@ export declare class MergeOutcome {
|
|
|
14
14
|
* --body-file` does not depend on that setting at all. When the PR is NOT yet mergeable there is no
|
|
15
15
|
* queue to fall back to, so we say so loudly instead of firing a `--auto` that can only fail.
|
|
16
16
|
*
|
|
17
|
+
* WHICH of those a repo gets is not guessed — `pr-gate.mergeMode` is REQUIRED config. AUTO means the
|
|
18
|
+
* tooling lands PRs; NONE means it only posts them and a person merges. No mode can force a queue the
|
|
19
|
+
* repo has turned off, so AUTO on a repo with allow_auto_merge=false is a CONFIG error, reported as
|
|
20
|
+
* one rather than papered over.
|
|
21
|
+
*
|
|
17
22
|
* Every `gh` status is checked. Nothing here is allowed to fail silently.
|
|
18
23
|
*/
|
|
19
24
|
export declare class PrMerger {
|
|
20
25
|
/**
|
|
21
26
|
* @param subject the squash-commit subject, normally `<PR title> (#N)`
|
|
22
27
|
* @param mergeBodyFile file holding the squash-commit body (risk/flags/PR link)
|
|
28
|
+
* @param mergeMode pr-gate.mergeMode from webpieces.config.json — AUTO or NONE. Anything else
|
|
29
|
+
* (including a repo still on a published rules-config that predates the field)
|
|
30
|
+
* is treated as NONE: when the policy is unreadable, do NOT touch main.
|
|
23
31
|
*/
|
|
24
|
-
merge(baseBranch: string, subject: string, mergeBodyFile: string): MergeOutcome;
|
|
32
|
+
merge(baseBranch: string, subject: string, mergeBodyFile: string, mergeMode: string): MergeOutcome;
|
|
25
33
|
protected autoMergeAllowed(): boolean;
|
|
26
34
|
protected gh(args: string[], quiet?: boolean): number;
|
|
27
35
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PrMerger = exports.MergeOutcome = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
7
|
const inversify_1 = require("inversify");
|
|
7
8
|
// What actually happened when we tried to land the squash merge. `message` is printed VERBATIM in the
|
|
8
9
|
// final wp-finish-upsert-pr summary, so a merge that did not happen can never be reported as done —
|
|
@@ -29,14 +30,28 @@ exports.MergeOutcome = MergeOutcome;
|
|
|
29
30
|
* --body-file` does not depend on that setting at all. When the PR is NOT yet mergeable there is no
|
|
30
31
|
* queue to fall back to, so we say so loudly instead of firing a `--auto` that can only fail.
|
|
31
32
|
*
|
|
33
|
+
* WHICH of those a repo gets is not guessed — `pr-gate.mergeMode` is REQUIRED config. AUTO means the
|
|
34
|
+
* tooling lands PRs; NONE means it only posts them and a person merges. No mode can force a queue the
|
|
35
|
+
* repo has turned off, so AUTO on a repo with allow_auto_merge=false is a CONFIG error, reported as
|
|
36
|
+
* one rather than papered over.
|
|
37
|
+
*
|
|
32
38
|
* Every `gh` status is checked. Nothing here is allowed to fail silently.
|
|
33
39
|
*/
|
|
34
40
|
let PrMerger = class PrMerger {
|
|
35
41
|
/**
|
|
36
42
|
* @param subject the squash-commit subject, normally `<PR title> (#N)`
|
|
37
43
|
* @param mergeBodyFile file holding the squash-commit body (risk/flags/PR link)
|
|
44
|
+
* @param mergeMode pr-gate.mergeMode from webpieces.config.json — AUTO or NONE. Anything else
|
|
45
|
+
* (including a repo still on a published rules-config that predates the field)
|
|
46
|
+
* is treated as NONE: when the policy is unreadable, do NOT touch main.
|
|
38
47
|
*/
|
|
39
|
-
merge(baseBranch, subject, mergeBodyFile) {
|
|
48
|
+
merge(baseBranch, subject, mergeBodyFile, mergeMode) {
|
|
49
|
+
// Anything that is not an explicit AUTO leaves the PR alone. The PR itself is already
|
|
50
|
+
// posted/updated by this point, which is the whole job in this mode.
|
|
51
|
+
if (mergeMode !== rules_config_1.MERGE_MODE_AUTO) {
|
|
52
|
+
return new MergeOutcome(false, false, `did NOT merge — pr-gate.mergeMode is ${mergeMode === rules_config_1.MERGE_MODE_NONE ? 'NONE' : `"${mergeMode}"`}, so the PR is left for a human to merge.\n` +
|
|
53
|
+
` Subject GitHub will use is its own (squash_merge_commit_title), NOT: "${subject}"`);
|
|
54
|
+
}
|
|
40
55
|
// A direct `gh pr merge --squash --subject --body-file` writes exactly this subject/body to
|
|
41
56
|
// main's history regardless of the repo's squash_merge_commit_title/message defaults — and
|
|
42
57
|
// regardless of allow_auto_merge. It is the ONLY path that guarantees the good commit message.
|
|
@@ -44,13 +59,16 @@ let PrMerger = class PrMerger {
|
|
|
44
59
|
if (direct === 0) {
|
|
45
60
|
return new MergeOutcome(true, false, `squash-merged the PR as: "${subject}"`);
|
|
46
61
|
}
|
|
62
|
+
// Past here the PR is not mergeable yet — checks still running, or a review / branch protection
|
|
63
|
+
// is blocking it. The auto-merge queue is the only way to still land it unattended, so only ask
|
|
64
|
+
// GitHub about the queue HERE: a run whose direct merge succeeded costs no extra API call.
|
|
47
65
|
if (!this.autoMergeAllowed()) {
|
|
48
|
-
return new MergeOutcome(false, false, '⚠️ did NOT merge, and queued NOTHING —
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
|
|
52
|
-
'
|
|
53
|
-
'
|
|
66
|
+
return new MergeOutcome(false, false, '⚠️ did NOT merge, and queued NOTHING — CONFIG MISMATCH: pr-gate.mergeMode is AUTO, but\n' +
|
|
67
|
+
' this repo has allow_auto_merge=false, so there is no queue to fall back to and the\n' +
|
|
68
|
+
' PR is not mergeable yet. `gh pr merge --auto` cannot override a repo that says no.\n' +
|
|
69
|
+
' Fix it at ONE of the two ends: turn on "Allow auto-merge" in the repo settings, or\n' +
|
|
70
|
+
' set commands.pr-gate.mergeMode to "NONE" (and set that repo\'s\n' +
|
|
71
|
+
' squash_merge_commit_title to PR_TITLE so a human merge still gets a real subject).');
|
|
54
72
|
}
|
|
55
73
|
// gh records the merge subject/body only at the moment auto-merge is FIRST enabled; a second
|
|
56
74
|
// `--auto` on an already-enabled PR silently keeps the OLD body. Disabling first re-stamps the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pr-merger.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/pr-merger.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,yCAA2D;AAE3D,sGAAsG;AACtG,oGAAoG;AACpG,kGAAkG;AAClG,uFAAuF;AACvF,MAAa,YAAY;IACrB,MAAM,CAAU;IAChB,gBAAgB,CAAU;IAC1B,OAAO,CAAS;IAEhB,YAAY,MAAe,EAAE,gBAAyB,EAAE,OAAe;QACnE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;CACJ;AAVD,oCAUC;AAED
|
|
1
|
+
{"version":3,"file":"pr-merger.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/pr-merger.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,0DAA2E;AAC3E,yCAA2D;AAE3D,sGAAsG;AACtG,oGAAoG;AACpG,kGAAkG;AAClG,uFAAuF;AACvF,MAAa,YAAY;IACrB,MAAM,CAAU;IAChB,gBAAgB,CAAU;IAC1B,OAAO,CAAS;IAEhB,YAAY,MAAe,EAAE,gBAAyB,EAAE,OAAe;QACnE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAA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CAAC;GAC5B,QAAQ,CAmEpB","sourcesContent":["import { spawnSync } from 'child_process';\nimport { MERGE_MODE_AUTO, MERGE_MODE_NONE } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n// What actually happened when we tried to land the squash merge. `message` is printed VERBATIM in the\n// final wp-finish-upsert-pr summary, so a merge that did not happen can never be reported as done —\n// the old code ignored `spawnSync().status` entirely and printed \"✅ PR finished\" even when `gh pr\n// merge` had errored out, which is what hid the auto-merge-disabled failure for weeks.\nexport class MergeOutcome {\n merged: boolean;\n autoMergeEnabled: boolean;\n message: string;\n\n constructor(merged: boolean, autoMergeEnabled: boolean, message: string) {\n this.merged = merged;\n this.autoMergeEnabled = autoMergeEnabled;\n this.message = message;\n }\n}\n\n/**\n * Lands — or queues — the squash merge with an EXPLICIT subject/body, on BOTH kinds of repo:\n *\n * - auto-merge ALLOWED (`allow_auto_merge: true`): a PR whose checks are still running falls back to\n * the auto-merge queue, carrying the same subject/body so it lands when the checks pass.\n * - auto-merge DISALLOWED (`allow_auto_merge: false`, a deliberate policy control in many orgs): the\n * direct merge still works the moment the PR is mergeable, because `gh pr merge --squash --subject\n * --body-file` does not depend on that setting at all. When the PR is NOT yet mergeable there is no\n * queue to fall back to, so we say so loudly instead of firing a `--auto` that can only fail.\n *\n * WHICH of those a repo gets is not guessed — `pr-gate.mergeMode` is REQUIRED config. AUTO means the\n * tooling lands PRs; NONE means it only posts them and a person merges. No mode can force a queue the\n * repo has turned off, so AUTO on a repo with allow_auto_merge=false is a CONFIG error, reported as\n * one rather than papered over.\n *\n * Every `gh` status is checked. Nothing here is allowed to fail silently.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PrMerger {\n /**\n * @param subject the squash-commit subject, normally `<PR title> (#N)`\n * @param mergeBodyFile file holding the squash-commit body (risk/flags/PR link)\n * @param mergeMode pr-gate.mergeMode from webpieces.config.json — AUTO or NONE. Anything else\n * (including a repo still on a published rules-config that predates the field)\n * is treated as NONE: when the policy is unreadable, do NOT touch main.\n */\n merge(baseBranch: string, subject: string, mergeBodyFile: string, mergeMode: string): MergeOutcome {\n // Anything that is not an explicit AUTO leaves the PR alone. The PR itself is already\n // posted/updated by this point, which is the whole job in this mode.\n if (mergeMode !== MERGE_MODE_AUTO) {\n return new MergeOutcome(false, false,\n `did NOT merge — pr-gate.mergeMode is ${mergeMode === MERGE_MODE_NONE ? 'NONE' : `\"${mergeMode}\"`}, so the PR is left for a human to merge.\\n` +\n ` Subject GitHub will use is its own (squash_merge_commit_title), NOT: \"${subject}\"`);\n }\n\n // A direct `gh pr merge --squash --subject --body-file` writes exactly this subject/body to\n // main's history regardless of the repo's squash_merge_commit_title/message defaults — and\n // regardless of allow_auto_merge. It is the ONLY path that guarantees the good commit message.\n const direct = this.gh(['pr', 'merge', baseBranch, '--squash', '--subject', subject, '--body-file', mergeBodyFile]);\n if (direct === 0) {\n return new MergeOutcome(true, false, `squash-merged the PR as: \"${subject}\"`);\n }\n\n // Past here the PR is not mergeable yet — checks still running, or a review / branch protection\n // is blocking it. The auto-merge queue is the only way to still land it unattended, so only ask\n // GitHub about the queue HERE: a run whose direct merge succeeded costs no extra API call.\n if (!this.autoMergeAllowed()) {\n return new MergeOutcome(false, false,\n '⚠️ did NOT merge, and queued NOTHING — CONFIG MISMATCH: pr-gate.mergeMode is AUTO, but\\n' +\n ' this repo has allow_auto_merge=false, so there is no queue to fall back to and the\\n' +\n ' PR is not mergeable yet. `gh pr merge --auto` cannot override a repo that says no.\\n' +\n ' Fix it at ONE of the two ends: turn on \"Allow auto-merge\" in the repo settings, or\\n' +\n ' set commands.pr-gate.mergeMode to \"NONE\" (and set that repo\\'s\\n' +\n ' squash_merge_commit_title to PR_TITLE so a human merge still gets a real subject).');\n }\n\n // gh records the merge subject/body only at the moment auto-merge is FIRST enabled; a second\n // `--auto` on an already-enabled PR silently keeps the OLD body. Disabling first re-stamps the\n // current subject/body on every re-run (a harmless no-op when auto-merge is not enabled).\n this.gh(['pr', 'merge', baseBranch, '--disable-auto'], true);\n const auto = this.gh(['pr', 'merge', baseBranch, '--auto', '--squash', '--subject', subject, '--body-file', mergeBodyFile]);\n if (auto !== 0) {\n return new MergeOutcome(false, false,\n '⚠️ did NOT merge and could NOT enable auto-merge either (see the gh error above) —\\n' +\n ' NOTHING is queued. Re-run once the PR is healthy.');\n }\n return new MergeOutcome(false, true, `enabled auto-merge — it will squash-merge as \"${subject}\" when the checks pass`);\n }\n\n // Whether `gh pr merge --auto` is even possible on this repo. Many orgs set allow_auto_merge=false\n // as a policy control, where `--auto` can only ever fail with `GraphQL: Auto merge is not allowed\n // for this repository`. One API call beats discovering that from an error string. Anything other\n // than a clean `true` counts as NOT allowed: if the setting cannot be read we must not claim the\n // queue is available.\n protected autoMergeAllowed(): boolean {\n const result = spawnSync('gh', ['api', 'repos/{owner}/{repo}', '--jq', '.allow_auto_merge'], { encoding: 'utf8' });\n return result.status === 0 && (result.stdout ?? '').trim() === 'true';\n }\n\n // Runs `gh`, returning its exit status (-1 when gh could not be spawned at all, which must NOT be\n // mistaken for the 0 that means success).\n protected gh(args: string[], quiet: boolean = false): number {\n const result = spawnSync('gh', args, { stdio: quiet ? 'ignore' : 'inherit' });\n return result.status ?? -1;\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const inversify_1 = require("inversify");
|
|
6
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
7
|
+
const pr_gate_app_1 = require("./pr-gate-app");
|
|
8
|
+
// Composition root: build the container and resolve the app so inversify constructs the whole DAG.
|
|
9
|
+
(0, rules_config_1.runMain)(async () => {
|
|
10
|
+
// autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)
|
|
11
|
+
const container = new inversify_1.Container({ autobind: true });
|
|
12
|
+
// Reject `--help`/bogus flags BEFORE the app touches git — an ignored flag must never start the flow.
|
|
13
|
+
container.get(rules_config_1.CliArgs).assertNoArgs(new rules_config_1.CliUsage('wp-land-pr', "Squash-merge this branch's PR into main with the compact risk/flags commit body."));
|
|
14
|
+
await container.get(pr_gate_app_1.PrGateApp).landPr();
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=wp-land-pr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wp-land-pr.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/wp-land-pr.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,yCAAsC;AACtC,0DAAqE;AACrE,+CAA0C;AAE1C,mGAAmG;AACnG,IAAA,sBAAO,EAAC,KAAK,IAAmB,EAAE;IAC9B,kHAAkH;IAClH,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,sGAAsG;IACtG,SAAS,CAAC,GAAG,CAAC,sBAAO,CAAC,CAAC,YAAY,CAAC,IAAI,uBAAQ,CAC5C,YAAY,EAAE,kFAAkF,CAAC,CAAC,CAAC;IACvG,MAAM,SAAS,CAAC,GAAG,CAAC,uBAAS,CAAC,CAAC,MAAM,EAAE,CAAC;AAC5C,CAAC,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport 'reflect-metadata';\nimport { Container } from 'inversify';\nimport { runMain, CliArgs, CliUsage } from '@webpieces/rules-config';\nimport { PrGateApp } from './pr-gate-app';\n\n// Composition root: build the container and resolve the app so inversify constructs the whole DAG.\nrunMain(async (): Promise<void> => {\n // autobind self-binds every @injectable(Singleton) tooling class (replaces the buildProviderModule registry scan)\n const container = new Container({ autobind: true });\n // Reject `--help`/bogus flags BEFORE the app touches git — an ignored flag must never start the flow.\n container.get(CliArgs).assertNoArgs(new CliUsage(\n 'wp-land-pr', \"Squash-merge this branch's PR into main with the compact risk/flags commit body.\"));\n await container.get(PrGateApp).landPr();\n});\n"]}
|