@webpieces/pr-gate 0.4.1006 → 0.4.1008
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/land-pr-command.d.ts +12 -1
- package/src/scripts/commands/land-pr-command.js +37 -6
- package/src/scripts/commands/land-pr-command.js.map +1 -1
- package/src/scripts/workflow/finish-banner.d.ts +5 -12
- package/src/scripts/workflow/finish-banner.js +10 -30
- package/src/scripts/workflow/finish-banner.js.map +1 -1
- package/src/scripts/workflow/landed-ticket-resolver.d.ts +34 -0
- package/src/scripts/workflow/landed-ticket-resolver.js +100 -0
- package/src/scripts/workflow/landed-ticket-resolver.js.map +1 -0
- package/src/scripts/workflow/ticket-reminder.d.ts +48 -0
- package/src/scripts/workflow/ticket-reminder.js +101 -0
- package/src/scripts/workflow/ticket-reminder.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.1008",
|
|
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",
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
19
|
-
"@webpieces/hook-runtime": "0.4.
|
|
20
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/hook-runtime": "0.4.1008",
|
|
20
|
+
"@webpieces/rules-config": "0.4.1008",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2",
|
|
23
|
-
"@webpieces/tooling-common": "0.4.
|
|
24
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
23
|
+
"@webpieces/tooling-common": "0.4.1008",
|
|
24
|
+
"@webpieces/repo-workflow-core": "0.4.1008"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
30
|
+
"@webpieces/tooling-testkit": "0.4.1008"
|
|
31
31
|
},
|
|
32
32
|
"types": "./src/index.d.ts",
|
|
33
33
|
"bin": {
|
|
@@ -3,11 +3,13 @@ import { RepoRootFinder } from '@webpieces/rules-config';
|
|
|
3
3
|
import { BranchArchiver } from '@webpieces/repo-workflow-core';
|
|
4
4
|
import { AiBranchName } from '../workflow/git-readAiBranchName';
|
|
5
5
|
import { BranchNaming } from '../workflow/branch-naming';
|
|
6
|
+
import { LandedTicketResolver } from '../workflow/landed-ticket-resolver';
|
|
6
7
|
import { LandedTreeResolver } from '../workflow/landed-tree-resolver';
|
|
7
8
|
import { LandedWorktreeReaper } from '../workflow/landed-worktree-reaper';
|
|
8
9
|
import { MergeBodyTempFile } from '../workflow/merge-body-temp-file';
|
|
9
10
|
import { MergeInfoIndex } from '../workflow/merge-info-index';
|
|
10
11
|
import { PrMerger } from '../workflow/pr-merger';
|
|
12
|
+
import { TicketReminder } from '../workflow/ticket-reminder';
|
|
11
13
|
/**
|
|
12
14
|
* `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.
|
|
13
15
|
*
|
|
@@ -70,7 +72,9 @@ export declare class LandPrCommand {
|
|
|
70
72
|
private readonly landedTree;
|
|
71
73
|
private readonly git;
|
|
72
74
|
private readonly processes;
|
|
73
|
-
|
|
75
|
+
private readonly landedTickets;
|
|
76
|
+
private readonly ticketReminder;
|
|
77
|
+
constructor(repoRootFinder: RepoRootFinder, aiBranchName: AiBranchName, branchNaming: BranchNaming, prMerger: PrMerger, archiver: BranchArchiver, mergeInfoIndex: MergeInfoIndex, landedWorktree: LandedWorktreeReaper, bodyFile: MergeBodyTempFile, landedTree: LandedTreeResolver, git: GitProcessApi, processes: NativeProcessApi, landedTickets: LandedTicketResolver, ticketReminder: TicketReminder);
|
|
74
78
|
/**
|
|
75
79
|
* THE INVOCATION DIRECTORY, which is not `process.cwd()`.
|
|
76
80
|
*
|
|
@@ -82,6 +86,13 @@ export declare class LandPrCommand {
|
|
|
82
86
|
*/
|
|
83
87
|
private invocationCwd;
|
|
84
88
|
run(request: LandPrRequest): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Where `wp-finish-upsert-pr` wrote summary.json: the linked worktree holding the landed commit when
|
|
91
|
+
* there is one (a coordinator landing `--pr <n>` from the primary clone is not standing in it), else
|
|
92
|
+
* the tree this command was invoked in.
|
|
93
|
+
*/
|
|
94
|
+
private summaryTree;
|
|
95
|
+
private featureName;
|
|
85
96
|
/**
|
|
86
97
|
* `--pr` without a usable number. It REFUSES rather than falling back to the branch, because the
|
|
87
98
|
* fallback would land a different PR from the one the operator was reaching for, and a squash into
|
|
@@ -9,11 +9,13 @@ const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
|
|
|
9
9
|
const inversify_1 = require("inversify");
|
|
10
10
|
const git_readAiBranchName_1 = require("../workflow/git-readAiBranchName");
|
|
11
11
|
const branch_naming_1 = require("../workflow/branch-naming");
|
|
12
|
+
const landed_ticket_resolver_1 = require("../workflow/landed-ticket-resolver");
|
|
12
13
|
const landed_tree_resolver_1 = require("../workflow/landed-tree-resolver");
|
|
13
14
|
const landed_worktree_reaper_1 = require("../workflow/landed-worktree-reaper");
|
|
14
15
|
const merge_body_temp_file_1 = require("../workflow/merge-body-temp-file");
|
|
15
16
|
const merge_info_index_1 = require("../workflow/merge-info-index");
|
|
16
17
|
const pr_merger_1 = require("../workflow/pr-merger");
|
|
18
|
+
const ticket_reminder_1 = require("../workflow/ticket-reminder");
|
|
17
19
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
18
20
|
/**
|
|
19
21
|
* `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.
|
|
@@ -77,8 +79,10 @@ let LandPrCommand = class LandPrCommand {
|
|
|
77
79
|
landedTree;
|
|
78
80
|
git;
|
|
79
81
|
processes;
|
|
82
|
+
landedTickets;
|
|
83
|
+
ticketReminder;
|
|
80
84
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
81
|
-
constructor(repoRootFinder, aiBranchName, branchNaming, prMerger, archiver, mergeInfoIndex, landedWorktree, bodyFile, landedTree, git, processes) {
|
|
85
|
+
constructor(repoRootFinder, aiBranchName, branchNaming, prMerger, archiver, mergeInfoIndex, landedWorktree, bodyFile, landedTree, git, processes, landedTickets, ticketReminder) {
|
|
82
86
|
this.repoRootFinder = repoRootFinder;
|
|
83
87
|
this.aiBranchName = aiBranchName;
|
|
84
88
|
this.branchNaming = branchNaming;
|
|
@@ -90,6 +94,8 @@ let LandPrCommand = class LandPrCommand {
|
|
|
90
94
|
this.landedTree = landedTree;
|
|
91
95
|
this.git = git;
|
|
92
96
|
this.processes = processes;
|
|
97
|
+
this.landedTickets = landedTickets;
|
|
98
|
+
this.ticketReminder = ticketReminder;
|
|
93
99
|
}
|
|
94
100
|
/**
|
|
95
101
|
* THE INVOCATION DIRECTORY, which is not `process.cwd()`.
|
|
@@ -139,8 +145,15 @@ let LandPrCommand = class LandPrCommand {
|
|
|
139
145
|
// never assert a config value nobody set — that is exactly what used to print a CONFIG MISMATCH
|
|
140
146
|
// about `mergeMode: AUTO` two lines above this command printing `mergeMode is NONE`.
|
|
141
147
|
const outcome = await this.prMerger.merge(base, `${ref.title} (#${ref.number})`, mergeBodyFile, new pr_merger_1.MergeIntent(policy ?? '', true));
|
|
142
|
-
|
|
143
|
-
|
|
148
|
+
// Everything below the merge happens ONLY when it landed: a PR that did not land gets no archive,
|
|
149
|
+
// no reap and no "update your ticket" reminder (issue #1456).
|
|
150
|
+
const tree = outcome.merged ? await this.landedTree.resolve(repoRoot, base, ref.headRefOid) : null;
|
|
151
|
+
// Read BEFORE the bookkeeping, which may reap the very worktree holding summary.json.
|
|
152
|
+
const tickets = tree !== null
|
|
153
|
+
? this.landedTickets.resolve(this.summaryTree(repoRoot, tree), this.featureName(base), ref.body)
|
|
154
|
+
: null;
|
|
155
|
+
const bookkeeping = tree !== null
|
|
156
|
+
? await this.bookkeeping(repoRoot, base, ref, tree, config.landPr.branchRetention, cwd)
|
|
144
157
|
: '';
|
|
145
158
|
process.stdout.write('\n' + SEP + (outcome.merged ? '✅ Landed\n' : 'ℹ️ Not landed yet\n') + SEP + '\n' +
|
|
146
159
|
` ${outcome.message}\n` +
|
|
@@ -149,6 +162,23 @@ let LandPrCommand = class LandPrCommand {
|
|
|
149
162
|
? ''
|
|
150
163
|
: ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr publishes PRs without attempting a merge.)\n`) +
|
|
151
164
|
'\n');
|
|
165
|
+
// The same reminder wp-finish-upsert-pr printed when it posted the PR, repeated now that the work
|
|
166
|
+
// has reached main — the stage-③ copy is many turns old by the time a PR lands (issue #1456).
|
|
167
|
+
if (tickets !== null)
|
|
168
|
+
process.stdout.write(this.ticketReminder.forLandedPr(ref.url, tickets) + '\n');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Where `wp-finish-upsert-pr` wrote summary.json: the linked worktree holding the landed commit when
|
|
172
|
+
* there is one (a coordinator landing `--pr <n>` from the primary clone is not standing in it), else
|
|
173
|
+
* the tree this command was invoked in.
|
|
174
|
+
*/
|
|
175
|
+
summaryTree(repoRoot, tree) {
|
|
176
|
+
return tree.worktree !== null ? tree.worktree.path : repoRoot;
|
|
177
|
+
}
|
|
178
|
+
// summary.json's directory is keyed by the branch with `/` flattened — AiBranchName.getFeatureName's
|
|
179
|
+
// form, computed from the PR's head branch rather than from whatever directory pnpm hoisted us into.
|
|
180
|
+
featureName(base) {
|
|
181
|
+
return this.branchNaming.baseBranchName(base).replace(/\//g, '-');
|
|
152
182
|
}
|
|
153
183
|
/**
|
|
154
184
|
* `--pr` without a usable number. It REFUSES rather than falling back to the branch, because the
|
|
@@ -287,8 +317,7 @@ let LandPrCommand = class LandPrCommand {
|
|
|
287
317
|
* it is more precise in both directions — a second clone sitting on the SAME commit can safely
|
|
288
318
|
* archive it, and a tree that has committed further work since finish ran correctly declines.
|
|
289
319
|
*/
|
|
290
|
-
async bookkeeping(repoRoot, base, ref, retention, cwd) {
|
|
291
|
-
const tree = await this.landedTree.resolve(repoRoot, base, ref.headRefOid);
|
|
320
|
+
async bookkeeping(repoRoot, base, ref, tree, retention, cwd) {
|
|
292
321
|
if (!tree.bookkeepingAllowed)
|
|
293
322
|
return this.notTheLandedTipNotice(base, tree, ref);
|
|
294
323
|
return await this.archiveAndPromote(repoRoot, base, ref, retention)
|
|
@@ -437,7 +466,9 @@ exports.LandPrCommand = LandPrCommand = tslib_1.__decorate([
|
|
|
437
466
|
merge_body_temp_file_1.MergeBodyTempFile,
|
|
438
467
|
landed_tree_resolver_1.LandedTreeResolver,
|
|
439
468
|
tooling_common_1.GitProcessApi,
|
|
440
|
-
tooling_common_1.NativeProcessApi
|
|
469
|
+
tooling_common_1.NativeProcessApi,
|
|
470
|
+
landed_ticket_resolver_1.LandedTicketResolver,
|
|
471
|
+
ticket_reminder_1.TicketReminder])
|
|
441
472
|
], LandPrCommand);
|
|
442
473
|
// The open PR as GitHub holds it: its number, title, web URL, DESCRIPTION (= the gated commit body) and
|
|
443
474
|
// the PAIR that identifies its tree locally — the head branch's name and the commit being squashed.
|
|
@@ -1 +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,8DAA2F;AAC3F,iEAA6D;AAC7D,0DAA2F;AAC3F,sEAAoH;AACpH,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,2EAAsG;AACtG,+EAA+F;AAC/F,2EAAqE;AACrE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,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;CACJ;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IACtB;;;;OAIG;IACH,aAAa,CAAU;IACvB,mGAAmG;IACnG,QAAQ,CAAS;IAEjB,YAAY,aAAsB,EAAE,QAAgB;QAChD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAdD,sCAcC","sourcesContent":["import { GitProcessApi, InformAiError, NativeProcessApi } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { RepoRootFinder, MERGE_MODE_AUTO, loadAndValidate } from '@webpieces/rules-config';\nimport { BranchArchiver, BRANCH_RETENTION_ARCHIVE_TAG, BRANCH_RETENTION_KEEP } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { LandedTree, LandedTreeResolver, LANDED_TREE_ABSENT } from '../workflow/landed-tree-resolver';\nimport { LandedWorktreeReaper, WorktreeReapHandoff } from '../workflow/landed-worktree-reaper';\nimport { MergeBodyTempFile } from '../workflow/merge-body-temp-file';\nimport { ArchiveRecord, MergeInfoIndex } from '../workflow/merge-info-index';\nimport { MergeIntent, 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 set the squash SUBJECT to `<title> (#N)`\n * and cannot archive the pre-squash tip. So when a merge has to happen outside `wp-finish-upsert-pr`\n * (a mergeMode=NONE repo, or a PR whose checks were still running when finish ran), this is the command\n * that keeps main's history consistent and finishes the branch's bookkeeping.\n *\n * ─── Where the bytes come from: THE PR ITSELF ──────────────────────────────────────────────────────\n * `wp-finish-upsert-pr` renders ONE string and publishes it as the PR DESCRIPTION, and the full\n * dashboard lives in the PR's comments (see `pr-body-is-merge-body.spec.ts`, which pins that the\n * description and the merge body are one renderer's output). So the description IS the gated squash\n * body, held by GitHub, and landing reads it back with `gh pr view --json body`.\n *\n * THE BYTES THAT LAND ARE THE BYTES FINISH PRODUCED — that invariant is unchanged; what changed is that\n * GitHub, not this machine, is the thing holding them. That removes the whole machine-global receipt\n * store: a cache of a fact the remote already owns, which could only ever be missing, stale, or on the\n * wrong computer. Landing from a second clone, a fresh clone, or another machine entirely now just\n * works. See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n *\n * It still deliberately does NOT re-render the body: re-deriving it at land time would be a second\n * authoritative gate whose result nobody reads, and it could silently disagree with what was reviewed.\n *\n * ─── Two scopes, and only one of them is the tree's ────────────────────────────────────────────────\n * 1. THE MERGE, which belongs to the PR — and is therefore reachable from anywhere.\n * 2. THE BOOKKEEPING — archiving the pre-squash tip as `archive/<date>/<branch>`, promoting merge-info,\n * and reaping the landed worktree. That half belongs to the tree whose `<branch>` really is the\n * commit being squashed, and it must NOT be attempted from anywhere else: another clone's\n * `<branch>` is a different commit, so archiving it there would tag the wrong objects under the\n * right name.\n *\n * ─── WHICH tree that is, is a FACT — it is not \"the one I am standing in\" ──────────────────────────\n * That distinction used to be resolved from `process.cwd()`, and it was wrong twice over.\n *\n * It was wrong MECHANICALLY: `pnpm` hoists a bin's cwd to the workspace root, and a Claude Code agent\n * worktree lives at `<primary>/.claude/worktrees/agent-<id>` — INSIDE the primary clone — so pnpm walked\n * straight past it and `git branch --show-current` answered `main`. Landing a worktree PR, i.e. every\n * `/full-cycle` run, reported \"No open PR found for this branch\" for a PR that was open, and the #512\n * worktree reap was unreachable dead code. The invocation directory is now read from `INIT_CWD` (pnpm\n * exports the directory the human actually typed in) and given to BOTH the repo-root resolution and the\n * `git` call, so neither can be answered by the hoisted directory.\n *\n * And it was wrong in PRINCIPLE, which is the larger half: most of the time the `/full-cycle` subagent\n * lands its own PR, but many times it does not — CI was still running when it finished, it errored, or a\n * coordinator picks the work up an hour later, by which point that agent is gone and its worktree is a\n * directory nobody is standing in. So `--pr <n>` names the PR, and {@link LandedTreeResolver} finds its\n * tree by the pair `(headRefName, headRefOid)` — never by branch name alone. The reap target is the\n * worktree whose HEAD is the exact commit GitHub squashed, whichever directory the operator is in, and\n * when nothing local holds that commit the merge still happens and the bookkeeping is SKIPPED OUT LOUD.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class LandPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly prMerger: PrMerger,\n private readonly archiver: BranchArchiver,\n private readonly mergeInfoIndex: MergeInfoIndex,\n private readonly landedWorktree: LandedWorktreeReaper,\n private readonly bodyFile: MergeBodyTempFile,\n private readonly landedTree: LandedTreeResolver,\n private readonly git: GitProcessApi,\n private readonly processes: NativeProcessApi,\n ) {}\n\n /**\n * THE INVOCATION DIRECTORY, which is not `process.cwd()`.\n *\n * `pnpm` runs a workspace bin with its cwd hoisted to the workspace root and exports the directory\n * the operator was actually in as `INIT_CWD`. Every agent worktree is NESTED inside the primary\n * clone, so the hoist silently relocated this command into a different tree holding a different\n * branch — see the class doc. `process.cwd()` remains the answer when nothing set `INIT_CWD` (a\n * direct `node` invocation, or a spec), which is the case where the two are the same anyway.\n */\n private invocationCwd(): string {\n const init = process.env['INIT_CWD'] ?? '';\n return init !== '' ? init : process.cwd();\n }\n\n async run(request: LandPrRequest): Promise<void> {\n if (request.prFlagPresent && !/^\\d+$/.test(request.prNumber)) throw this.badPrNumber(request);\n const cwd = this.invocationCwd();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n // `--pr <n>` selects the PR outright; with no flag it is this branch's, read from the tree the\n // operator is really standing in.\n const selector = request.prNumber !== ''\n ? request.prNumber\n : this.branchNaming.baseBranchName(await this.currentBranch(cwd));\n\n const ref = await this.readPr(selector);\n if (ref === null) throw this.noSuchPr(request, selector);\n // The PR's OWN head branch, never the selector: with `--pr <n>` the operator named a number and\n // has said nothing about branches, and even in the zero-arg case GitHub is the authority on which\n // branch that PR is merging.\n const base = ref.headRefName !== '' ? ref.headRefName : selector;\n if (ref.body === '') throw this.emptyDescription(ref);\n const unfit = this.notFitForGitLog(ref.body);\n if (unfit !== '') throw this.descriptionUnfitForGitLog(ref, unfit);\n\n process.stdout.write('\\n' + SEP + `🚀 Landing PR #${ref.number}\\n` + SEP + '\\n');\n const mergeBodyFile = this.bodyFile.write(ref.body);\n\n const config = loadAndValidate(repoRoot).prGate;\n const policy = config.mergeMode;\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 //\n // `commanded: true` — running THIS command IS the intent to merge, so it is not gated on\n // pr-gate.mergeMode (a NONE repo runs this precisely to land one PR by hand). The real `policy`\n // travels alongside it rather than being replaced by a literal AUTO, so PrMerger's diagnostics\n // never assert a config value nobody set — that is exactly what used to print a CONFIG MISMATCH\n // about `mergeMode: AUTO` two lines above this command printing `mergeMode is NONE`.\n const outcome = await this.prMerger.merge(\n base, `${ref.title} (#${ref.number})`, mergeBodyFile, new MergeIntent(policy ?? '', true),\n );\n\n const bookkeeping = outcome.merged\n ? await this.bookkeeping(repoRoot, base, ref, config.landPr.branchRetention, cwd)\n : '';\n process.stdout.write(\n '\\n' + SEP + (outcome.merged ? '✅ Landed\\n' : 'ℹ️ Not landed yet\\n') + SEP + '\\n' +\n ` ${outcome.message}\\n` +\n bookkeeping +\n (policy === MERGE_MODE_AUTO\n ? ''\n : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr publishes PRs without attempting a merge.)\\n`) +\n '\\n',\n );\n }\n\n /**\n * `--pr` without a usable number. It REFUSES rather than falling back to the branch, because the\n * fallback would land a different PR from the one the operator was reaching for, and a squash into\n * main is not a place to guess. `--pr` bare and `--pr HEAD` land here alike.\n */\n private badPrNumber(request: LandPrRequest): InformAiError {\n const got = request.prNumber === '' ? 'nothing' : `\"${request.prNumber}\"`;\n return new InformAiError(\n '\\n' + SEP + '❌ --pr needs a PR NUMBER\\n' + SEP + '\\n' +\n `\\`--pr\\` was given ${got}. It takes the digits of one pull request:\\n` +\n ' pnpm wp-land-pr --pr 1087\\n\\n' +\n 'To land the PR of the branch you are standing on, pass no flag at all:\\n' +\n ' pnpm wp-land-pr\\n' + SEP);\n }\n\n /**\n * The refusal when `gh` has no open PR for what we asked about — and it must say WHICH question was\n * asked, because the two have different cures.\n *\n * The branch form used to be the only one, and it was the face of the cwd bug: run from an agent\n * worktree, pnpm's hoist made the branch read `main`, and an operator with an open PR in front of\n * them was told there was none. So the branch form now says what it looked up and where it read that\n * branch FROM, which is the one fact that makes a wrong answer recognisable as a wrong answer, and it\n * names the `--pr <n>` form that does not depend on the tree at all.\n */\n private noSuchPr(request: LandPrRequest, selector: string): InformAiError {\n if (request.prNumber !== '') {\n return new InformAiError(\n '\\n' + SEP + `❌ No open PR #${request.prNumber}\\n` + SEP + '\\n' +\n `\\`gh pr view ${request.prNumber}\\` found no OPEN pull request with that number.\\n` +\n 'If it is already merged, run `pnpm wp-cleanup` from the primary clone to finish the\\n' +\n 'branch and worktree bookkeeping. Otherwise check the number with `gh pr list`.\\n' + SEP);\n }\n return new InformAiError(\n '\\n' + SEP + '❌ No open PR found for this branch\\n' + SEP + '\\n' +\n `No open PR has head branch \"${selector}\", read from ${this.invocationCwd()}. Nothing to land.\\n` +\n 'If that is not the branch you expected, land it by number instead — it does not depend on\\n' +\n 'which directory you are standing in:\\n' +\n ' pnpm wp-land-pr --pr <n>\\n' +\n 'If the PR is already merged, run `pnpm wp-cleanup`.\\n' +\n 'If it was never posted, run the gated flow — it posts the PR AND writes the description\\n' +\n 'that becomes this commit body:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP);\n }\n\n /**\n * The refusal when the PR exists but its description is empty.\n *\n * This is the ONE remaining \"no gated body\" case, and it is now a property of the PR rather than of\n * this machine — which is why the cure is a single command with no human judgement call attached.\n * There is deliberately no `--fallback-title-only` escape any more: that flag existed because the\n * bytes could be on a DIFFERENT COMPUTER from the one landing, which cannot happen when GitHub holds\n * them. Re-running finish is always available, always correct, and lands the reviewed bytes.\n */\n private emptyDescription(ref: PrIdentity): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number} has an EMPTY description\\n` + SEP + '\\n' +\n 'The PR description IS the squash-commit body — `pnpm wp-finish-upsert-pr` renders one string\\n' +\n 'and publishes it as the description, and landing reads it straight back with\\n' +\n '`gh pr view --json body`. An empty description means the gated flow never published one\\n' +\n '(or a human cleared it), so there is nothing reviewed to land.\\n\\n' +\n 'Re-run the gated flow — it re-renders the description and re-posts it to this same PR:\\n' +\n ' pnpm wp-start-upsert-pr # update from main (3-point merge). No push, no build gate.\\n' +\n ' pnpm wp-review-upsert-pr # validate the merge, build gate, extract the diff, brief reviewers\\n' +\n ' # write summary.json at the path wp-review-upsert-pr prints\\n' +\n ' pnpm wp-finish-upsert-pr # build gate, dashboard, create/update the PR\\n' +\n 'Then re-run `pnpm wp-land-pr`.\\n' + SEP,\n );\n }\n\n /**\n * '' when the description is a compact gated body; otherwise the marker that proves it is not.\n *\n * This reads the SAME invariant `pr-body-is-merge-body.spec.ts` asserts from the other end: the\n * compact body \"contains nothing a plain-text git log cannot carry\" — no markdown heading, no table\n * pipe. It is therefore not a heuristic about what a dashboard looks like; it is the renderer's own\n * pinned property, checked against bytes that arrived from outside this process.\n *\n * WHY IT IS NEEDED, and why it is not a compatibility fallback: a PR posted by a release OLDER than\n * the surface swap still has the FULL DASHBOARD as its description. Measured on this repo,\n * 2026-08-07 — PR #613 (posted after the swap) has a description byte-identical to its squash body,\n * while PR #614 (still open, posted minutes before) begins `## 🚦 PR Gate Dashboard`. Landing that\n * one would dump a risk table into main, which is precisely the defect\n * `decisions/0004` § 4.1 warned about. So this REFUSES and names the one command that fixes it. It\n * never falls back, never rewrites, and never reaches for a second source of bytes.\n *\n * It keeps earning its place after the transition: nothing stops a human editing a PR description\n * in GitHub's textarea, and this is the only point between that edit and main's history.\n *\n * What it must NOT be read as is proof that the bytes did not come from `renderPrBody`. They can:\n * the compact body interpolates author text, and a `|` reaches that text from a TypeScript union, a\n * regex alternation or a quoted shell pipeline. `Dashboard.gitLogSafe` substitutes both markers at\n * the render exit so a freshly-rendered body no longer trips this — which is where that invariant\n * belongs, since the renderer is the only thing that can fix it without an extra CI cycle.\n */\n private notFitForGitLog(body: string): string {\n if (body.includes('##')) return '## (a markdown heading)';\n if (body.includes('|')) return '| (a markdown table)';\n return '';\n }\n\n /**\n * The refusal when the description is not the compact gated body.\n *\n * It names BOTH ways bytes get here, because naming only one sent readers down a path that did not\n * exist. It used to assert an old release as \"the usual cause\" and prescribe re-running finish — and\n * when the marker had come from AUTHOR TEXT instead (a `|` in a summary, from a TypeScript union or a\n * regex alternation), finish re-rendered the identical character from the unchanged `summary.json` and\n * landing refused again: a loop costing a CI cycle per turn, escapable only by guessing that one\n * character in your prose was the problem. `Dashboard.gitLogSafe` now substitutes both markers at the\n * render exit, so a freshly-rendered body cannot reach here at all — which leaves a HAND-EDITED\n * description and a genuinely old PR as the two remaining causes, and this says so.\n */\n private descriptionUnfitForGitLog(ref: PrIdentity, marker: string): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number}'s description is not a git-log commit body\\n` + SEP + '\\n' +\n `It contains ${marker}, which the compact body rendered by \\`pnpm wp-finish-upsert-pr\\` never\\n` +\n 'does — it substitutes both markers as it renders — so these bytes are not the gated summary,\\n' +\n 'and landing them would put a PR Gate Dashboard (or hand-written markdown) into main\\'s\\n' +\n 'history permanently.\\n\\n' +\n 'There are two causes, and they need different fixes:\\n\\n' +\n ' 1. The description was EDITED BY HAND on GitHub after finish posted it. Re-running finish\\n' +\n ' overwrites that edit with the compact body, so landing works.\\n' +\n ' 2. The PR was posted by a webpieces release OLDER than the one that made the description\\n' +\n ' the commit body, so it is still the full dashboard. The dashboard now lives in the PR\\'s\\n' +\n ' 1st comment instead, and re-running finish moves it there.\\n\\n' +\n `Either way the cure is the same, and it does NOT require removing ${marker.trim()} from your PR\\n` +\n 'summary text — a pipe or a heading in a summary is rendered safe, not rejected:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP,\n );\n }\n\n /**\n * The landed branch's post-merge bookkeeping — but ONLY when this tree's `<branch>` IS the commit\n * that was squashed.\n *\n * The fact being tested is \"does this working tree hold the objects the PR merged\", and the PR\n * answers it authoritatively: `headRefOid` is the tip GitHub squashed. A second clone's `<branch>`\n * is a different commit, so `archive/<date>/<branch>` there would tag the wrong tip under the right\n * name; `merge-info/staged/<feature>` lives in the posting tree's state, not ours; and the worktree\n * to reap is not this one. So the merge stands and the bookkeeping is declined ALOUD.\n *\n * This used to be read out of an `origin.json` sidecar recording which tree posted the PR. Comparing\n * SHAs is strictly better: it is a fact rather than a recorded claim, it needs no stored state, and\n * it is more precise in both directions — a second clone sitting on the SAME commit can safely\n * archive it, and a tree that has committed further work since finish ran correctly declines.\n */\n private async bookkeeping(\n repoRoot: string, base: string, ref: PrIdentity, retention: string, cwd: string,\n ): Promise<string> {\n const tree = await this.landedTree.resolve(repoRoot, base, ref.headRefOid);\n if (!tree.bookkeepingAllowed) return this.notTheLandedTipNotice(base, tree, ref);\n return await this.archiveAndPromote(repoRoot, base, ref, retention)\n + await this.nextStep(repoRoot, tree, cwd);\n }\n\n /**\n * What was skipped, why, and what the two SHAs are — so the reader can tell WHICH cause it was.\n *\n * Two causes, one message, because the cure is the same for both: the objects the PR squashed are not\n * in this repo under that name, so nothing here may archive them or reap a tree for them.\n */\n private notTheLandedTipNotice(base: string, tree: LandedTree, ref: PrIdentity): string {\n const found = tree.kind === LANDED_TREE_ABSENT\n ? ` ${base} is not in this repo at all\\n`\n : ` ${base} here → ${tree.localSha}\\n`;\n return '\\n ⚠️ Archive + worktree cleanup SKIPPED — nothing here holds the commit that landed:\\n' +\n found +\n ` PR #${ref.number} squashed → ${ref.headRefOid}\\n` +\n ' Archiving from here would tag the wrong objects under the right name, and the\\n' +\n ` merge-info record and (if any) the worktree holding ${base} live with the other tip.\\n` +\n ' Either this is a second clone of the repo — finish the bookkeeping in the clone that\\n' +\n ' posted the PR with `pnpm wp-cleanup` — or that tree has commits made after\\n' +\n ' `pnpm wp-finish-upsert-pr` ran, which the PR does not contain.\\n';\n }\n\n /**\n * What happens next — which is NOT the same act when you landed from a worktree.\n *\n * Landing from a linked worktree always used to leave a corpse: the merged branch is checked out\n * here, so `git branch -D` refuses, `wp-cleanup`'s branch pass spares it as in-use, and nothing\n * removed the worktree — so the pair sat there until branch-creation-guard hit its cap. #512 made\n * worktrees reapable and printed `cd <primary> && pnpm wp-cleanup`; that instruction was correct\n * and it was the most-skipped step in the flow, because the PR is already landed and the work\n * feels done.\n *\n * So the reap is no longer an instruction. This command still refuses to remove the directory it\n * is standing in — that rail is untouched — and instead HANDS THE REAP to a child process rooted\n * in the primary clone, which is a tree nobody is deleting. See LandedWorktreeReaper. When that\n * hand-off is not safely achievable the #512 notice is printed unchanged, because an honest\n * limitation beats a command that deletes its own working directory mid-run.\n */\n private async nextStep(repoRoot: string, tree: LandedTree, cwd: string): Promise<string> {\n const handoff: WorktreeReapHandoff | null\n = this.landedWorktree.plan(repoRoot, tree.worktree, cwd);\n if (handoff === null) return ' Next: `pnpm wp-cleanup` to delete the merged branch.\\n';\n if (!handoff.canReap) return this.landedWorktree.manualNotice(handoff);\n return this.landedWorktree.handOff(handoff);\n }\n\n /**\n * The landed branch's post-merge bookkeeping, in one place:\n * 1. ARCHIVE the pre-squash tip as `archive/<date>/<branch>` — the tag makes the original history\n * permanently restorable (`git checkout -b <branch> <tag>` gives back the exact objects) while\n * costing one ref, so the branch itself no longer has to survive as a `*PreMerge` husk that\n * counts toward the branch cap. See BranchArchiver for why a tag beats a patch or the reflog.\n * 2. PROMOTE `merge-info/staged/<feature>/` to `merge-info/merged/<feature>/` and rebuild\n * `index.json`, so `staged/` holds only branches that are still in flight.\n *\n * Never throws: the PR is already merged by the time we get here, and failing the command after a\n * successful merge would report a landed PR as a failure. Problems are reported in the recap.\n */\n private async archiveAndPromote(repoRoot: string, base: string, ref: PrIdentity, retention: string): Promise<string> {\n if (retention === BRANCH_RETENTION_KEEP) return ' Branch retention is \"keep\" — nothing archived.\\n';\n\n let line = '';\n let tag = '';\n if (retention === BRANCH_RETENTION_ARCHIVE_TAG) {\n const archive = await this.archiver.archive(repoRoot, base);\n tag = archive.tag;\n line = archive.ok\n ? ` Archived ${base} → ${archive.tag} (restore: ${this.archiver.restoreCommand(base, archive.tag)})\\n`\n : ` ⚠️ Could not archive ${base}: ${archive.error} — the branch was left alone.\\n`;\n }\n\n const feature = await this.aiBranchName.getFeatureName();\n const record = new ArchiveRecord(\n tag, await this.revParse(repoRoot, base), await this.revParse(repoRoot, 'origin/main'),\n Number(ref.number), new Date().toISOString(),\n );\n if (this.mergeInfoIndex.promoteToMerged(repoRoot, feature, record)) {\n line += ` merge-info: staged/${feature} → merged/${feature} (index.json rebuilt)\\n`;\n }\n return line;\n }\n\n // Best-effort sha of a ref — '' when it cannot resolve. Recorded in archive.json for provenance.\n private async revParse(repoRoot: string, ref: string): Promise<string> {\n const result = await this.git.run(['rev-parse', ref], repoRoot);\n return result.ok ? result.stdout.trim() : '';\n }\n\n // `git branch --show-current` in the invocation directory. Must succeed: a branch we cannot read is\n // not a selector to guess at.\n private async currentBranch(cwd: string): Promise<string> {\n const result = await this.git.run(['branch', '--show-current'], cwd);\n if (!result.ok) {\n throw new InformAiError(`Could not read the current branch in ${cwd} (git branch --show-current): ${result.stderr.trim()}`);\n }\n return result.stdout.trim();\n }\n\n /**\n * Everything landing needs about the PR, in ONE `gh` read: number, title, URL, DESCRIPTION and the\n * head sha GitHub is squashing. `null` when there is no open PR for this head branch.\n *\n * The TITLE comes from the PR itself, not summary.json, so the squash subject matches what a reviewer\n * approved even if summary.json was edited afterwards. The BODY is the gated commit body (see the\n * class doc). `headRefOid` is read BEFORE the merge, because it is what the bookkeeping check\n * compares against and the merge is what makes the branch's fate uninteresting to GitHub.\n */\n private async readPr(selector: string): Promise<PrIdentity | null> {\n const result = await this.processes.run(\n 'gh', ['pr', 'view', selector, '--json', 'number,title,url,body,headRefOid,headRefName'],\n );\n if (!result.ok) return null;\n return this.parsePr(result.stdout);\n }\n\n // `gh --json` output → PrIdentity. Malformed/absent JSON reads as \"no PR\", which the caller turns\n // into the same refusal a missing PR gets: both mean nothing here can be landed.\n private parsePr(stdout: string): PrIdentity | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unparseable gh output means \"no PR\", never a crash\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- gh's JSON is opaque until narrowed field-by-field below\n const raw = JSON.parse(stdout) as Record<string, unknown>;\n const number = typeof raw['number'] === 'number' ? String(raw['number']) : this.str(raw['number']);\n if (number === '') return null;\n // GitHub stores descriptions with CRLF. A commit body must not carry them, and the bytes are\n // otherwise identical to what finish rendered, so the line endings are normalized back here.\n const body = this.str(raw['body']).replace(/\\r\\n/g, '\\n').trim();\n return new PrIdentity(\n number, this.str(raw['title']), this.str(raw['url']), body === '' ? '' : body + '\\n',\n this.str(raw['headRefOid']), this.str(raw['headRefName']),\n );\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON field, narrowed to string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n\n// The open PR as GitHub holds it: its number, title, web URL, DESCRIPTION (= the gated commit body) and\n// the PAIR that identifies its tree locally — the head branch's name and the commit being squashed.\nclass PrIdentity {\n number: string;\n title: string;\n url: string;\n body: string;\n headRefOid: string;\n /**\n * The PR's head BRANCH. Required alongside `headRefOid` because neither half identifies a tree on its\n * own: the name is what a worktree list can be searched by, the sha is what makes a hit the right\n * one. It also frees `--pr <n>` from needing the operator to be standing anywhere in particular.\n */\n headRefName: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n number: string, title: string, url: string, body: string, headRefOid: string, headRefName: string,\n ) {\n this.number = number;\n this.title = title;\n this.url = url;\n this.body = body;\n this.headRefOid = headRefOid;\n this.headRefName = headRefName;\n }\n}\n\n/**\n * Data-only (per CLAUDE.md, classes for data): what the operator asked `wp-land-pr` to land.\n *\n * `prNumber` is '' for the zero-arg form — \"this branch's PR\" — which stays the shorthand the worker\n * uses. It is NOT an optional constructor parameter with a default at the call site: `wp-land-pr.ts`\n * builds exactly one of these from the parsed argv, so there is one spelling of the decision.\n */\nexport class LandPrRequest {\n /**\n * Was `--pr` on the command line at all? Kept SEPARATE from the value because `--pr` with no number\n * is a mistake, not a request to guess: collapsing the two would silently land whatever PR the\n * current directory's branch happens to have, which is the opposite of what the operator typed.\n */\n prFlagPresent: boolean;\n /** The `--pr <n>` value verbatim, or '' to infer the PR from the invocation directory's branch. */\n prNumber: string;\n\n constructor(prFlagPresent: boolean, prNumber: string) {\n this.prFlagPresent = prFlagPresent;\n this.prNumber = prNumber;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"land-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/land-pr-command.ts"],"names":[],"mappings":";;;;AAAA,8DAA2F;AAC3F,iEAA6D;AAC7D,0DAA2F;AAC3F,sEAAoH;AACpH,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,+EAA0E;AAC1E,2E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AAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;CACJ;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IACtB;;;;OAIG;IACH,aAAa,CAAU;IACvB,mGAAmG;IACnG,QAAQ,CAAS;IAEjB,YAAY,aAAsB,EAAE,QAAgB;QAChD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAdD,sCAcC","sourcesContent":["import { GitProcessApi, InformAiError, NativeProcessApi } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { RepoRootFinder, MERGE_MODE_AUTO, loadAndValidate } from '@webpieces/rules-config';\nimport { BranchArchiver, BRANCH_RETENTION_ARCHIVE_TAG, BRANCH_RETENTION_KEEP } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { LandedTicketResolver } from '../workflow/landed-ticket-resolver';\nimport { LandedTree, LandedTreeResolver, LANDED_TREE_ABSENT } from '../workflow/landed-tree-resolver';\nimport { LandedWorktreeReaper, WorktreeReapHandoff } from '../workflow/landed-worktree-reaper';\nimport { MergeBodyTempFile } from '../workflow/merge-body-temp-file';\nimport { ArchiveRecord, MergeInfoIndex } from '../workflow/merge-info-index';\nimport { MergeIntent, PrMerger } from '../workflow/pr-merger';\nimport { TicketReminder } from '../workflow/ticket-reminder';\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 set the squash SUBJECT to `<title> (#N)`\n * and cannot archive the pre-squash tip. So when a merge has to happen outside `wp-finish-upsert-pr`\n * (a mergeMode=NONE repo, or a PR whose checks were still running when finish ran), this is the command\n * that keeps main's history consistent and finishes the branch's bookkeeping.\n *\n * ─── Where the bytes come from: THE PR ITSELF ──────────────────────────────────────────────────────\n * `wp-finish-upsert-pr` renders ONE string and publishes it as the PR DESCRIPTION, and the full\n * dashboard lives in the PR's comments (see `pr-body-is-merge-body.spec.ts`, which pins that the\n * description and the merge body are one renderer's output). So the description IS the gated squash\n * body, held by GitHub, and landing reads it back with `gh pr view --json body`.\n *\n * THE BYTES THAT LAND ARE THE BYTES FINISH PRODUCED — that invariant is unchanged; what changed is that\n * GitHub, not this machine, is the thing holding them. That removes the whole machine-global receipt\n * store: a cache of a fact the remote already owns, which could only ever be missing, stale, or on the\n * wrong computer. Landing from a second clone, a fresh clone, or another machine entirely now just\n * works. See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n *\n * It still deliberately does NOT re-render the body: re-deriving it at land time would be a second\n * authoritative gate whose result nobody reads, and it could silently disagree with what was reviewed.\n *\n * ─── Two scopes, and only one of them is the tree's ────────────────────────────────────────────────\n * 1. THE MERGE, which belongs to the PR — and is therefore reachable from anywhere.\n * 2. THE BOOKKEEPING — archiving the pre-squash tip as `archive/<date>/<branch>`, promoting merge-info,\n * and reaping the landed worktree. That half belongs to the tree whose `<branch>` really is the\n * commit being squashed, and it must NOT be attempted from anywhere else: another clone's\n * `<branch>` is a different commit, so archiving it there would tag the wrong objects under the\n * right name.\n *\n * ─── WHICH tree that is, is a FACT — it is not \"the one I am standing in\" ──────────────────────────\n * That distinction used to be resolved from `process.cwd()`, and it was wrong twice over.\n *\n * It was wrong MECHANICALLY: `pnpm` hoists a bin's cwd to the workspace root, and a Claude Code agent\n * worktree lives at `<primary>/.claude/worktrees/agent-<id>` — INSIDE the primary clone — so pnpm walked\n * straight past it and `git branch --show-current` answered `main`. Landing a worktree PR, i.e. every\n * `/full-cycle` run, reported \"No open PR found for this branch\" for a PR that was open, and the #512\n * worktree reap was unreachable dead code. The invocation directory is now read from `INIT_CWD` (pnpm\n * exports the directory the human actually typed in) and given to BOTH the repo-root resolution and the\n * `git` call, so neither can be answered by the hoisted directory.\n *\n * And it was wrong in PRINCIPLE, which is the larger half: most of the time the `/full-cycle` subagent\n * lands its own PR, but many times it does not — CI was still running when it finished, it errored, or a\n * coordinator picks the work up an hour later, by which point that agent is gone and its worktree is a\n * directory nobody is standing in. So `--pr <n>` names the PR, and {@link LandedTreeResolver} finds its\n * tree by the pair `(headRefName, headRefOid)` — never by branch name alone. The reap target is the\n * worktree whose HEAD is the exact commit GitHub squashed, whichever directory the operator is in, and\n * when nothing local holds that commit the merge still happens and the bookkeeping is SKIPPED OUT LOUD.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class LandPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly prMerger: PrMerger,\n private readonly archiver: BranchArchiver,\n private readonly mergeInfoIndex: MergeInfoIndex,\n private readonly landedWorktree: LandedWorktreeReaper,\n private readonly bodyFile: MergeBodyTempFile,\n private readonly landedTree: LandedTreeResolver,\n private readonly git: GitProcessApi,\n private readonly processes: NativeProcessApi,\n private readonly landedTickets: LandedTicketResolver,\n private readonly ticketReminder: TicketReminder,\n ) {}\n\n /**\n * THE INVOCATION DIRECTORY, which is not `process.cwd()`.\n *\n * `pnpm` runs a workspace bin with its cwd hoisted to the workspace root and exports the directory\n * the operator was actually in as `INIT_CWD`. Every agent worktree is NESTED inside the primary\n * clone, so the hoist silently relocated this command into a different tree holding a different\n * branch — see the class doc. `process.cwd()` remains the answer when nothing set `INIT_CWD` (a\n * direct `node` invocation, or a spec), which is the case where the two are the same anyway.\n */\n private invocationCwd(): string {\n const init = process.env['INIT_CWD'] ?? '';\n return init !== '' ? init : process.cwd();\n }\n\n async run(request: LandPrRequest): Promise<void> {\n if (request.prFlagPresent && !/^\\d+$/.test(request.prNumber)) throw this.badPrNumber(request);\n const cwd = this.invocationCwd();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n // `--pr <n>` selects the PR outright; with no flag it is this branch's, read from the tree the\n // operator is really standing in.\n const selector = request.prNumber !== ''\n ? request.prNumber\n : this.branchNaming.baseBranchName(await this.currentBranch(cwd));\n\n const ref = await this.readPr(selector);\n if (ref === null) throw this.noSuchPr(request, selector);\n // The PR's OWN head branch, never the selector: with `--pr <n>` the operator named a number and\n // has said nothing about branches, and even in the zero-arg case GitHub is the authority on which\n // branch that PR is merging.\n const base = ref.headRefName !== '' ? ref.headRefName : selector;\n if (ref.body === '') throw this.emptyDescription(ref);\n const unfit = this.notFitForGitLog(ref.body);\n if (unfit !== '') throw this.descriptionUnfitForGitLog(ref, unfit);\n\n process.stdout.write('\\n' + SEP + `🚀 Landing PR #${ref.number}\\n` + SEP + '\\n');\n const mergeBodyFile = this.bodyFile.write(ref.body);\n\n const config = loadAndValidate(repoRoot).prGate;\n const policy = config.mergeMode;\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 //\n // `commanded: true` — running THIS command IS the intent to merge, so it is not gated on\n // pr-gate.mergeMode (a NONE repo runs this precisely to land one PR by hand). The real `policy`\n // travels alongside it rather than being replaced by a literal AUTO, so PrMerger's diagnostics\n // never assert a config value nobody set — that is exactly what used to print a CONFIG MISMATCH\n // about `mergeMode: AUTO` two lines above this command printing `mergeMode is NONE`.\n const outcome = await this.prMerger.merge(\n base, `${ref.title} (#${ref.number})`, mergeBodyFile, new MergeIntent(policy ?? '', true),\n );\n\n // Everything below the merge happens ONLY when it landed: a PR that did not land gets no archive,\n // no reap and no \"update your ticket\" reminder (issue #1456).\n const tree = outcome.merged ? await this.landedTree.resolve(repoRoot, base, ref.headRefOid) : null;\n // Read BEFORE the bookkeeping, which may reap the very worktree holding summary.json.\n const tickets = tree !== null\n ? this.landedTickets.resolve(this.summaryTree(repoRoot, tree), this.featureName(base), ref.body)\n : null;\n const bookkeeping = tree !== null\n ? await this.bookkeeping(repoRoot, base, ref, tree, config.landPr.branchRetention, cwd)\n : '';\n process.stdout.write(\n '\\n' + SEP + (outcome.merged ? '✅ Landed\\n' : 'ℹ️ Not landed yet\\n') + SEP + '\\n' +\n ` ${outcome.message}\\n` +\n bookkeeping +\n (policy === MERGE_MODE_AUTO\n ? ''\n : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr publishes PRs without attempting a merge.)\\n`) +\n '\\n',\n );\n // The same reminder wp-finish-upsert-pr printed when it posted the PR, repeated now that the work\n // has reached main — the stage-③ copy is many turns old by the time a PR lands (issue #1456).\n if (tickets !== null) process.stdout.write(this.ticketReminder.forLandedPr(ref.url, tickets) + '\\n');\n }\n\n /**\n * Where `wp-finish-upsert-pr` wrote summary.json: the linked worktree holding the landed commit when\n * there is one (a coordinator landing `--pr <n>` from the primary clone is not standing in it), else\n * the tree this command was invoked in.\n */\n private summaryTree(repoRoot: string, tree: LandedTree): string {\n return tree.worktree !== null ? tree.worktree.path : repoRoot;\n }\n\n // summary.json's directory is keyed by the branch with `/` flattened — AiBranchName.getFeatureName's\n // form, computed from the PR's head branch rather than from whatever directory pnpm hoisted us into.\n private featureName(base: string): string {\n return this.branchNaming.baseBranchName(base).replace(/\\//g, '-');\n }\n\n /**\n * `--pr` without a usable number. It REFUSES rather than falling back to the branch, because the\n * fallback would land a different PR from the one the operator was reaching for, and a squash into\n * main is not a place to guess. `--pr` bare and `--pr HEAD` land here alike.\n */\n private badPrNumber(request: LandPrRequest): InformAiError {\n const got = request.prNumber === '' ? 'nothing' : `\"${request.prNumber}\"`;\n return new InformAiError(\n '\\n' + SEP + '❌ --pr needs a PR NUMBER\\n' + SEP + '\\n' +\n `\\`--pr\\` was given ${got}. It takes the digits of one pull request:\\n` +\n ' pnpm wp-land-pr --pr 1087\\n\\n' +\n 'To land the PR of the branch you are standing on, pass no flag at all:\\n' +\n ' pnpm wp-land-pr\\n' + SEP);\n }\n\n /**\n * The refusal when `gh` has no open PR for what we asked about — and it must say WHICH question was\n * asked, because the two have different cures.\n *\n * The branch form used to be the only one, and it was the face of the cwd bug: run from an agent\n * worktree, pnpm's hoist made the branch read `main`, and an operator with an open PR in front of\n * them was told there was none. So the branch form now says what it looked up and where it read that\n * branch FROM, which is the one fact that makes a wrong answer recognisable as a wrong answer, and it\n * names the `--pr <n>` form that does not depend on the tree at all.\n */\n private noSuchPr(request: LandPrRequest, selector: string): InformAiError {\n if (request.prNumber !== '') {\n return new InformAiError(\n '\\n' + SEP + `❌ No open PR #${request.prNumber}\\n` + SEP + '\\n' +\n `\\`gh pr view ${request.prNumber}\\` found no OPEN pull request with that number.\\n` +\n 'If it is already merged, run `pnpm wp-cleanup` from the primary clone to finish the\\n' +\n 'branch and worktree bookkeeping. Otherwise check the number with `gh pr list`.\\n' + SEP);\n }\n return new InformAiError(\n '\\n' + SEP + '❌ No open PR found for this branch\\n' + SEP + '\\n' +\n `No open PR has head branch \"${selector}\", read from ${this.invocationCwd()}. Nothing to land.\\n` +\n 'If that is not the branch you expected, land it by number instead — it does not depend on\\n' +\n 'which directory you are standing in:\\n' +\n ' pnpm wp-land-pr --pr <n>\\n' +\n 'If the PR is already merged, run `pnpm wp-cleanup`.\\n' +\n 'If it was never posted, run the gated flow — it posts the PR AND writes the description\\n' +\n 'that becomes this commit body:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP);\n }\n\n /**\n * The refusal when the PR exists but its description is empty.\n *\n * This is the ONE remaining \"no gated body\" case, and it is now a property of the PR rather than of\n * this machine — which is why the cure is a single command with no human judgement call attached.\n * There is deliberately no `--fallback-title-only` escape any more: that flag existed because the\n * bytes could be on a DIFFERENT COMPUTER from the one landing, which cannot happen when GitHub holds\n * them. Re-running finish is always available, always correct, and lands the reviewed bytes.\n */\n private emptyDescription(ref: PrIdentity): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number} has an EMPTY description\\n` + SEP + '\\n' +\n 'The PR description IS the squash-commit body — `pnpm wp-finish-upsert-pr` renders one string\\n' +\n 'and publishes it as the description, and landing reads it straight back with\\n' +\n '`gh pr view --json body`. An empty description means the gated flow never published one\\n' +\n '(or a human cleared it), so there is nothing reviewed to land.\\n\\n' +\n 'Re-run the gated flow — it re-renders the description and re-posts it to this same PR:\\n' +\n ' pnpm wp-start-upsert-pr # update from main (3-point merge). No push, no build gate.\\n' +\n ' pnpm wp-review-upsert-pr # validate the merge, build gate, extract the diff, brief reviewers\\n' +\n ' # write summary.json at the path wp-review-upsert-pr prints\\n' +\n ' pnpm wp-finish-upsert-pr # build gate, dashboard, create/update the PR\\n' +\n 'Then re-run `pnpm wp-land-pr`.\\n' + SEP,\n );\n }\n\n /**\n * '' when the description is a compact gated body; otherwise the marker that proves it is not.\n *\n * This reads the SAME invariant `pr-body-is-merge-body.spec.ts` asserts from the other end: the\n * compact body \"contains nothing a plain-text git log cannot carry\" — no markdown heading, no table\n * pipe. It is therefore not a heuristic about what a dashboard looks like; it is the renderer's own\n * pinned property, checked against bytes that arrived from outside this process.\n *\n * WHY IT IS NEEDED, and why it is not a compatibility fallback: a PR posted by a release OLDER than\n * the surface swap still has the FULL DASHBOARD as its description. Measured on this repo,\n * 2026-08-07 — PR #613 (posted after the swap) has a description byte-identical to its squash body,\n * while PR #614 (still open, posted minutes before) begins `## 🚦 PR Gate Dashboard`. Landing that\n * one would dump a risk table into main, which is precisely the defect\n * `decisions/0004` § 4.1 warned about. So this REFUSES and names the one command that fixes it. It\n * never falls back, never rewrites, and never reaches for a second source of bytes.\n *\n * It keeps earning its place after the transition: nothing stops a human editing a PR description\n * in GitHub's textarea, and this is the only point between that edit and main's history.\n *\n * What it must NOT be read as is proof that the bytes did not come from `renderPrBody`. They can:\n * the compact body interpolates author text, and a `|` reaches that text from a TypeScript union, a\n * regex alternation or a quoted shell pipeline. `Dashboard.gitLogSafe` substitutes both markers at\n * the render exit so a freshly-rendered body no longer trips this — which is where that invariant\n * belongs, since the renderer is the only thing that can fix it without an extra CI cycle.\n */\n private notFitForGitLog(body: string): string {\n if (body.includes('##')) return '## (a markdown heading)';\n if (body.includes('|')) return '| (a markdown table)';\n return '';\n }\n\n /**\n * The refusal when the description is not the compact gated body.\n *\n * It names BOTH ways bytes get here, because naming only one sent readers down a path that did not\n * exist. It used to assert an old release as \"the usual cause\" and prescribe re-running finish — and\n * when the marker had come from AUTHOR TEXT instead (a `|` in a summary, from a TypeScript union or a\n * regex alternation), finish re-rendered the identical character from the unchanged `summary.json` and\n * landing refused again: a loop costing a CI cycle per turn, escapable only by guessing that one\n * character in your prose was the problem. `Dashboard.gitLogSafe` now substitutes both markers at the\n * render exit, so a freshly-rendered body cannot reach here at all — which leaves a HAND-EDITED\n * description and a genuinely old PR as the two remaining causes, and this says so.\n */\n private descriptionUnfitForGitLog(ref: PrIdentity, marker: string): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number}'s description is not a git-log commit body\\n` + SEP + '\\n' +\n `It contains ${marker}, which the compact body rendered by \\`pnpm wp-finish-upsert-pr\\` never\\n` +\n 'does — it substitutes both markers as it renders — so these bytes are not the gated summary,\\n' +\n 'and landing them would put a PR Gate Dashboard (or hand-written markdown) into main\\'s\\n' +\n 'history permanently.\\n\\n' +\n 'There are two causes, and they need different fixes:\\n\\n' +\n ' 1. The description was EDITED BY HAND on GitHub after finish posted it. Re-running finish\\n' +\n ' overwrites that edit with the compact body, so landing works.\\n' +\n ' 2. The PR was posted by a webpieces release OLDER than the one that made the description\\n' +\n ' the commit body, so it is still the full dashboard. The dashboard now lives in the PR\\'s\\n' +\n ' 1st comment instead, and re-running finish moves it there.\\n\\n' +\n `Either way the cure is the same, and it does NOT require removing ${marker.trim()} from your PR\\n` +\n 'summary text — a pipe or a heading in a summary is rendered safe, not rejected:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP,\n );\n }\n\n /**\n * The landed branch's post-merge bookkeeping — but ONLY when this tree's `<branch>` IS the commit\n * that was squashed.\n *\n * The fact being tested is \"does this working tree hold the objects the PR merged\", and the PR\n * answers it authoritatively: `headRefOid` is the tip GitHub squashed. A second clone's `<branch>`\n * is a different commit, so `archive/<date>/<branch>` there would tag the wrong tip under the right\n * name; `merge-info/staged/<feature>` lives in the posting tree's state, not ours; and the worktree\n * to reap is not this one. So the merge stands and the bookkeeping is declined ALOUD.\n *\n * This used to be read out of an `origin.json` sidecar recording which tree posted the PR. Comparing\n * SHAs is strictly better: it is a fact rather than a recorded claim, it needs no stored state, and\n * it is more precise in both directions — a second clone sitting on the SAME commit can safely\n * archive it, and a tree that has committed further work since finish ran correctly declines.\n */\n private async bookkeeping(\n repoRoot: string, base: string, ref: PrIdentity, tree: LandedTree, retention: string, cwd: string,\n ): Promise<string> {\n if (!tree.bookkeepingAllowed) return this.notTheLandedTipNotice(base, tree, ref);\n return await this.archiveAndPromote(repoRoot, base, ref, retention)\n + await this.nextStep(repoRoot, tree, cwd);\n }\n\n /**\n * What was skipped, why, and what the two SHAs are — so the reader can tell WHICH cause it was.\n *\n * Two causes, one message, because the cure is the same for both: the objects the PR squashed are not\n * in this repo under that name, so nothing here may archive them or reap a tree for them.\n */\n private notTheLandedTipNotice(base: string, tree: LandedTree, ref: PrIdentity): string {\n const found = tree.kind === LANDED_TREE_ABSENT\n ? ` ${base} is not in this repo at all\\n`\n : ` ${base} here → ${tree.localSha}\\n`;\n return '\\n ⚠️ Archive + worktree cleanup SKIPPED — nothing here holds the commit that landed:\\n' +\n found +\n ` PR #${ref.number} squashed → ${ref.headRefOid}\\n` +\n ' Archiving from here would tag the wrong objects under the right name, and the\\n' +\n ` merge-info record and (if any) the worktree holding ${base} live with the other tip.\\n` +\n ' Either this is a second clone of the repo — finish the bookkeeping in the clone that\\n' +\n ' posted the PR with `pnpm wp-cleanup` — or that tree has commits made after\\n' +\n ' `pnpm wp-finish-upsert-pr` ran, which the PR does not contain.\\n';\n }\n\n /**\n * What happens next — which is NOT the same act when you landed from a worktree.\n *\n * Landing from a linked worktree always used to leave a corpse: the merged branch is checked out\n * here, so `git branch -D` refuses, `wp-cleanup`'s branch pass spares it as in-use, and nothing\n * removed the worktree — so the pair sat there until branch-creation-guard hit its cap. #512 made\n * worktrees reapable and printed `cd <primary> && pnpm wp-cleanup`; that instruction was correct\n * and it was the most-skipped step in the flow, because the PR is already landed and the work\n * feels done.\n *\n * So the reap is no longer an instruction. This command still refuses to remove the directory it\n * is standing in — that rail is untouched — and instead HANDS THE REAP to a child process rooted\n * in the primary clone, which is a tree nobody is deleting. See LandedWorktreeReaper. When that\n * hand-off is not safely achievable the #512 notice is printed unchanged, because an honest\n * limitation beats a command that deletes its own working directory mid-run.\n */\n private async nextStep(repoRoot: string, tree: LandedTree, cwd: string): Promise<string> {\n const handoff: WorktreeReapHandoff | null\n = this.landedWorktree.plan(repoRoot, tree.worktree, cwd);\n if (handoff === null) return ' Next: `pnpm wp-cleanup` to delete the merged branch.\\n';\n if (!handoff.canReap) return this.landedWorktree.manualNotice(handoff);\n return this.landedWorktree.handOff(handoff);\n }\n\n /**\n * The landed branch's post-merge bookkeeping, in one place:\n * 1. ARCHIVE the pre-squash tip as `archive/<date>/<branch>` — the tag makes the original history\n * permanently restorable (`git checkout -b <branch> <tag>` gives back the exact objects) while\n * costing one ref, so the branch itself no longer has to survive as a `*PreMerge` husk that\n * counts toward the branch cap. See BranchArchiver for why a tag beats a patch or the reflog.\n * 2. PROMOTE `merge-info/staged/<feature>/` to `merge-info/merged/<feature>/` and rebuild\n * `index.json`, so `staged/` holds only branches that are still in flight.\n *\n * Never throws: the PR is already merged by the time we get here, and failing the command after a\n * successful merge would report a landed PR as a failure. Problems are reported in the recap.\n */\n private async archiveAndPromote(repoRoot: string, base: string, ref: PrIdentity, retention: string): Promise<string> {\n if (retention === BRANCH_RETENTION_KEEP) return ' Branch retention is \"keep\" — nothing archived.\\n';\n\n let line = '';\n let tag = '';\n if (retention === BRANCH_RETENTION_ARCHIVE_TAG) {\n const archive = await this.archiver.archive(repoRoot, base);\n tag = archive.tag;\n line = archive.ok\n ? ` Archived ${base} → ${archive.tag} (restore: ${this.archiver.restoreCommand(base, archive.tag)})\\n`\n : ` ⚠️ Could not archive ${base}: ${archive.error} — the branch was left alone.\\n`;\n }\n\n const feature = await this.aiBranchName.getFeatureName();\n const record = new ArchiveRecord(\n tag, await this.revParse(repoRoot, base), await this.revParse(repoRoot, 'origin/main'),\n Number(ref.number), new Date().toISOString(),\n );\n if (this.mergeInfoIndex.promoteToMerged(repoRoot, feature, record)) {\n line += ` merge-info: staged/${feature} → merged/${feature} (index.json rebuilt)\\n`;\n }\n return line;\n }\n\n // Best-effort sha of a ref — '' when it cannot resolve. Recorded in archive.json for provenance.\n private async revParse(repoRoot: string, ref: string): Promise<string> {\n const result = await this.git.run(['rev-parse', ref], repoRoot);\n return result.ok ? result.stdout.trim() : '';\n }\n\n // `git branch --show-current` in the invocation directory. Must succeed: a branch we cannot read is\n // not a selector to guess at.\n private async currentBranch(cwd: string): Promise<string> {\n const result = await this.git.run(['branch', '--show-current'], cwd);\n if (!result.ok) {\n throw new InformAiError(`Could not read the current branch in ${cwd} (git branch --show-current): ${result.stderr.trim()}`);\n }\n return result.stdout.trim();\n }\n\n /**\n * Everything landing needs about the PR, in ONE `gh` read: number, title, URL, DESCRIPTION and the\n * head sha GitHub is squashing. `null` when there is no open PR for this head branch.\n *\n * The TITLE comes from the PR itself, not summary.json, so the squash subject matches what a reviewer\n * approved even if summary.json was edited afterwards. The BODY is the gated commit body (see the\n * class doc). `headRefOid` is read BEFORE the merge, because it is what the bookkeeping check\n * compares against and the merge is what makes the branch's fate uninteresting to GitHub.\n */\n private async readPr(selector: string): Promise<PrIdentity | null> {\n const result = await this.processes.run(\n 'gh', ['pr', 'view', selector, '--json', 'number,title,url,body,headRefOid,headRefName'],\n );\n if (!result.ok) return null;\n return this.parsePr(result.stdout);\n }\n\n // `gh --json` output → PrIdentity. Malformed/absent JSON reads as \"no PR\", which the caller turns\n // into the same refusal a missing PR gets: both mean nothing here can be landed.\n private parsePr(stdout: string): PrIdentity | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unparseable gh output means \"no PR\", never a crash\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- gh's JSON is opaque until narrowed field-by-field below\n const raw = JSON.parse(stdout) as Record<string, unknown>;\n const number = typeof raw['number'] === 'number' ? String(raw['number']) : this.str(raw['number']);\n if (number === '') return null;\n // GitHub stores descriptions with CRLF. A commit body must not carry them, and the bytes are\n // otherwise identical to what finish rendered, so the line endings are normalized back here.\n const body = this.str(raw['body']).replace(/\\r\\n/g, '\\n').trim();\n return new PrIdentity(\n number, this.str(raw['title']), this.str(raw['url']), body === '' ? '' : body + '\\n',\n this.str(raw['headRefOid']), this.str(raw['headRefName']),\n );\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON field, narrowed to string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n\n// The open PR as GitHub holds it: its number, title, web URL, DESCRIPTION (= the gated commit body) and\n// the PAIR that identifies its tree locally — the head branch's name and the commit being squashed.\nclass PrIdentity {\n number: string;\n title: string;\n url: string;\n body: string;\n headRefOid: string;\n /**\n * The PR's head BRANCH. Required alongside `headRefOid` because neither half identifies a tree on its\n * own: the name is what a worktree list can be searched by, the sha is what makes a hit the right\n * one. It also frees `--pr <n>` from needing the operator to be standing anywhere in particular.\n */\n headRefName: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n number: string, title: string, url: string, body: string, headRefOid: string, headRefName: string,\n ) {\n this.number = number;\n this.title = title;\n this.url = url;\n this.body = body;\n this.headRefOid = headRefOid;\n this.headRefName = headRefName;\n }\n}\n\n/**\n * Data-only (per CLAUDE.md, classes for data): what the operator asked `wp-land-pr` to land.\n *\n * `prNumber` is '' for the zero-arg form — \"this branch's PR\" — which stays the shorthand the worker\n * uses. It is NOT an optional constructor parameter with a default at the call site: `wp-land-pr.ts`\n * builds exactly one of these from the parsed argv, so there is one spelling of the decision.\n */\nexport class LandPrRequest {\n /**\n * Was `--pr` on the command line at all? Kept SEPARATE from the value because `--pr` with no number\n * is a mistake, not a request to guess: collapsing the two would silently land whatever PR the\n * current directory's branch happens to have, which is the opposite of what the operator typed.\n */\n prFlagPresent: boolean;\n /** The `--pr <n>` value verbatim, or '' to infer the PR from the invocation directory's branch. */\n prNumber: string;\n\n constructor(prFlagPresent: boolean, prNumber: string) {\n this.prFlagPresent = prFlagPresent;\n this.prNumber = prNumber;\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MergeOutcome } from './pr-merger';
|
|
2
|
+
import { TicketReminder } from './ticket-reminder';
|
|
2
3
|
export declare class FinishBannerInput {
|
|
3
4
|
prNumber: string;
|
|
4
5
|
prUrl: string;
|
|
@@ -23,22 +24,14 @@ export declare class FinishBannerInput {
|
|
|
23
24
|
* is to be the last thing the AI says.
|
|
24
25
|
*/
|
|
25
26
|
export declare class FinishBanner {
|
|
27
|
+
private readonly tickets;
|
|
28
|
+
constructor(tickets: TicketReminder);
|
|
26
29
|
render(input: FinishBannerInput): string;
|
|
27
30
|
/**
|
|
28
|
-
* The "link this PR FROM its ticket" next action (issue #1453).
|
|
29
|
-
*
|
|
30
|
-
* The PR body's `Fixes <url>` / `Part of <url>` line links the PR TO its ticket; nothing links the
|
|
31
|
-
* ticket back to the PR, and on a tracker outside GitHub (Linear, Jira) nothing ever will unless the
|
|
32
|
-
* caller does it. One ticket often spans several PRs, so the reminder says to ADD the link, keeping the
|
|
33
|
-
* earlier ones — and it says plainly that webpieces updated no ticket, because it contacts no tracker.
|
|
34
|
-
*
|
|
35
|
-
* Printed only when the command holds the PR's REAL resolved URL — '' (a failed `gh pr create`, an
|
|
36
|
-
* unresolvable PR) prints nothing rather than a link that is not real. On a not-done outcome the PR
|
|
37
|
-
* still exists, so the reminder still applies, but it says the PR is NOT merged instead of implying a
|
|
38
|
-
* finished run.
|
|
31
|
+
* The "link this PR FROM its ticket" next action (issue #1453). Its wording lives in TicketReminder,
|
|
32
|
+
* which `wp-land-pr` shares (issue #1456), so the two commands cannot drift into two spellings.
|
|
39
33
|
*/
|
|
40
34
|
private ticketReminder;
|
|
41
|
-
private ticketList;
|
|
42
35
|
isDone(merge: MergeOutcome): boolean;
|
|
43
36
|
private header;
|
|
44
37
|
private behindHeader;
|
|
@@ -4,6 +4,7 @@ exports.FinishBanner = exports.FinishBannerInput = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const inversify_1 = require("inversify");
|
|
6
6
|
const pr_merger_1 = require("./pr-merger");
|
|
7
|
+
const ticket_reminder_1 = require("./ticket-reminder");
|
|
7
8
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
8
9
|
// Everything the closing block of wp-finish-upsert-pr needs to describe what actually happened. Both
|
|
9
10
|
// `prNumber` and `prUrl` are '' when the PR could not be resolved (e.g. `gh pr create` failed).
|
|
@@ -41,6 +42,10 @@ exports.FinishBannerInput = FinishBannerInput;
|
|
|
41
42
|
* is to be the last thing the AI says.
|
|
42
43
|
*/
|
|
43
44
|
let FinishBanner = class FinishBanner {
|
|
45
|
+
tickets;
|
|
46
|
+
constructor(tickets) {
|
|
47
|
+
this.tickets = tickets;
|
|
48
|
+
}
|
|
44
49
|
// The full closing recap: header keyed to the real outcome, the four things this command did, and —
|
|
45
50
|
// when the PR is not done — what must happen next.
|
|
46
51
|
render(input) {
|
|
@@ -55,37 +60,11 @@ let FinishBanner = class FinishBanner {
|
|
|
55
60
|
this.whatIsOwed(input) + '\n';
|
|
56
61
|
}
|
|
57
62
|
/**
|
|
58
|
-
* The "link this PR FROM its ticket" next action (issue #1453).
|
|
59
|
-
*
|
|
60
|
-
* The PR body's `Fixes <url>` / `Part of <url>` line links the PR TO its ticket; nothing links the
|
|
61
|
-
* ticket back to the PR, and on a tracker outside GitHub (Linear, Jira) nothing ever will unless the
|
|
62
|
-
* caller does it. One ticket often spans several PRs, so the reminder says to ADD the link, keeping the
|
|
63
|
-
* earlier ones — and it says plainly that webpieces updated no ticket, because it contacts no tracker.
|
|
64
|
-
*
|
|
65
|
-
* Printed only when the command holds the PR's REAL resolved URL — '' (a failed `gh pr create`, an
|
|
66
|
-
* unresolvable PR) prints nothing rather than a link that is not real. On a not-done outcome the PR
|
|
67
|
-
* still exists, so the reminder still applies, but it says the PR is NOT merged instead of implying a
|
|
68
|
-
* finished run.
|
|
63
|
+
* The "link this PR FROM its ticket" next action (issue #1453). Its wording lives in TicketReminder,
|
|
64
|
+
* which `wp-land-pr` shares (issue #1456), so the two commands cannot drift into two spellings.
|
|
69
65
|
*/
|
|
70
66
|
ticketReminder(input) {
|
|
71
|
-
|
|
72
|
-
return '';
|
|
73
|
-
const state = this.isDone(input.merge)
|
|
74
|
-
? ''
|
|
75
|
-
: ' (The PR is open but NOT merged — see step 4. The link is still correct to add now.)\n';
|
|
76
|
-
return '\n' + SEP +
|
|
77
|
-
`📌 NEXT ACTION — UPDATE YOUR TICKET (Linear, Jira, GitHub issue, or another tracker) with a link\n` +
|
|
78
|
-
` to this PR: ${input.prUrl}\n` + state +
|
|
79
|
-
' Keep the links to earlier PRs so the ticket lists every PR associated with the work.\n' +
|
|
80
|
-
' webpieces did NOT update any ticket — it contacts no tracker. Adding the link is yours to do.\n' +
|
|
81
|
-
this.ticketList(input.ticketUrls);
|
|
82
|
-
}
|
|
83
|
-
ticketList(ticketUrls) {
|
|
84
|
-
if (ticketUrls.length === 0) {
|
|
85
|
-
return ' summary.json names no addressesIssues ticket — use the ticket in your tracker this work belongs to.\n';
|
|
86
|
-
}
|
|
87
|
-
return ' Ticket(s) this PR addresses (summary.json addressesIssues):\n' +
|
|
88
|
-
ticketUrls.map((url) => ` ${url}\n`).join('');
|
|
67
|
+
return this.tickets.forPostedPr(input.prUrl, this.isDone(input.merge), input.ticketUrls);
|
|
89
68
|
}
|
|
90
69
|
// TRUE only for the outcomes where nothing further is owed: merged, queued behind green-able checks,
|
|
91
70
|
// or published without an automatic merge. Everything else — BEHIND, config mismatch, gh failure, no PR —
|
|
@@ -296,6 +275,7 @@ let FinishBanner = class FinishBanner {
|
|
|
296
275
|
};
|
|
297
276
|
exports.FinishBanner = FinishBanner;
|
|
298
277
|
exports.FinishBanner = FinishBanner = tslib_1.__decorate([
|
|
299
|
-
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
|
|
278
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
279
|
+
tslib_1.__metadata("design:paramtypes", [ticket_reminder_1.TicketReminder])
|
|
300
280
|
], FinishBanner);
|
|
301
281
|
//# sourceMappingURL=finish-banner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finish-banner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/finish-banner.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,2CAGqB;AAErB,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,qGAAqG;AACrG,gGAAgG;AAChG,4FAA4F;AAC5F,MAAa,iBAAiB;IAC1B,QAAQ,CAAS;IACjB,KAAK,CAAS;IACd,KAAK,CAAS;IACd,IAAI,CAAS;IACb,KAAK,CAAe;IACpB,UAAU,CAAW;IAErB,yDAAyD;IACzD,YAAY,QAAgB,EAAE,KAAa,EAAE,KAAa,EAAE,IAAY,EAAE,KAAmB,EAAE,UAAoB;QAC/G,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IA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;YAAE,OAAO,oEAAoE,CAAC;QAClI,IAAI,KAAK,CAAC,MAAM,KAAK,uCAA2B;YAAE,OAAO,8DAA8D,CAAC;QACxH,IAAI,KAAK,CAAC,QAAQ,EAAE;YAAE,OAAO,kEAAkE,CAAC;QAChG,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ,CAAA;AAlQY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,YAAY,CAkQxB","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport {\n MergeOutcome, MERGE_RESULT_MERGED, MERGE_RESULT_AUTO_QUEUED, MERGE_RESULT_LEFT_TO_HUMAN,\n MERGE_RESULT_BEHIND_CONFLICTING, MERGE_RESULT_BEHIND_UNKNOWN,\n} from './pr-merger';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Everything the closing block of wp-finish-upsert-pr needs to describe what actually happened. Both\n// `prNumber` and `prUrl` are '' when the PR could not be resolved (e.g. `gh pr create` failed).\n// `ticketUrls` are summary.json's `addressesIssues` URLs, in order — [] when it names none.\nexport class FinishBannerInput {\n prNumber: string;\n prUrl: string;\n title: string;\n base: string;\n merge: MergeOutcome;\n ticketUrls: string[];\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(prNumber: string, prUrl: string, title: string, base: string, merge: MergeOutcome, ticketUrls: string[]) {\n this.prNumber = prNumber;\n this.prUrl = prUrl;\n this.title = title;\n this.base = base;\n this.merge = merge;\n this.ticketUrls = ticketUrls;\n }\n}\n\n/**\n * Renders the closing block of `wp-finish-upsert-pr` — and it is the FRAME, not the merge message, that\n * this class exists to get right.\n *\n * PrMerger has long been honest in its `message`. The banner around it was not: it printed a hard-coded\n * `✅ PR finished` on every path, so a run whose merge failed still looked like a completed one at a\n * glance. The worst case is `mergeStateStatus: BEHIND` — unlike BLOCKED (waiting on checks), which\n * auto-merge resolves on its own, a BEHIND branch NEVER lands. Under a green checkmark, agents walked\n * away from stranded PRs. Three of them independently reported the output as untrustworthy.\n *\n * So the header is derived from `MergeOutcome.result`, and a not-done outcome is loud, distinct, and\n * carries the exact commands that fix it — including in the clickable-link directive, whose whole job\n * is to be the last thing the AI says.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class FinishBanner {\n // The full closing recap: header keyed to the real outcome, the four things this command did, and —\n // when the PR is not done — what must happen next.\n render(input: FinishBannerInput): string {\n const prNum = input.prNumber;\n return '\\n' + SEP + this.header(input.merge) + SEP + '\\n' +\n ` 1. validated the build gate (authoritative)\\n` +\n ` 2. ${prNum ? `wrote the gated body to PR #${prNum}` : 'composed the gated PR body'} titled: \"${input.title}\"\\n` +\n ` 3. force-pushed your work to origin/${input.base} (after the body, so CI reads the right token)\\n` +\n ` 4. ${input.merge.message}\\n` +\n ` You are on ${input.base} — same name as the remote branch and the PR head.\\n` +\n this.ticketReminder(input) +\n this.whatIsOwed(input) + '\\n';\n }\n\n /**\n * The \"link this PR FROM its ticket\" next action (issue #1453).\n *\n * The PR body's `Fixes <url>` / `Part of <url>` line links the PR TO its ticket; nothing links the\n * ticket back to the PR, and on a tracker outside GitHub (Linear, Jira) nothing ever will unless the\n * caller does it. One ticket often spans several PRs, so the reminder says to ADD the link, keeping the\n * earlier ones — and it says plainly that webpieces updated no ticket, because it contacts no tracker.\n *\n * Printed only when the command holds the PR's REAL resolved URL — '' (a failed `gh pr create`, an\n * unresolvable PR) prints nothing rather than a link that is not real. On a not-done outcome the PR\n * still exists, so the reminder still applies, but it says the PR is NOT merged instead of implying a\n * finished run.\n */\n private ticketReminder(input: FinishBannerInput): string {\n if (input.prUrl === '') return '';\n const state = this.isDone(input.merge)\n ? ''\n : ' (The PR is open but NOT merged — see step 4. The link is still correct to add now.)\\n';\n return '\\n' + SEP +\n `📌 NEXT ACTION — UPDATE YOUR TICKET (Linear, Jira, GitHub issue, or another tracker) with a link\\n` +\n ` to this PR: ${input.prUrl}\\n` + state +\n ' Keep the links to earlier PRs so the ticket lists every PR associated with the work.\\n' +\n ' webpieces did NOT update any ticket — it contacts no tracker. Adding the link is yours to do.\\n' +\n this.ticketList(input.ticketUrls);\n }\n\n private ticketList(ticketUrls: string[]): string {\n if (ticketUrls.length === 0) {\n return ' summary.json names no addressesIssues ticket — use the ticket in your tracker this work belongs to.\\n';\n }\n return ' Ticket(s) this PR addresses (summary.json addressesIssues):\\n' +\n ticketUrls.map((url: string): string => ` ${url}\\n`).join('');\n }\n\n // TRUE only for the outcomes where nothing further is owed: merged, queued behind green-able checks,\n // or published without an automatic merge. Everything else — BEHIND, config mismatch, gh failure, no PR —\n // is unfinished work, and the banner must not decorate it with a checkmark.\n isDone(merge: MergeOutcome): boolean {\n return merge.result === MERGE_RESULT_MERGED\n || merge.result === MERGE_RESULT_AUTO_QUEUED\n || merge.result === MERGE_RESULT_LEFT_TO_HUMAN;\n }\n\n private header(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_MERGED) return '✅ PR finished AND MERGED — here is exactly what I did\\n';\n if (merge.result === MERGE_RESULT_AUTO_QUEUED) {\n return '✅ PR finished — auto-merge is ON; it lands itself when the checks pass\\n';\n }\n if (merge.result === MERGE_RESULT_LEFT_TO_HUMAN) {\n return '✅ PR published — automatic merging by wp-finish-upsert-pr is disabled\\n';\n }\n // NOT \"PR NOT FINISHED\". Everything this command owns SUCCEEDED — the branch is pushed, the body\n // is written, the build gate is green. What happened is that another author landed on main\n // between our fetch and our push. Reporting that as the author's failure sent agents off\n // re-auditing their own diff and hunting build flakes for a race they did not cause.\n if (merge.isBehind()) return this.behindHeader(merge);\n return '⚠️ PR NOT FINISHED — the PR is up, but the merge did NOT happen\\n';\n }\n\n private behindHeader(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return '⏸️ PR IS UP AND GREEN — someone landed on main first, and it CONFLICTS with your work\\n';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return '⏸️ PR IS UP AND GREEN — GitHub has not finished computing mergeability yet\\n';\n }\n return '⏸️ PR IS UP AND GREEN — someone landed on main first (no conflicts with your work)\\n';\n }\n\n // The follow-up block. '' for a done outcome — a finished run should not invent chores.\n private whatIsOwed(input: FinishBannerInput): string {\n if (this.isDone(input.merge)) return this.doneNote(input.merge);\n if (input.merge.isBehind()) return this.behindRemedy(input);\n return '\\n' + SEP +\n ' ⚠️ DO NOT report this PR as done. The merge failed for the reason in step 4 above.\\n' +\n ' Fix that, then re-run: pnpm wp-finish-upsert-pr\\n' +\n ` Confirm for yourself: gh pr view ${input.prNumber === '' ? '<n>' : input.prNumber} --json mergeable,mergeStateStatus,state\\n`;\n }\n\n /**\n * The BEHIND follow-up. Two rules govern every word here.\n *\n * FIRST: the remedy is the FULL ①②③, never a shortcut. `gh pr update-branch` looks like the obvious\n * one-command fix and is a trap — it rewrites the REMOTE branch while every fork-point consumer\n * (`ForkPoint.resolveForkPoint`, `nx affected --base=$(git merge-base ...)`, the review diff) computes\n * against the LOCAL HEAD. That splits reality in two: stage ③ force-pushes local over the remote and\n * silently reverts it, the recorded hash points describe a tree that is no longer the PR head, and the\n * rebased tree never passes a build gate. Only ① moves the fork point AND records it; only ② rebuilds\n * and re-receipts against the new one.\n *\n * SECOND: it ASKS, it does not order. An imperative command list is what turns an agent into a loop —\n * it complies, main moves again, it complies again. Asking forces a stop at a human, which is the only\n * thing that reliably terminates a race we cannot win by retrying.\n */\n private behindRemedy(input: FinishBannerInput): string {\n const num = input.prNumber === '' ? '<n>' : input.prNumber;\n return '\\n' + SEP + this.behindSituation(input.merge) + '\\n' +\n ' ⚠️ STOP HERE AND ASK THE HUMAN. Do NOT run these yourself — if main keeps moving,\\n' +\n ' running them on your own is an infinite loop with a full build inside it.\\n\\n' +\n ' Ask, in your own words:\\n' +\n ` \"${this.behindAsk(input.merge)}\\n` +\n ` ${this.behindAskClose(input.merge)}\"\\n\\n` +\n ' Only once they say yes:\\n\\n' +\n ' pnpm wp-start-upsert-pr # 3-point merge from main — re-forks onto the new main\\n' +\n ' pnpm wp-review-upsert-pr # re-validates the merge + REBUILDS on the new fork point\\n' +\n ' pnpm wp-finish-upsert-pr # gated body + merge, now up to date\\n\\n' +\n ' Do NOT skip ②. It is the only stage that validates the new merge and rebuilds against\\n' +\n ' the new fork point; skipping it publishes a PR whose tree was never gated.\\n' +\n ' Do NOT reach for `gh pr update-branch`. It rewrites the REMOTE branch only, which stage\\n' +\n ' ③ then force-pushes over — and it lands a tree no build gate ever saw.\\n' +\n ` Verify independently, do not trust this banner:\\n` +\n ` gh pr view ${num} --json mergeable,mergeStateStatus,state\\n`;\n }\n\n // What is actually true right now, per kind. The CLEAN case gets the caveat that it may not even\n // matter: \"out of date\" only blocks a merge on repos that require branches be up to date.\n private behindSituation(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return ' Your PR is pushed, its body is written, and the build gate passed. Then someone\\n' +\n ' else landed on main, and their change CONFLICTS with yours — same lines. Real\\n' +\n ' resolution is owed, and if people keep landing ahead of you it genuinely repeats.\\n' +\n ' That is inherent to concurrent editing, not a bug and not something you did wrong.\\n';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return ' Your PR is pushed, its body is written, and the build gate passed. GitHub has not\\n' +\n ' finished computing mergeability yet (it is asynchronous, and we asked seconds after\\n' +\n ' the push), so we do NOT know whether this conflicts. Re-check before doing anything:\\n' +\n ' a few seconds later the answer is usually CLEAN and no work is owed at all.\\n';\n }\n return ' Your PR is pushed, its body is written, and the build gate passed. Someone else simply\\n' +\n ' landed on main first. There are NO conflicts — nobody touched your lines.\\n' +\n ' This may not even matter: \"out of date\" blocks a merge only on repos that REQUIRE\\n' +\n ' branches be up to date. If yours does not, this PR can merge as-is.\\n';\n }\n\n // The one sentence to put to the human, in their terms.\n private behindAsk(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return 'Someone beat me to landing on main and there are conflicts. We MUST run a\\n' +\n ' 3-point merge so I can resolve them properly.';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return 'Someone beat me to landing on main. GitHub has not said yet whether it\\n' +\n ' conflicts, so I have not touched anything.';\n }\n return 'Someone beat me to landing on main. There are no conflicts, so this is just\\n' +\n ' a re-sync — but it costs a full rebuild.';\n }\n\n // The actual question. UNKNOWN gets a DIFFERENT one: with mergeability still uncomputed, proposing a\n // full re-run is proposing work we cannot yet show is needed — a re-check is free and often ends it.\n private behindAskClose(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return 'Shall I re-check in a moment, or start the wp-*-upsert-pr process over?';\n }\n return 'May I start the wp-*-upsert-pr process over again?';\n }\n\n // A short, positive \"you are free to stop\" line for the two non-merged-but-fine outcomes, so an AI\n // reading a queued PR does not go hunting for work that is not owed.\n private doneNote(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_AUTO_QUEUED) {\n return ' Once the ticket links this PR, nothing else is owed: GitHub lands it when the checks go\\n' +\n ' green. You can stop here.\\n' +\n this.watchOffer();\n }\n if (merge.result === MERGE_RESULT_LEFT_TO_HUMAN) {\n return ' This command published the PR without attempting a merge.\\n' +\n ' This setting does not require additional authorization or override existing user instructions.\\n' +\n ' If landing was requested (including $full-cycle or /full-cycle), continue through the\\n' +\n ' required checks and run `pnpm wp-land-pr`.\\n' +\n '\\n' +\n ' ℹ️ Clicking Merge in the GitHub UI is CORRECT here and produces the right history. The\\n' +\n ' PR description IS the commit body this flow rendered — compact, non-green flags\\n' +\n ' only, with the PR link on top — and this flow keeps the two repo settings that copy\\n' +\n ' it into main pinned itself (squash_merge_commit_title=PR_TITLE,\\n' +\n ' squash_merge_commit_message=PR_BODY). There is nothing for you to configure.\\n' +\n ' (`pnpm wp-land-pr` lands the identical bytes from the CLI, and also archives the\\n' +\n ' pre-squash tip and reaps the worktree. Either route is fine.)\\n';\n }\n return '';\n }\n\n /**\n * The one OPTIONAL line about watching CI — offered, never instructed.\n *\n * \"You can stop here\" above stays the DEFAULT and is deliberately printed first: landing is the\n * developer's call, and several of this repo's workflows stop at a green PR on purpose. This exists\n * for the caller who has ALREADY decided to see it land, because the alternative they otherwise\n * reach for is an `echo .` keep-alive — measured at 18.3% of every token the fleet spent in the 24h\n * to 2026-09-07 (issue #874). Naming a blocking command is cheaper than the wait somebody was going\n * to do anyway; it is not a reason to wait.\n *\n * It names the EFFICIENT WAIT and the wasteful one, and says nothing about when to end a turn\n * (issue #902). An earlier cut led with \"END YOUR TURN\"; that is a turn-level judgement the caller is\n * better placed to make than this string is, and it contradicted `SUBAGENT_CURE` shipped in the same\n * release. `--watch` is named because it exists, it blocks, and it is never refused; what it lacks is\n * a bounded exit, so the harness kills it at 600s having printed nothing.\n */\n private watchOffer(): string {\n return ' (Optional — only if you have decided to watch it land, which nothing here asks you to do.\\n' +\n ' Be efficient with tokens: `pnpm wp-await-checks --pr <n>` BLOCKS in one call and returns\\n' +\n ' at 540s asking to be run again; `gh pr checks <n> --watch` also blocks but is killed at\\n' +\n ' the 600s silence ceiling. Do not send status checks every few seconds, and\\n' +\n ' never `echo` to keep a turn alive — a turn costs your whole context.)\\n';\n }\n\n /**\n * The closing AI directive: the resolved PR's number/title/URL and an instruction to end the\n * user-facing summary with EXACTLY `[#N title](url)` as the final line, nothing after it.\n *\n * The link text CARRIES the outcome. Ending on a bare cheerful link is exactly how a stranded PR got\n * reported as finished, and the directive says the link must be last — so the truth has to live\n * inside the link itself, not merely above it.\n *\n * '' when the PR could not be resolved: better to say nothing than to point at a link that is not real.\n */\n linkDirective(input: FinishBannerInput): string {\n if (input.prNumber === '' || input.prUrl === '') return '';\n const label = this.isDone(input.merge) ? input.title : `${input.title} — ${this.notDoneTag(input.merge)}`;\n const preamble = this.isDone(input.merge)\n ? ''\n : `AI — this PR is NOT done (${this.notDoneTag(input.merge)}). Your summary MUST say so plainly.\\n` +\n (input.merge.isBehind()\n ? `MUST END BY ASKING the human for permission to re-run the flow, and MUST NOT run any of\\n` +\n `the commands above until they answer. Say plainly that nothing they did caused this —\\n` +\n `another author landed on main first — and that the PR itself is pushed and gate-green.\\n\\n`\n : `MUST include the remedy commands printed above. Do not describe this run as complete.\\n\\n`);\n return SEP + `🔗 PR #${input.prNumber}: ${input.title}\\n ${input.prUrl}\\n\\n` + SEP + preamble +\n `AI — the LAST line of your summary to the user MUST be EXACTLY this clickable link, with\\n` +\n `NOTHING printed after it (no sign-off, no next steps, no blank commentary):\\n\\n` +\n ` [#${input.prNumber} ${label}](${input.prUrl})\\n\\n`;\n }\n\n // The tag rides INSIDE the clickable link, which the directive above forces to be the last line the\n // AI prints — so it is the one piece of wording guaranteed to reach the user. It says who is waiting\n // on whom: for every BEHIND flavour the answer is \"a human\", not \"more automation\".\n private notDoneTag(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) return 'NOT MERGED — main moved and it conflicts, needs your OK to re-sync';\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) return 'NOT MERGED — main moved, GitHub still computing mergeability';\n if (merge.isBehind()) return 'NOT MERGED — main moved (no conflicts), needs your OK to re-sync';\n return 'NOT MERGED';\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"finish-banner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/finish-banner.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,2CAGqB;AACrB,uDAAmD;AAEnD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,qGAAqG;AACrG,gGAAgG;AAChG,4FAA4F;AAC5F,MAAa,iBAAiB;IAC1B,QAAQ,CAAS;IACjB,KAAK,CAAS;IACd,KAAK,CAAS;IACd,IAAI,CAAS;IACb,KAAK,CAAe;IACpB,UAAU,CAAW;IAErB,yDAAyD;IACzD,YAAY,QAAgB,EAAE,KAAa,EAAE,KAAa,EAAE,IAAY,EAAE,KAAmB,EAAE,U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8BAAkB,CAAC,SAAS,CAAC;6CAEC,gCAAc;GAD3C,YAAY,CA0OxB","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport {\n MergeOutcome, MERGE_RESULT_MERGED, MERGE_RESULT_AUTO_QUEUED, MERGE_RESULT_LEFT_TO_HUMAN,\n MERGE_RESULT_BEHIND_CONFLICTING, MERGE_RESULT_BEHIND_UNKNOWN,\n} from './pr-merger';\nimport { TicketReminder } from './ticket-reminder';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Everything the closing block of wp-finish-upsert-pr needs to describe what actually happened. Both\n// `prNumber` and `prUrl` are '' when the PR could not be resolved (e.g. `gh pr create` failed).\n// `ticketUrls` are summary.json's `addressesIssues` URLs, in order — [] when it names none.\nexport class FinishBannerInput {\n prNumber: string;\n prUrl: string;\n title: string;\n base: string;\n merge: MergeOutcome;\n ticketUrls: string[];\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(prNumber: string, prUrl: string, title: string, base: string, merge: MergeOutcome, ticketUrls: string[]) {\n this.prNumber = prNumber;\n this.prUrl = prUrl;\n this.title = title;\n this.base = base;\n this.merge = merge;\n this.ticketUrls = ticketUrls;\n }\n}\n\n/**\n * Renders the closing block of `wp-finish-upsert-pr` — and it is the FRAME, not the merge message, that\n * this class exists to get right.\n *\n * PrMerger has long been honest in its `message`. The banner around it was not: it printed a hard-coded\n * `✅ PR finished` on every path, so a run whose merge failed still looked like a completed one at a\n * glance. The worst case is `mergeStateStatus: BEHIND` — unlike BLOCKED (waiting on checks), which\n * auto-merge resolves on its own, a BEHIND branch NEVER lands. Under a green checkmark, agents walked\n * away from stranded PRs. Three of them independently reported the output as untrustworthy.\n *\n * So the header is derived from `MergeOutcome.result`, and a not-done outcome is loud, distinct, and\n * carries the exact commands that fix it — including in the clickable-link directive, whose whole job\n * is to be the last thing the AI says.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class FinishBanner {\n constructor(private readonly tickets: TicketReminder) {}\n\n // The full closing recap: header keyed to the real outcome, the four things this command did, and —\n // when the PR is not done — what must happen next.\n render(input: FinishBannerInput): string {\n const prNum = input.prNumber;\n return '\\n' + SEP + this.header(input.merge) + SEP + '\\n' +\n ` 1. validated the build gate (authoritative)\\n` +\n ` 2. ${prNum ? `wrote the gated body to PR #${prNum}` : 'composed the gated PR body'} titled: \"${input.title}\"\\n` +\n ` 3. force-pushed your work to origin/${input.base} (after the body, so CI reads the right token)\\n` +\n ` 4. ${input.merge.message}\\n` +\n ` You are on ${input.base} — same name as the remote branch and the PR head.\\n` +\n this.ticketReminder(input) +\n this.whatIsOwed(input) + '\\n';\n }\n\n /**\n * The \"link this PR FROM its ticket\" next action (issue #1453). Its wording lives in TicketReminder,\n * which `wp-land-pr` shares (issue #1456), so the two commands cannot drift into two spellings.\n */\n private ticketReminder(input: FinishBannerInput): string {\n return this.tickets.forPostedPr(input.prUrl, this.isDone(input.merge), input.ticketUrls);\n }\n\n // TRUE only for the outcomes where nothing further is owed: merged, queued behind green-able checks,\n // or published without an automatic merge. Everything else — BEHIND, config mismatch, gh failure, no PR —\n // is unfinished work, and the banner must not decorate it with a checkmark.\n isDone(merge: MergeOutcome): boolean {\n return merge.result === MERGE_RESULT_MERGED\n || merge.result === MERGE_RESULT_AUTO_QUEUED\n || merge.result === MERGE_RESULT_LEFT_TO_HUMAN;\n }\n\n private header(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_MERGED) return '✅ PR finished AND MERGED — here is exactly what I did\\n';\n if (merge.result === MERGE_RESULT_AUTO_QUEUED) {\n return '✅ PR finished — auto-merge is ON; it lands itself when the checks pass\\n';\n }\n if (merge.result === MERGE_RESULT_LEFT_TO_HUMAN) {\n return '✅ PR published — automatic merging by wp-finish-upsert-pr is disabled\\n';\n }\n // NOT \"PR NOT FINISHED\". Everything this command owns SUCCEEDED — the branch is pushed, the body\n // is written, the build gate is green. What happened is that another author landed on main\n // between our fetch and our push. Reporting that as the author's failure sent agents off\n // re-auditing their own diff and hunting build flakes for a race they did not cause.\n if (merge.isBehind()) return this.behindHeader(merge);\n return '⚠️ PR NOT FINISHED — the PR is up, but the merge did NOT happen\\n';\n }\n\n private behindHeader(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return '⏸️ PR IS UP AND GREEN — someone landed on main first, and it CONFLICTS with your work\\n';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return '⏸️ PR IS UP AND GREEN — GitHub has not finished computing mergeability yet\\n';\n }\n return '⏸️ PR IS UP AND GREEN — someone landed on main first (no conflicts with your work)\\n';\n }\n\n // The follow-up block. '' for a done outcome — a finished run should not invent chores.\n private whatIsOwed(input: FinishBannerInput): string {\n if (this.isDone(input.merge)) return this.doneNote(input.merge);\n if (input.merge.isBehind()) return this.behindRemedy(input);\n return '\\n' + SEP +\n ' ⚠️ DO NOT report this PR as done. The merge failed for the reason in step 4 above.\\n' +\n ' Fix that, then re-run: pnpm wp-finish-upsert-pr\\n' +\n ` Confirm for yourself: gh pr view ${input.prNumber === '' ? '<n>' : input.prNumber} --json mergeable,mergeStateStatus,state\\n`;\n }\n\n /**\n * The BEHIND follow-up. Two rules govern every word here.\n *\n * FIRST: the remedy is the FULL ①②③, never a shortcut. `gh pr update-branch` looks like the obvious\n * one-command fix and is a trap — it rewrites the REMOTE branch while every fork-point consumer\n * (`ForkPoint.resolveForkPoint`, `nx affected --base=$(git merge-base ...)`, the review diff) computes\n * against the LOCAL HEAD. That splits reality in two: stage ③ force-pushes local over the remote and\n * silently reverts it, the recorded hash points describe a tree that is no longer the PR head, and the\n * rebased tree never passes a build gate. Only ① moves the fork point AND records it; only ② rebuilds\n * and re-receipts against the new one.\n *\n * SECOND: it ASKS, it does not order. An imperative command list is what turns an agent into a loop —\n * it complies, main moves again, it complies again. Asking forces a stop at a human, which is the only\n * thing that reliably terminates a race we cannot win by retrying.\n */\n private behindRemedy(input: FinishBannerInput): string {\n const num = input.prNumber === '' ? '<n>' : input.prNumber;\n return '\\n' + SEP + this.behindSituation(input.merge) + '\\n' +\n ' ⚠️ STOP HERE AND ASK THE HUMAN. Do NOT run these yourself — if main keeps moving,\\n' +\n ' running them on your own is an infinite loop with a full build inside it.\\n\\n' +\n ' Ask, in your own words:\\n' +\n ` \"${this.behindAsk(input.merge)}\\n` +\n ` ${this.behindAskClose(input.merge)}\"\\n\\n` +\n ' Only once they say yes:\\n\\n' +\n ' pnpm wp-start-upsert-pr # 3-point merge from main — re-forks onto the new main\\n' +\n ' pnpm wp-review-upsert-pr # re-validates the merge + REBUILDS on the new fork point\\n' +\n ' pnpm wp-finish-upsert-pr # gated body + merge, now up to date\\n\\n' +\n ' Do NOT skip ②. It is the only stage that validates the new merge and rebuilds against\\n' +\n ' the new fork point; skipping it publishes a PR whose tree was never gated.\\n' +\n ' Do NOT reach for `gh pr update-branch`. It rewrites the REMOTE branch only, which stage\\n' +\n ' ③ then force-pushes over — and it lands a tree no build gate ever saw.\\n' +\n ` Verify independently, do not trust this banner:\\n` +\n ` gh pr view ${num} --json mergeable,mergeStateStatus,state\\n`;\n }\n\n // What is actually true right now, per kind. The CLEAN case gets the caveat that it may not even\n // matter: \"out of date\" only blocks a merge on repos that require branches be up to date.\n private behindSituation(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return ' Your PR is pushed, its body is written, and the build gate passed. Then someone\\n' +\n ' else landed on main, and their change CONFLICTS with yours — same lines. Real\\n' +\n ' resolution is owed, and if people keep landing ahead of you it genuinely repeats.\\n' +\n ' That is inherent to concurrent editing, not a bug and not something you did wrong.\\n';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return ' Your PR is pushed, its body is written, and the build gate passed. GitHub has not\\n' +\n ' finished computing mergeability yet (it is asynchronous, and we asked seconds after\\n' +\n ' the push), so we do NOT know whether this conflicts. Re-check before doing anything:\\n' +\n ' a few seconds later the answer is usually CLEAN and no work is owed at all.\\n';\n }\n return ' Your PR is pushed, its body is written, and the build gate passed. Someone else simply\\n' +\n ' landed on main first. There are NO conflicts — nobody touched your lines.\\n' +\n ' This may not even matter: \"out of date\" blocks a merge only on repos that REQUIRE\\n' +\n ' branches be up to date. If yours does not, this PR can merge as-is.\\n';\n }\n\n // The one sentence to put to the human, in their terms.\n private behindAsk(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return 'Someone beat me to landing on main and there are conflicts. We MUST run a\\n' +\n ' 3-point merge so I can resolve them properly.';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return 'Someone beat me to landing on main. GitHub has not said yet whether it\\n' +\n ' conflicts, so I have not touched anything.';\n }\n return 'Someone beat me to landing on main. There are no conflicts, so this is just\\n' +\n ' a re-sync — but it costs a full rebuild.';\n }\n\n // The actual question. UNKNOWN gets a DIFFERENT one: with mergeability still uncomputed, proposing a\n // full re-run is proposing work we cannot yet show is needed — a re-check is free and often ends it.\n private behindAskClose(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return 'Shall I re-check in a moment, or start the wp-*-upsert-pr process over?';\n }\n return 'May I start the wp-*-upsert-pr process over again?';\n }\n\n // A short, positive \"you are free to stop\" line for the two non-merged-but-fine outcomes, so an AI\n // reading a queued PR does not go hunting for work that is not owed.\n private doneNote(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_AUTO_QUEUED) {\n return ' Once the ticket links this PR, nothing else is owed: GitHub lands it when the checks go\\n' +\n ' green. You can stop here.\\n' +\n this.watchOffer();\n }\n if (merge.result === MERGE_RESULT_LEFT_TO_HUMAN) {\n return ' This command published the PR without attempting a merge.\\n' +\n ' This setting does not require additional authorization or override existing user instructions.\\n' +\n ' If landing was requested (including $full-cycle or /full-cycle), continue through the\\n' +\n ' required checks and run `pnpm wp-land-pr`.\\n' +\n '\\n' +\n ' ℹ️ Clicking Merge in the GitHub UI is CORRECT here and produces the right history. The\\n' +\n ' PR description IS the commit body this flow rendered — compact, non-green flags\\n' +\n ' only, with the PR link on top — and this flow keeps the two repo settings that copy\\n' +\n ' it into main pinned itself (squash_merge_commit_title=PR_TITLE,\\n' +\n ' squash_merge_commit_message=PR_BODY). There is nothing for you to configure.\\n' +\n ' (`pnpm wp-land-pr` lands the identical bytes from the CLI, and also archives the\\n' +\n ' pre-squash tip and reaps the worktree. Either route is fine.)\\n';\n }\n return '';\n }\n\n /**\n * The one OPTIONAL line about watching CI — offered, never instructed.\n *\n * \"You can stop here\" above stays the DEFAULT and is deliberately printed first: landing is the\n * developer's call, and several of this repo's workflows stop at a green PR on purpose. This exists\n * for the caller who has ALREADY decided to see it land, because the alternative they otherwise\n * reach for is an `echo .` keep-alive — measured at 18.3% of every token the fleet spent in the 24h\n * to 2026-09-07 (issue #874). Naming a blocking command is cheaper than the wait somebody was going\n * to do anyway; it is not a reason to wait.\n *\n * It names the EFFICIENT WAIT and the wasteful one, and says nothing about when to end a turn\n * (issue #902). An earlier cut led with \"END YOUR TURN\"; that is a turn-level judgement the caller is\n * better placed to make than this string is, and it contradicted `SUBAGENT_CURE` shipped in the same\n * release. `--watch` is named because it exists, it blocks, and it is never refused; what it lacks is\n * a bounded exit, so the harness kills it at 600s having printed nothing.\n */\n private watchOffer(): string {\n return ' (Optional — only if you have decided to watch it land, which nothing here asks you to do.\\n' +\n ' Be efficient with tokens: `pnpm wp-await-checks --pr <n>` BLOCKS in one call and returns\\n' +\n ' at 540s asking to be run again; `gh pr checks <n> --watch` also blocks but is killed at\\n' +\n ' the 600s silence ceiling. Do not send status checks every few seconds, and\\n' +\n ' never `echo` to keep a turn alive — a turn costs your whole context.)\\n';\n }\n\n /**\n * The closing AI directive: the resolved PR's number/title/URL and an instruction to end the\n * user-facing summary with EXACTLY `[#N title](url)` as the final line, nothing after it.\n *\n * The link text CARRIES the outcome. Ending on a bare cheerful link is exactly how a stranded PR got\n * reported as finished, and the directive says the link must be last — so the truth has to live\n * inside the link itself, not merely above it.\n *\n * '' when the PR could not be resolved: better to say nothing than to point at a link that is not real.\n */\n linkDirective(input: FinishBannerInput): string {\n if (input.prNumber === '' || input.prUrl === '') return '';\n const label = this.isDone(input.merge) ? input.title : `${input.title} — ${this.notDoneTag(input.merge)}`;\n const preamble = this.isDone(input.merge)\n ? ''\n : `AI — this PR is NOT done (${this.notDoneTag(input.merge)}). Your summary MUST say so plainly.\\n` +\n (input.merge.isBehind()\n ? `MUST END BY ASKING the human for permission to re-run the flow, and MUST NOT run any of\\n` +\n `the commands above until they answer. Say plainly that nothing they did caused this —\\n` +\n `another author landed on main first — and that the PR itself is pushed and gate-green.\\n\\n`\n : `MUST include the remedy commands printed above. Do not describe this run as complete.\\n\\n`);\n return SEP + `🔗 PR #${input.prNumber}: ${input.title}\\n ${input.prUrl}\\n\\n` + SEP + preamble +\n `AI — the LAST line of your summary to the user MUST be EXACTLY this clickable link, with\\n` +\n `NOTHING printed after it (no sign-off, no next steps, no blank commentary):\\n\\n` +\n ` [#${input.prNumber} ${label}](${input.prUrl})\\n\\n`;\n }\n\n // The tag rides INSIDE the clickable link, which the directive above forces to be the last line the\n // AI prints — so it is the one piece of wording guaranteed to reach the user. It says who is waiting\n // on whom: for every BEHIND flavour the answer is \"a human\", not \"more automation\".\n private notDoneTag(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) return 'NOT MERGED — main moved and it conflicts, needs your OK to re-sync';\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) return 'NOT MERGED — main moved, GitHub still computing mergeability';\n if (merge.isBehind()) return 'NOT MERGED — main moved (no conflicts), needs your OK to re-sync';\n return 'NOT MERGED';\n }\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ReviewJsonService } from '@webpieces/rules-config';
|
|
2
|
+
import { LandedTickets } from './ticket-reminder';
|
|
3
|
+
/**
|
|
4
|
+
* Recovers, at LAND time, the tickets a PR addresses — so `wp-land-pr`'s "update your ticket" reminder
|
|
5
|
+
* (issue #1456) can name them. It never invents one: a URL is printed only when it was found written down.
|
|
6
|
+
*
|
|
7
|
+
* Two sources, in order:
|
|
8
|
+
* 1. summary.json's `addressesIssues`, when the tree that ran `wp-finish-upsert-pr` still holds it
|
|
9
|
+
* (finish leaves it in place). It is the author's own statement, with `closesIssue` on every entry.
|
|
10
|
+
* 2. The PR body's `Fixes <url>` / `Part of <url>` lines, which finish rendered FROM that array — the
|
|
11
|
+
* fallback when landing runs from a tree that never had the summary (a second clone, another machine).
|
|
12
|
+
*
|
|
13
|
+
* Neither yields anything → {@link TICKET_SOURCE_NONE}, and the reminder points the caller at their own
|
|
14
|
+
* tracker instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare class LandedTicketResolver {
|
|
17
|
+
private readonly reviewJson;
|
|
18
|
+
private static readonly BODY_LINE;
|
|
19
|
+
constructor(reviewJson: ReviewJsonService);
|
|
20
|
+
/**
|
|
21
|
+
* `treeRoot` is the tree that holds the landed commit (where finish wrote summary.json), `featureName`
|
|
22
|
+
* the PR head branch in summary.json's directory form, and `prBody` the description GitHub holds.
|
|
23
|
+
*/
|
|
24
|
+
resolve(treeRoot: string, featureName: string, prBody: string): LandedTickets;
|
|
25
|
+
private fromBody;
|
|
26
|
+
/**
|
|
27
|
+
* The well-formed `addressesIssues` entries, or [] when the file is gone or unreadable. Lenient on
|
|
28
|
+
* purpose: the PR is ALREADY merged, so this only decides which URLs a reminder names — it is not the
|
|
29
|
+
* gate that validates summary.json (finish already did that), and failing here would report a landed
|
|
30
|
+
* PR as a failure. An unreadable file falls through to the PR body, which holds the same tickets.
|
|
31
|
+
*/
|
|
32
|
+
private fromSummary;
|
|
33
|
+
private entry;
|
|
34
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var LandedTicketResolver_1;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.LandedTicketResolver = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
+
const rules_config_1 = require("@webpieces/rules-config");
|
|
8
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
9
|
+
const inversify_1 = require("inversify");
|
|
10
|
+
const ticket_reminder_1 = require("./ticket-reminder");
|
|
11
|
+
/**
|
|
12
|
+
* Recovers, at LAND time, the tickets a PR addresses — so `wp-land-pr`'s "update your ticket" reminder
|
|
13
|
+
* (issue #1456) can name them. It never invents one: a URL is printed only when it was found written down.
|
|
14
|
+
*
|
|
15
|
+
* Two sources, in order:
|
|
16
|
+
* 1. summary.json's `addressesIssues`, when the tree that ran `wp-finish-upsert-pr` still holds it
|
|
17
|
+
* (finish leaves it in place). It is the author's own statement, with `closesIssue` on every entry.
|
|
18
|
+
* 2. The PR body's `Fixes <url>` / `Part of <url>` lines, which finish rendered FROM that array — the
|
|
19
|
+
* fallback when landing runs from a tree that never had the summary (a second clone, another machine).
|
|
20
|
+
*
|
|
21
|
+
* Neither yields anything → {@link TICKET_SOURCE_NONE}, and the reminder points the caller at their own
|
|
22
|
+
* tracker instead.
|
|
23
|
+
*/
|
|
24
|
+
let LandedTicketResolver = class LandedTicketResolver {
|
|
25
|
+
static { LandedTicketResolver_1 = this; }
|
|
26
|
+
reviewJson;
|
|
27
|
+
// A whole line `Fixes <url>` or `Part of <url>` — exactly the shape IssueReferences.blockLines renders.
|
|
28
|
+
static BODY_LINE = /^(Fixes|Part of) (https:\/\/\S+)$/;
|
|
29
|
+
constructor(reviewJson) {
|
|
30
|
+
this.reviewJson = reviewJson;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `treeRoot` is the tree that holds the landed commit (where finish wrote summary.json), `featureName`
|
|
34
|
+
* the PR head branch in summary.json's directory form, and `prBody` the description GitHub holds.
|
|
35
|
+
*/
|
|
36
|
+
resolve(treeRoot, featureName, prBody) {
|
|
37
|
+
const fromSummary = this.fromSummary(this.reviewJson.summaryJsonPath(treeRoot, featureName));
|
|
38
|
+
if (fromSummary.length > 0)
|
|
39
|
+
return new ticket_reminder_1.LandedTickets(fromSummary, ticket_reminder_1.TICKET_SOURCE_SUMMARY);
|
|
40
|
+
const fromBody = this.fromBody(prBody);
|
|
41
|
+
if (fromBody.length > 0)
|
|
42
|
+
return new ticket_reminder_1.LandedTickets(fromBody, ticket_reminder_1.TICKET_SOURCE_PR_BODY);
|
|
43
|
+
return new ticket_reminder_1.LandedTickets([], ticket_reminder_1.TICKET_SOURCE_NONE);
|
|
44
|
+
}
|
|
45
|
+
fromBody(body) {
|
|
46
|
+
const links = [];
|
|
47
|
+
for (const line of body.split('\n')) {
|
|
48
|
+
const match = LandedTicketResolver_1.BODY_LINE.exec(line.trim());
|
|
49
|
+
if (match === null)
|
|
50
|
+
continue;
|
|
51
|
+
if (links.some((link) => link.url === match[2]))
|
|
52
|
+
continue;
|
|
53
|
+
links.push(new ticket_reminder_1.TicketLink(match[2], match[1] === 'Fixes'));
|
|
54
|
+
}
|
|
55
|
+
return links;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The well-formed `addressesIssues` entries, or [] when the file is gone or unreadable. Lenient on
|
|
59
|
+
* purpose: the PR is ALREADY merged, so this only decides which URLs a reminder names — it is not the
|
|
60
|
+
* gate that validates summary.json (finish already did that), and failing here would report a landed
|
|
61
|
+
* PR as a failure. An unreadable file falls through to the PR body, which holds the same tickets.
|
|
62
|
+
*/
|
|
63
|
+
fromSummary(file) {
|
|
64
|
+
if (!fs.existsSync(file))
|
|
65
|
+
return [];
|
|
66
|
+
// webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable summary.json falls back to the PR body, by design
|
|
67
|
+
// eslint-disable-next-line @webpieces/no-unmanaged-exceptions
|
|
68
|
+
try {
|
|
69
|
+
// webpieces-disable no-any-unknown -- summary.json is opaque until narrowed field-by-field below
|
|
70
|
+
const raw = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
71
|
+
const issues = raw['addressesIssues'];
|
|
72
|
+
// webpieces-disable no-any-unknown -- one opaque JSON array element, narrowed by entry()
|
|
73
|
+
return Array.isArray(issues) ? issues.flatMap((item) => this.entry(item)) : [];
|
|
74
|
+
// webpieces-disable catch-must-propagate -- the PR is already merged; an unparseable summary.json only means the reminder reads the PR body's ticket lines instead
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
const error = (0, to_error_1.toError)(err);
|
|
78
|
+
void error;
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// webpieces-disable no-any-unknown -- one opaque JSON array element, narrowed here
|
|
83
|
+
entry(entry) {
|
|
84
|
+
if (typeof entry !== 'object' || entry === null)
|
|
85
|
+
return [];
|
|
86
|
+
// webpieces-disable no-any-unknown -- opaque JSON object; each key is narrowed below
|
|
87
|
+
const record = entry;
|
|
88
|
+
const url = record['url'];
|
|
89
|
+
const closes = record['closesIssue'];
|
|
90
|
+
if (typeof url !== 'string' || !url.trim().startsWith('https://') || typeof closes !== 'boolean')
|
|
91
|
+
return [];
|
|
92
|
+
return [new ticket_reminder_1.TicketLink(url.trim(), closes)];
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.LandedTicketResolver = LandedTicketResolver;
|
|
96
|
+
exports.LandedTicketResolver = LandedTicketResolver = LandedTicketResolver_1 = tslib_1.__decorate([
|
|
97
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
98
|
+
tslib_1.__metadata("design:paramtypes", [rules_config_1.ReviewJsonService])
|
|
99
|
+
], LandedTicketResolver);
|
|
100
|
+
//# sourceMappingURL=landed-ticket-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"landed-ticket-resolver.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/landed-ticket-resolver.ts"],"names":[],"mappings":";;;;;AAAA,+CAAyB;AACzB,0D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AAQ,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,OAAO,MAAM,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QAC5G,OAAO,CAAC,IAAI,4BAAU,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC;;AA9DQ,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAKI,gCAAiB;GAJjD,oBAAoB,CA+DhC","sourcesContent":["import * as fs from 'fs';\nimport { ReviewJsonService } from '@webpieces/rules-config';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport {\n LandedTickets, TicketLink, TICKET_SOURCE_NONE, TICKET_SOURCE_PR_BODY, TICKET_SOURCE_SUMMARY,\n} from './ticket-reminder';\n\n/**\n * Recovers, at LAND time, the tickets a PR addresses — so `wp-land-pr`'s \"update your ticket\" reminder\n * (issue #1456) can name them. It never invents one: a URL is printed only when it was found written down.\n *\n * Two sources, in order:\n * 1. summary.json's `addressesIssues`, when the tree that ran `wp-finish-upsert-pr` still holds it\n * (finish leaves it in place). It is the author's own statement, with `closesIssue` on every entry.\n * 2. The PR body's `Fixes <url>` / `Part of <url>` lines, which finish rendered FROM that array — the\n * fallback when landing runs from a tree that never had the summary (a second clone, another machine).\n *\n * Neither yields anything → {@link TICKET_SOURCE_NONE}, and the reminder points the caller at their own\n * tracker instead.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class LandedTicketResolver {\n // A whole line `Fixes <url>` or `Part of <url>` — exactly the shape IssueReferences.blockLines renders.\n private static readonly BODY_LINE = /^(Fixes|Part of) (https:\\/\\/\\S+)$/;\n\n constructor(private readonly reviewJson: ReviewJsonService) {}\n\n /**\n * `treeRoot` is the tree that holds the landed commit (where finish wrote summary.json), `featureName`\n * the PR head branch in summary.json's directory form, and `prBody` the description GitHub holds.\n */\n resolve(treeRoot: string, featureName: string, prBody: string): LandedTickets {\n const fromSummary = this.fromSummary(this.reviewJson.summaryJsonPath(treeRoot, featureName));\n if (fromSummary.length > 0) return new LandedTickets(fromSummary, TICKET_SOURCE_SUMMARY);\n const fromBody = this.fromBody(prBody);\n if (fromBody.length > 0) return new LandedTickets(fromBody, TICKET_SOURCE_PR_BODY);\n return new LandedTickets([], TICKET_SOURCE_NONE);\n }\n\n private fromBody(body: string): TicketLink[] {\n const links: TicketLink[] = [];\n for (const line of body.split('\\n')) {\n const match = LandedTicketResolver.BODY_LINE.exec(line.trim());\n if (match === null) continue;\n if (links.some((link: TicketLink): boolean => link.url === match[2])) continue;\n links.push(new TicketLink(match[2], match[1] === 'Fixes'));\n }\n return links;\n }\n\n /**\n * The well-formed `addressesIssues` entries, or [] when the file is gone or unreadable. Lenient on\n * purpose: the PR is ALREADY merged, so this only decides which URLs a reminder names — it is not the\n * gate that validates summary.json (finish already did that), and failing here would report a landed\n * PR as a failure. An unreadable file falls through to the PR body, which holds the same tickets.\n */\n private fromSummary(file: string): TicketLink[] {\n if (!fs.existsSync(file)) return [];\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable summary.json falls back to the PR body, by design\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- summary.json is opaque until narrowed field-by-field below\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<string, unknown>;\n const issues = raw['addressesIssues'];\n // webpieces-disable no-any-unknown -- one opaque JSON array element, narrowed by entry()\n return Array.isArray(issues) ? issues.flatMap((item: unknown): TicketLink[] => this.entry(item)) : [];\n // webpieces-disable catch-must-propagate -- the PR is already merged; an unparseable summary.json only means the reminder reads the PR body's ticket lines instead\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return [];\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON array element, narrowed here\n private entry(entry: unknown): TicketLink[] {\n if (typeof entry !== 'object' || entry === null) return [];\n // webpieces-disable no-any-unknown -- opaque JSON object; each key is narrowed below\n const record = entry as Record<string, unknown>;\n const url = record['url'];\n const closes = record['closesIssue'];\n if (typeof url !== 'string' || !url.trim().startsWith('https://') || typeof closes !== 'boolean') return [];\n return [new TicketLink(url.trim(), closes)];\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** The tickets came from summary.json's `addressesIssues` (still on disk at land time). */
|
|
2
|
+
export declare const TICKET_SOURCE_SUMMARY = "summary.json addressesIssues";
|
|
3
|
+
/** The tickets came from the PR body's rendered `Fixes <url>` / `Part of <url>` lines. */
|
|
4
|
+
export declare const TICKET_SOURCE_PR_BODY = "the PR body's \"Fixes <url>\" / \"Part of <url>\" lines";
|
|
5
|
+
/** No ticket URL could be recovered from either place. */
|
|
6
|
+
export declare const TICKET_SOURCE_NONE = "none";
|
|
7
|
+
/**
|
|
8
|
+
* Data-only: one ticket a PR addresses, and whether that PR finishes it. `closesIssue` is true for a
|
|
9
|
+
* `Fixes <url>` (this PR completes the ticket) and false for a `Part of <url>` (more PRs are owed).
|
|
10
|
+
*/
|
|
11
|
+
export declare class TicketLink {
|
|
12
|
+
url: string;
|
|
13
|
+
closesIssue: boolean;
|
|
14
|
+
constructor(url: string, closesIssue: boolean);
|
|
15
|
+
}
|
|
16
|
+
/** Data-only: the tickets a LANDED PR addresses, and where they were read from (a TICKET_SOURCE_*). */
|
|
17
|
+
export declare class LandedTickets {
|
|
18
|
+
links: TicketLink[];
|
|
19
|
+
source: string;
|
|
20
|
+
constructor(links: TicketLink[], source: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* THE one wording of the "link this PR FROM its ticket" next action — printed by `wp-finish-upsert-pr`
|
|
24
|
+
* after it posts or updates a PR (issue #1453) and again by `wp-land-pr` after it lands one (issue #1456).
|
|
25
|
+
*
|
|
26
|
+
* The PR body's `Fixes <url>` / `Part of <url>` line links the PR TO its ticket; nothing links the ticket
|
|
27
|
+
* back to the PR, and on a tracker outside GitHub (Linear, Jira) nothing ever will unless the caller does
|
|
28
|
+
* it. One ticket often spans several PRs, so the reminder says to ADD the link, keeping the earlier ones —
|
|
29
|
+
* and it says plainly that webpieces updated no ticket, because it contacts no tracker.
|
|
30
|
+
*
|
|
31
|
+
* Landing repeats it because the stage-③ reminder is printed many turns before the PR reaches main, and
|
|
32
|
+
* by then it has usually been forgotten. Landing is also the moment a Linear or Jira ticket should move
|
|
33
|
+
* to Done, which a reminder printed while the PR is still open cannot say.
|
|
34
|
+
*
|
|
35
|
+
* Both entry points print nothing for a PR URL of '' — better no reminder than a link that is not real.
|
|
36
|
+
*/
|
|
37
|
+
export declare class TicketReminder {
|
|
38
|
+
/**
|
|
39
|
+
* The stage-③ form. `done` is FinishBanner.isDone of the merge outcome: when false the PR exists but
|
|
40
|
+
* is not merged, so the reminder says so instead of implying a finished run.
|
|
41
|
+
*/
|
|
42
|
+
forPostedPr(prUrl: string, done: boolean, ticketUrls: string[]): string;
|
|
43
|
+
/** The `wp-land-pr` form: the PR is merged, so the wording is LANDED and covers moving to Done. */
|
|
44
|
+
forLandedPr(prUrl: string, tickets: LandedTickets): string;
|
|
45
|
+
private heading;
|
|
46
|
+
private obligations;
|
|
47
|
+
private landedList;
|
|
48
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TicketReminder = exports.LandedTickets = exports.TicketLink = exports.TICKET_SOURCE_NONE = exports.TICKET_SOURCE_PR_BODY = exports.TICKET_SOURCE_SUMMARY = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const inversify_1 = require("inversify");
|
|
6
|
+
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
7
|
+
/** The tickets came from summary.json's `addressesIssues` (still on disk at land time). */
|
|
8
|
+
exports.TICKET_SOURCE_SUMMARY = 'summary.json addressesIssues';
|
|
9
|
+
/** The tickets came from the PR body's rendered `Fixes <url>` / `Part of <url>` lines. */
|
|
10
|
+
exports.TICKET_SOURCE_PR_BODY = 'the PR body\'s "Fixes <url>" / "Part of <url>" lines';
|
|
11
|
+
/** No ticket URL could be recovered from either place. */
|
|
12
|
+
exports.TICKET_SOURCE_NONE = 'none';
|
|
13
|
+
/**
|
|
14
|
+
* Data-only: one ticket a PR addresses, and whether that PR finishes it. `closesIssue` is true for a
|
|
15
|
+
* `Fixes <url>` (this PR completes the ticket) and false for a `Part of <url>` (more PRs are owed).
|
|
16
|
+
*/
|
|
17
|
+
class TicketLink {
|
|
18
|
+
url;
|
|
19
|
+
closesIssue;
|
|
20
|
+
constructor(url, closesIssue) {
|
|
21
|
+
this.url = url;
|
|
22
|
+
this.closesIssue = closesIssue;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.TicketLink = TicketLink;
|
|
26
|
+
/** Data-only: the tickets a LANDED PR addresses, and where they were read from (a TICKET_SOURCE_*). */
|
|
27
|
+
class LandedTickets {
|
|
28
|
+
links;
|
|
29
|
+
source;
|
|
30
|
+
constructor(links, source) {
|
|
31
|
+
this.links = links;
|
|
32
|
+
this.source = source;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.LandedTickets = LandedTickets;
|
|
36
|
+
/**
|
|
37
|
+
* THE one wording of the "link this PR FROM its ticket" next action — printed by `wp-finish-upsert-pr`
|
|
38
|
+
* after it posts or updates a PR (issue #1453) and again by `wp-land-pr` after it lands one (issue #1456).
|
|
39
|
+
*
|
|
40
|
+
* The PR body's `Fixes <url>` / `Part of <url>` line links the PR TO its ticket; nothing links the ticket
|
|
41
|
+
* back to the PR, and on a tracker outside GitHub (Linear, Jira) nothing ever will unless the caller does
|
|
42
|
+
* it. One ticket often spans several PRs, so the reminder says to ADD the link, keeping the earlier ones —
|
|
43
|
+
* and it says plainly that webpieces updated no ticket, because it contacts no tracker.
|
|
44
|
+
*
|
|
45
|
+
* Landing repeats it because the stage-③ reminder is printed many turns before the PR reaches main, and
|
|
46
|
+
* by then it has usually been forgotten. Landing is also the moment a Linear or Jira ticket should move
|
|
47
|
+
* to Done, which a reminder printed while the PR is still open cannot say.
|
|
48
|
+
*
|
|
49
|
+
* Both entry points print nothing for a PR URL of '' — better no reminder than a link that is not real.
|
|
50
|
+
*/
|
|
51
|
+
let TicketReminder = class TicketReminder {
|
|
52
|
+
/**
|
|
53
|
+
* The stage-③ form. `done` is FinishBanner.isDone of the merge outcome: when false the PR exists but
|
|
54
|
+
* is not merged, so the reminder says so instead of implying a finished run.
|
|
55
|
+
*/
|
|
56
|
+
forPostedPr(prUrl, done, ticketUrls) {
|
|
57
|
+
if (prUrl === '')
|
|
58
|
+
return '';
|
|
59
|
+
const state = done
|
|
60
|
+
? ''
|
|
61
|
+
: ' (The PR is open but NOT merged — see step 4. The link is still correct to add now.)\n';
|
|
62
|
+
const list = ticketUrls.length === 0
|
|
63
|
+
? ' summary.json names no addressesIssues ticket — use the ticket in your tracker this work belongs to.\n'
|
|
64
|
+
: ` Ticket(s) this PR addresses (${exports.TICKET_SOURCE_SUMMARY}):\n` +
|
|
65
|
+
ticketUrls.map((url) => ` ${url}\n`).join('');
|
|
66
|
+
return this.heading(`to this PR: ${prUrl}\n`) + state + this.obligations() + list;
|
|
67
|
+
}
|
|
68
|
+
/** The `wp-land-pr` form: the PR is merged, so the wording is LANDED and covers moving to Done. */
|
|
69
|
+
forLandedPr(prUrl, tickets) {
|
|
70
|
+
if (prUrl === '')
|
|
71
|
+
return '';
|
|
72
|
+
const done = ' It is merged into main. When this PR completes a ticket\'s work, this is also the moment to\n' +
|
|
73
|
+
' move a Linear or Jira ticket to Done (a GitHub issue named by a "Fixes" line closes itself).\n';
|
|
74
|
+
return this.heading(`to this LANDED (merged) PR: ${prUrl}\n`) + done + this.obligations() +
|
|
75
|
+
this.landedList(tickets);
|
|
76
|
+
}
|
|
77
|
+
heading(target) {
|
|
78
|
+
return '\n' + SEP +
|
|
79
|
+
'📌 NEXT ACTION — UPDATE YOUR TICKET (Linear, Jira, GitHub issue, or another tracker) with a link\n' +
|
|
80
|
+
` ${target}`;
|
|
81
|
+
}
|
|
82
|
+
obligations() {
|
|
83
|
+
return ' Keep the links to earlier PRs so the ticket lists every PR associated with the work.\n' +
|
|
84
|
+
' webpieces did NOT update any ticket — it contacts no tracker. Adding the link is yours to do.\n';
|
|
85
|
+
}
|
|
86
|
+
landedList(tickets) {
|
|
87
|
+
if (tickets.links.length === 0) {
|
|
88
|
+
return ` No ticket URL found in ${exports.TICKET_SOURCE_SUMMARY} or in the PR body — use the ticket in your\n` +
|
|
89
|
+
' tracker this work belongs to.\n';
|
|
90
|
+
}
|
|
91
|
+
return ` Ticket(s) this PR addresses (${tickets.source}):\n` +
|
|
92
|
+
tickets.links.map((link) => link.closesIssue
|
|
93
|
+
? ` ${link.url} (Fixes — this PR completes it)\n`
|
|
94
|
+
: ` ${link.url} (Part of — more PRs are owed; leave it open)\n`).join('');
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.TicketReminder = TicketReminder;
|
|
98
|
+
exports.TicketReminder = TicketReminder = tslib_1.__decorate([
|
|
99
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton)
|
|
100
|
+
], TicketReminder);
|
|
101
|
+
//# sourceMappingURL=ticket-reminder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticket-reminder.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/ticket-reminder.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAE3D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,2FAA2F;AAC9E,QAAA,qBAAqB,GAAG,8BAA8B,CAAC;AACpE,0FAA0F;AAC7E,QAAA,qBAAqB,GAAG,sDAAsD,CAAC;AAC5F,0DAA0D;AAC7C,QAAA,kBAAkB,GAAG,MAAM,CAAC;AAEz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,OAAO,IAAI,CAAC,OAAO,CAAC,+BAA+B,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE;YACrF,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAEO,OAAO,CAAC,MAAc;QAC1B,OAAO,IAAI,GAAG,GAAG;YACb,oGAAoG;YACpG,MAAM,MAAM,EAAE,CAAC;IACvB,CAAC;IAEO,WAAW;QACf,OAAO,2FAA2F;YAC9F,oGAAoG,CAAC;IAC7G,CAAC;IAEO,UAAU,CAAC,OAAsB;QACrC,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,6BAA6B,6BAAqB,+CAA+C;gBACpG,oCAAoC,CAAC;QAC7C,CAAC;QACD,OAAO,mCAAmC,OAAO,CAAC,MAAM,MAAM;YAC1D,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAgB,EAAU,EAAE,CAAC,IAAI,CAAC,WAAW;gBAC5D,CAAC,CAAC,UAAU,IAAI,CAAC,GAAG,qCAAqC;gBACzD,CAAC,CAAC,UAAU,IAAI,CAAC,GAAG,mDAAmD,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9F,CAAC;CACJ,CAAA;AAhDY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,cAAc,CAgD1B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** The tickets came from summary.json's `addressesIssues` (still on disk at land time). */\nexport const TICKET_SOURCE_SUMMARY = 'summary.json addressesIssues';\n/** The tickets came from the PR body's rendered `Fixes <url>` / `Part of <url>` lines. */\nexport const TICKET_SOURCE_PR_BODY = 'the PR body\\'s \"Fixes <url>\" / \"Part of <url>\" lines';\n/** No ticket URL could be recovered from either place. */\nexport const TICKET_SOURCE_NONE = 'none';\n\n/**\n * Data-only: one ticket a PR addresses, and whether that PR finishes it. `closesIssue` is true for a\n * `Fixes <url>` (this PR completes the ticket) and false for a `Part of <url>` (more PRs are owed).\n */\nexport class TicketLink {\n url: string;\n closesIssue: boolean;\n\n constructor(url: string, closesIssue: boolean) {\n this.url = url;\n this.closesIssue = closesIssue;\n }\n}\n\n/** Data-only: the tickets a LANDED PR addresses, and where they were read from (a TICKET_SOURCE_*). */\nexport class LandedTickets {\n links: TicketLink[];\n source: string;\n\n constructor(links: TicketLink[], source: string) {\n this.links = links;\n this.source = source;\n }\n}\n\n/**\n * THE one wording of the \"link this PR FROM its ticket\" next action — printed by `wp-finish-upsert-pr`\n * after it posts or updates a PR (issue #1453) and again by `wp-land-pr` after it lands one (issue #1456).\n *\n * The PR body's `Fixes <url>` / `Part of <url>` line links the PR TO its ticket; nothing links the ticket\n * back to the PR, and on a tracker outside GitHub (Linear, Jira) nothing ever will unless the caller does\n * it. One ticket often spans several PRs, so the reminder says to ADD the link, keeping the earlier ones —\n * and it says plainly that webpieces updated no ticket, because it contacts no tracker.\n *\n * Landing repeats it because the stage-③ reminder is printed many turns before the PR reaches main, and\n * by then it has usually been forgotten. Landing is also the moment a Linear or Jira ticket should move\n * to Done, which a reminder printed while the PR is still open cannot say.\n *\n * Both entry points print nothing for a PR URL of '' — better no reminder than a link that is not real.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class TicketReminder {\n /**\n * The stage-③ form. `done` is FinishBanner.isDone of the merge outcome: when false the PR exists but\n * is not merged, so the reminder says so instead of implying a finished run.\n */\n forPostedPr(prUrl: string, done: boolean, ticketUrls: string[]): string {\n if (prUrl === '') return '';\n const state = done\n ? ''\n : ' (The PR is open but NOT merged — see step 4. The link is still correct to add now.)\\n';\n const list = ticketUrls.length === 0\n ? ' summary.json names no addressesIssues ticket — use the ticket in your tracker this work belongs to.\\n'\n : ` Ticket(s) this PR addresses (${TICKET_SOURCE_SUMMARY}):\\n` +\n ticketUrls.map((url: string): string => ` ${url}\\n`).join('');\n return this.heading(`to this PR: ${prUrl}\\n`) + state + this.obligations() + list;\n }\n\n /** The `wp-land-pr` form: the PR is merged, so the wording is LANDED and covers moving to Done. */\n forLandedPr(prUrl: string, tickets: LandedTickets): string {\n if (prUrl === '') return '';\n const done =\n ' It is merged into main. When this PR completes a ticket\\'s work, this is also the moment to\\n' +\n ' move a Linear or Jira ticket to Done (a GitHub issue named by a \"Fixes\" line closes itself).\\n';\n return this.heading(`to this LANDED (merged) PR: ${prUrl}\\n`) + done + this.obligations() +\n this.landedList(tickets);\n }\n\n private heading(target: string): string {\n return '\\n' + SEP +\n '📌 NEXT ACTION — UPDATE YOUR TICKET (Linear, Jira, GitHub issue, or another tracker) with a link\\n' +\n ` ${target}`;\n }\n\n private obligations(): string {\n return ' Keep the links to earlier PRs so the ticket lists every PR associated with the work.\\n' +\n ' webpieces did NOT update any ticket — it contacts no tracker. Adding the link is yours to do.\\n';\n }\n\n private landedList(tickets: LandedTickets): string {\n if (tickets.links.length === 0) {\n return ` No ticket URL found in ${TICKET_SOURCE_SUMMARY} or in the PR body — use the ticket in your\\n` +\n ' tracker this work belongs to.\\n';\n }\n return ` Ticket(s) this PR addresses (${tickets.source}):\\n` +\n tickets.links.map((link: TicketLink): string => link.closesIssue\n ? ` ${link.url} (Fixes — this PR completes it)\\n`\n : ` ${link.url} (Part of — more PRs are owed; leave it open)\\n`).join('');\n }\n}\n"]}
|