@defrex/autobuild 1.4.1 → 1.5.0
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/README.md +1 -1
- package/SPEC.md +440 -95
- package/bin/ab-dispatch-kernel.ts +1 -0
- package/docs/accounts.md +9 -0
- package/docs/agent-runtimes.md +1 -0
- package/docs/answering-blocked-builds.md +2 -1
- package/docs/architecture.md +290 -130
- package/docs/assets/headline-wide.png +0 -0
- package/docs/build-store.md +33 -3
- package/docs/cli.md +2 -1
- package/docs/configuration-overview.md +9 -0
- package/docs/configuration.md +166 -101
- package/docs/dispatcher-hosting.md +19 -3
- package/docs/dispatcher.md +9 -4
- package/docs/integration-overview.md +2 -2
- package/docs/integration-tree.md +91 -28
- package/docs/merge-policy.md +28 -9
- package/docs/operator-api.md +43 -18
- package/docs/operator-surfaces.md +1 -1
- package/docs/plugin-authoring.md +85 -8
- package/docs/remote-store-protocol.md +25 -7
- package/docs/remote-ticket-protocol.md +126 -12
- package/docs/restacking.md +20 -6
- package/docs/seams.md +2 -2
- package/docs/setup.md +19 -13
- package/docs/spec-standard.md +2 -1
- package/docs/ticket-dependencies.md +26 -8
- package/docs/ticket-migration.md +70 -7
- package/docs/ticket-sources.md +82 -5
- package/docs/tickets.md +34 -2
- package/docs/troubleshooting.md +2 -2
- package/docs/verification.md +5 -5
- package/docs/website.md +8 -0
- package/docs/workspaces.md +1 -1
- package/package.json +5 -4
- package/packages/core/src/accounts/hosted-readiness.ts +21 -0
- package/packages/core/src/cli/attention.ts +1 -0
- package/packages/core/src/cli/build-control.ts +36 -12
- package/packages/core/src/cli/connect.ts +9 -18
- package/packages/core/src/cli/context.ts +44 -0
- package/packages/core/src/cli/dashboard/configuration.ts +11 -0
- package/packages/core/src/cli/dashboard/model.ts +40 -10
- package/packages/core/src/cli/dashboard/queue.ts +21 -0
- package/packages/core/src/cli/dashboard/render.ts +40 -22
- package/packages/core/src/cli/dispatch-frontend.ts +63 -30
- package/packages/core/src/cli/dispatch-mode.ts +35 -16
- package/packages/core/src/cli/dispatch-repository-feed.ts +40 -11
- package/packages/core/src/cli/dispatch.ts +154 -47
- package/packages/core/src/cli/help.ts +59 -22
- package/packages/core/src/cli/init-hosted-accounts.ts +54 -0
- package/packages/core/src/cli/init-readiness-remote.ts +16 -3
- package/packages/core/src/cli/init-validation.ts +144 -42
- package/packages/core/src/cli/issue-links.ts +67 -0
- package/packages/core/src/cli/main.ts +32 -15
- package/packages/core/src/cli/pr-summary-publication.ts +38 -7
- package/packages/core/src/cli/publication-settlement.ts +36 -24
- package/packages/core/src/cli/repository-status.ts +201 -49
- package/packages/core/src/cli/status.ts +41 -3
- package/packages/core/src/cli/terminals.ts +37 -2
- package/packages/core/src/cli/ticket-editor.ts +20 -6
- package/packages/core/src/cli/ticket.ts +264 -46
- package/packages/core/src/cli/triage-count-sampler.ts +59 -0
- package/packages/core/src/cli/watch.ts +4 -0
- package/packages/core/src/config/live.ts +45 -4
- package/packages/core/src/config/load.ts +9 -0
- package/packages/core/src/config/pipeline-source.ts +6 -2
- package/packages/core/src/config/ready-assignee.ts +86 -0
- package/packages/core/src/config/schema.ts +164 -36
- package/packages/core/src/distribution-packaging.ts +1 -1
- package/packages/core/src/events/catalog.ts +5 -0
- package/packages/core/src/events/compatibility.ts +2 -1
- package/packages/core/src/events/payloads.ts +70 -0
- package/packages/core/src/events/policy.ts +8 -0
- package/packages/core/src/events/repository.ts +91 -28
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +41 -0
- package/packages/core/src/kernel/build-identity.ts +12 -0
- package/packages/core/src/kernel/change-presence.ts +139 -6
- package/packages/core/src/kernel/dispatch-capacity.ts +80 -14
- package/packages/core/src/kernel/dispatch-status.ts +10 -1
- package/packages/core/src/kernel/dispatch-upgrade.ts +104 -5
- package/packages/core/src/kernel/engine.ts +4 -2
- package/packages/core/src/kernel/finalize-pr-rejection.ts +95 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +15 -1
- package/packages/core/src/kernel/harvest.ts +4 -1
- package/packages/core/src/kernel/integration-completeness.ts +104 -17
- package/packages/core/src/kernel/integration-landing.ts +17 -0
- package/packages/core/src/kernel/integration-state.ts +17 -0
- package/packages/core/src/kernel/issue-keywords.ts +202 -0
- package/packages/core/src/kernel/janitor-failure.ts +11 -0
- package/packages/core/src/kernel/kernel-git.ts +87 -0
- package/packages/core/src/kernel/landing-readiness.ts +25 -17
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-issue-links.ts +142 -0
- package/packages/core/src/kernel/node-parent.ts +6 -0
- package/packages/core/src/kernel/node-restack-transaction.ts +2 -0
- package/packages/core/src/kernel/pr-summary.ts +24 -0
- package/packages/core/src/kernel/read-deferrals.ts +75 -12
- package/packages/core/src/kernel/read-facts.ts +32 -1
- package/packages/core/src/kernel/reconcile-restack.ts +1 -1
- package/packages/core/src/kernel/reducer-registry.ts +31 -1
- package/packages/core/src/kernel/reducer.ts +90 -2
- package/packages/core/src/kernel/ticket-preparation.ts +12 -0
- package/packages/core/src/kernel/verify-budget.ts +43 -0
- package/packages/core/src/operator/index.ts +3 -1
- package/packages/core/src/operator/presentation.ts +3 -0
- package/packages/core/src/operator/protocol.ts +38 -2
- package/packages/core/src/operator/query.ts +66 -29
- package/packages/core/src/operator/registry.ts +47 -26
- package/packages/core/src/operator/tickets.ts +77 -10
- package/packages/core/src/plugin-sdk/index.ts +13 -0
- package/packages/core/src/plugins/manifest.ts +1 -1
- package/packages/core/src/plugins/registry.ts +1 -0
- package/packages/core/src/ports/forge/contract.ts +69 -0
- package/packages/core/src/ports/forge/create.ts +5 -0
- package/packages/core/src/ports/forge/fake.ts +184 -3
- package/packages/core/src/ports/forge/git-rewrite.ts +4 -2
- package/packages/core/src/ports/forge/github.ts +175 -38
- package/packages/core/src/ports/forge/local-git.ts +14 -0
- package/packages/core/src/ports/forge/readiness.ts +10 -0
- package/packages/core/src/ports/forge-failure.ts +43 -0
- package/packages/core/src/ports/runner/claude.ts +7 -1
- package/packages/core/src/ports/runner/codex.ts +7 -2
- package/packages/core/src/ports/runner/native-cli-fixture.ts +2 -1
- package/packages/core/src/ports/runner/pi.ts +7 -1
- package/packages/core/src/ports/runner/runtime.ts +3 -0
- package/packages/core/src/ports/runner/start-prompt.ts +37 -0
- package/packages/core/src/ports/tickets/contract.ts +320 -7
- package/packages/core/src/ports/tickets/create.ts +72 -17
- package/packages/core/src/ports/tickets/fake.ts +18 -0
- package/packages/core/src/ports/tickets/file-codec.ts +20 -0
- package/packages/core/src/ports/tickets/file.ts +43 -1
- package/packages/core/src/ports/tickets/github-fake.ts +1123 -0
- package/packages/core/src/ports/tickets/github-issues.ts +431 -0
- package/packages/core/src/ports/tickets/github-validators.ts +194 -0
- package/packages/core/src/ports/tickets/github.ts +2029 -0
- package/packages/core/src/ports/tickets/hosted-index.ts +34 -3
- package/packages/core/src/ports/tickets/issue-links.ts +86 -0
- package/packages/core/src/ports/tickets/lifecycle.ts +60 -4
- package/packages/core/src/ports/tickets/linear.ts +66 -6
- package/packages/core/src/ports/tickets/migration.ts +290 -68
- package/packages/core/src/ports/tickets/operations.ts +98 -12
- package/packages/core/src/ports/tickets/priority.ts +55 -0
- package/packages/core/src/ports/tickets/remote-protocol.ts +195 -29
- package/packages/core/src/ports/tickets/remote.ts +188 -13
- package/packages/core/src/ports/tickets/revision.ts +22 -1
- package/packages/core/src/ports/tickets/states.ts +43 -0
- package/packages/core/src/ports/tickets/tree.ts +58 -12
- package/packages/core/src/ports/tickets/update.ts +12 -2
- package/packages/core/src/ports/types.ts +194 -11
- package/packages/core/src/ports/workspace/commit-preservation.ts +135 -13
- package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +132 -27
- package/packages/core/src/processes/build-runner.ts +99 -21
- package/packages/core/src/processes/dispatcher.ts +1080 -533
- package/packages/core/src/processes/execution-no-progress.ts +5 -0
- package/packages/core/src/processes/harvest-runner.ts +17 -8
- package/packages/core/src/processes/harvest.ts +5 -8
- package/packages/core/src/processes/tick-publication.ts +12 -2
- package/packages/core/src/processes/ticket-scan-schedule.ts +78 -0
- package/packages/core/src/processes/workspace-preservation.ts +37 -2
- package/packages/core/src/runtime-identity.ts +10 -2
- package/packages/core/src/scenarios/harness.ts +4 -0
- package/packages/core/src/store/adapter.ts +7 -1
- package/packages/core/src/store/contract.ts +83 -2
- package/packages/core/src/store/digest.ts +32 -1
- package/packages/core/src/store/reducer-value-shapes.json +4187 -3391
- package/packages/core/src/store/remote/protocol.ts +2 -0
- package/packages/core/src/store/remote/released-clients.json +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.5.0.json +26924 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +2 -0
- package/packages/core/src/store/types.ts +5 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +729 -123
- package/packages/core/src/testing/index.ts +18 -1
- package/packages/core/src/testing/presence-history.ts +79 -0
- package/packages/core/src/testing/reduced-read-budget.ts +1197 -31
- package/packages/core/src/testing/upgrade-generations.ts +77 -0
- package/skills/code-review/SKILL.md +4 -3
- package/skills/finalize/SKILL.md +18 -2
- package/skills/guide/SKILL.md +382 -139
- package/skills/guide/references/accounts.md +9 -0
- package/skills/guide/references/integration-tree.md +91 -28
- package/skills/guide/references/merge-policy.md +28 -9
- package/skills/guide/references/operator-api.md +43 -18
- package/skills/guide/references/plugin-authoring.md +85 -8
- package/skills/guide/references/remote-store-protocol.md +25 -7
- package/skills/guide/references/remote-ticket-protocol.md +126 -12
- package/skills/guide/references/restacking.md +20 -6
- package/skills/guide/references/setup.md +19 -13
- package/skills/guide/references/spec-standard.md +2 -1
- package/skills/guide/references/ticket-dependencies.md +26 -8
- package/skills/guide/references/ticket-migration.md +70 -7
- package/skills/harvest-review/SKILL.md +4 -3
- package/skills/implement/SKILL.md +20 -1
- package/skills/operate/SKILL.md +103 -28
- package/skills/plan/SKILL.md +1 -1
- package/skills/reconcile/SKILL.md +5 -4
- package/skills/spec/SKILL.md +15 -2
- package/skills/tickets/SKILL.md +114 -37
- package/templates/autobuild.toml +5 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { readinessChecks, type ForgeReadinessCheck } from './readiness'
|
|
2
|
-
import { hasBuildTrailer
|
|
2
|
+
import { hasBuildTrailer } from '../../kernel/build-identity'
|
|
3
|
+
import {
|
|
4
|
+
landingMessage,
|
|
5
|
+
neutralizeClosingReferences,
|
|
6
|
+
withIssueKeywords,
|
|
7
|
+
} from '../../kernel/issue-keywords'
|
|
3
8
|
import type { BuildLandingOptions } from '../types'
|
|
9
|
+
import { ForgeRejection } from '../forge-failure'
|
|
4
10
|
import { findSummaryMarker } from './summary-marker'
|
|
5
11
|
/**
|
|
6
12
|
* FakeForge (SPEC §3.2): in-memory Forge for seam tests. Gate existence and
|
|
@@ -20,6 +26,7 @@ import type {
|
|
|
20
26
|
PrAttachmentReclaimRequest,
|
|
21
27
|
PrAttachmentUploadRequest,
|
|
22
28
|
Forge,
|
|
29
|
+
IssueLink,
|
|
23
30
|
PrRef,
|
|
24
31
|
PrState,
|
|
25
32
|
} from '../types'
|
|
@@ -56,6 +63,15 @@ export interface AutoMergeRecord {
|
|
|
56
63
|
enabled: boolean
|
|
57
64
|
/** False on an idempotent retry or a result that leaves native state off. */
|
|
58
65
|
changed: boolean
|
|
66
|
+
/** The identity request an options-bearing enable or repair armed. */
|
|
67
|
+
armed?: FakeArmedRequest
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A native request's merge method and commit message, as GitHub stores it. */
|
|
71
|
+
export interface FakeArmedRequest {
|
|
72
|
+
method: 'SQUASH' | 'MERGE' | 'REBASE'
|
|
73
|
+
headline: string
|
|
74
|
+
body: string
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
export interface SquashMergeRecord {
|
|
@@ -137,6 +153,15 @@ export class FakeForge implements Forge {
|
|
|
137
153
|
: { kind: 'gated', reason: 'Fake destination requires merge gates' }
|
|
138
154
|
}
|
|
139
155
|
readonly name = 'fake'
|
|
156
|
+
/** Absent by default, matching a forge without issue-closing support. */
|
|
157
|
+
readonly closesIssues?: boolean
|
|
158
|
+
/** Present only with `closesIssues`, like GitHub's PR body rewrite. */
|
|
159
|
+
readonly updatePrIssueLinks?: Forge['updatePrIssueLinks']
|
|
160
|
+
readonly issueLinkUpdates: { number: number; issueLinks: IssueLink[] }[] = []
|
|
161
|
+
/** Each adoption by `openPr` that converged an open PR's keyword lines. */
|
|
162
|
+
readonly issueLinkAdoptions: { number: number; issueLinks: IssueLink[] }[] = []
|
|
163
|
+
/** Test knob: the next readbacks disagree with the composed body. */
|
|
164
|
+
failIssueLinkReadback = false
|
|
140
165
|
readonly archives = new Map<string, string>()
|
|
141
166
|
readonly rewrites: { branch: string; expected: string; sha: string }[] = []
|
|
142
167
|
rewrite: import('../types').ForgeRewrite = {
|
|
@@ -192,11 +217,22 @@ export class FakeForge implements Forge {
|
|
|
192
217
|
private readonly mergeStates = new Map<number, MergeStateStatus>()
|
|
193
218
|
private readonly gates = new Map<number, FakeGateState>()
|
|
194
219
|
private readonly autoMerge = new Map<number, boolean>()
|
|
220
|
+
/** Modelled armed requests. An enabled PR without an entry is a legacy arm
|
|
221
|
+
* (seeded or enabled without options) whose message is unmodelled and is
|
|
222
|
+
* treated as matching. */
|
|
223
|
+
private readonly armed = new Map<number, FakeArmedRequest>()
|
|
224
|
+
/** Current PR title and body: the source of GitHub's fresh default message. */
|
|
225
|
+
private readonly metadata = new Map<number, { title: string; body: string }>()
|
|
226
|
+
/** PR number of every options-bearing readback of an enabled request. */
|
|
227
|
+
readonly identityReads: number[] = []
|
|
195
228
|
private readonly nativeDeferrals = new Map<number, AutoMergeDeferralReason>()
|
|
196
229
|
private readonly squashErrors = new Map<number, string>()
|
|
197
230
|
private readonly attachmentAssets = new Map<string, HostedPrAttachmentAsset>()
|
|
198
231
|
private readonly attachmentUploadErrors: string[] = []
|
|
199
232
|
private readonly attachmentReclaimErrors: string[] = []
|
|
233
|
+
private readonly openPrRejections: { status: number; forgeMessage: string; forge: string }[] = []
|
|
234
|
+
/** PR creates that reached the forge (adoptions of an open PR excluded). */
|
|
235
|
+
openPrAttempts = 0
|
|
200
236
|
private readonly closePrErrors: string[] = []
|
|
201
237
|
private readonly deleteBranchErrors: string[] = []
|
|
202
238
|
private readonly publishedBranches = new Set<string>()
|
|
@@ -232,8 +268,25 @@ export class FakeForge implements Forge {
|
|
|
232
268
|
/** Hosting is unsupported by default, matching a forge without this
|
|
233
269
|
* optional capability. Tests opt in explicitly. */
|
|
234
270
|
prAttachments?: boolean
|
|
271
|
+
/** Compose issue keywords like GitHub; absent by default. */
|
|
272
|
+
closesIssues?: boolean
|
|
235
273
|
} = {},
|
|
236
274
|
) {
|
|
275
|
+
if (opts.closesIssues === true) {
|
|
276
|
+
this.closesIssues = true
|
|
277
|
+
this.updatePrIssueLinks = async (_workspacePath, number, issueLinks) => {
|
|
278
|
+
const pr = this.opened[number - 1]
|
|
279
|
+
if (!pr || this.prs.get(number)?.state !== 'open')
|
|
280
|
+
throw new Error(`PR #${number} is not open; issue keywords not updated`)
|
|
281
|
+
this.issueLinkUpdates.push({ number, issueLinks: issueLinks.map((link) => ({ ...link })) })
|
|
282
|
+
pr.title = neutralizeClosingReferences(pr.title, issueLinks)
|
|
283
|
+
pr.body = withIssueKeywords(pr.body, issueLinks, { trailers: false })
|
|
284
|
+
const metadata = this.metadata.get(number)
|
|
285
|
+
if (metadata) metadata.body = pr.body
|
|
286
|
+
if (this.failIssueLinkReadback)
|
|
287
|
+
throw new Error(`PR #${number} body readback disagrees with issue keywords`)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
237
290
|
this.headSha = opts.headSha ?? ((n) => `sha-${n}`)
|
|
238
291
|
this.mergeSha = opts.mergeSha ?? ((n) => `squash-${n}`)
|
|
239
292
|
// Existing tests model the historical, gated native path unless they opt
|
|
@@ -263,6 +316,8 @@ export class FakeForge implements Forge {
|
|
|
263
316
|
this.prs.set(number, state)
|
|
264
317
|
if (!this.headShas.has(number)) this.headShas.set(number, this.resolveHeadSha(number))
|
|
265
318
|
if (!this.autoMerge.has(number)) this.autoMerge.set(number, false)
|
|
319
|
+
if (!this.metadata.has(number))
|
|
320
|
+
this.metadata.set(number, { title: `Fake PR #${number}`, body: '' })
|
|
266
321
|
if (!this.gates.has(number)) this.gates.set(number, this.defaultGatePresence)
|
|
267
322
|
if (!this.mergeStates.has(number)) {
|
|
268
323
|
const mergeState: MergeStateStatus =
|
|
@@ -410,6 +465,11 @@ export class FakeForge implements Forge {
|
|
|
410
465
|
// Missing means it was already deleted: cleanup is idempotent.
|
|
411
466
|
}
|
|
412
467
|
|
|
468
|
+
/** Rejects the next PR create that is not adopted from an open PR. */
|
|
469
|
+
rejectNextOpenPr(status: number, forgeMessage: string, forge = 'Fake'): void {
|
|
470
|
+
this.openPrRejections.push({ status, forgeMessage, forge })
|
|
471
|
+
}
|
|
472
|
+
|
|
413
473
|
failNextClosePr(message: string): void {
|
|
414
474
|
this.closePrErrors.push(message)
|
|
415
475
|
}
|
|
@@ -432,6 +492,54 @@ export class FakeForge implements Forge {
|
|
|
432
492
|
setAutoMergeState(number: number, enabled: boolean): void {
|
|
433
493
|
this.assertPr(number)
|
|
434
494
|
this.autoMerge.set(number, enabled)
|
|
495
|
+
if (!enabled) this.armed.delete(number)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/** Arm native auto-merge with exactly this method and message, as a human
|
|
499
|
+
* enabling it in the GitHub UI would. */
|
|
500
|
+
armAutoMerge(number: number, request: FakeArmedRequest): void {
|
|
501
|
+
this.assertPr(number)
|
|
502
|
+
this.autoMerge.set(number, true)
|
|
503
|
+
this.armed.set(number, { ...request })
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** The modelled armed request; undefined when disabled or a legacy arm. */
|
|
507
|
+
armedAutoMerge(number: number): FakeArmedRequest | undefined {
|
|
508
|
+
const request = this.armed.get(number)
|
|
509
|
+
return request && { ...request }
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** Edit the PR title or body. This changes GitHub's fresh default message,
|
|
513
|
+
* never the message of an already-armed request. */
|
|
514
|
+
editPr(number: number, edit: { title?: string; body?: string }): void {
|
|
515
|
+
this.assertPr(number)
|
|
516
|
+
const metadata = this.metadata.get(number)!
|
|
517
|
+
if (edit.title !== undefined) metadata.title = edit.title
|
|
518
|
+
if (edit.body !== undefined) metadata.body = edit.body
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** The identity squash request GitHub would arm for these options now:
|
|
522
|
+
* fresh viewer defaults plus the build trailer. */
|
|
523
|
+
expectedIdentity(number: number, options: BuildLandingOptions): FakeArmedRequest {
|
|
524
|
+
this.assertPr(number)
|
|
525
|
+
const { title, body } = this.metadata.get(number)!
|
|
526
|
+
const links = this.closesIssues === true ? (options.issueLinks ?? []) : []
|
|
527
|
+
return {
|
|
528
|
+
method: 'SQUASH',
|
|
529
|
+
headline: neutralizeClosingReferences(`${title} (#${number})`, links),
|
|
530
|
+
body: landingMessage(body, options.buildSlug, links),
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
private identityMatches(number: number, options: BuildLandingOptions): boolean {
|
|
535
|
+
const armed = this.armed.get(number)
|
|
536
|
+
if (armed === undefined) return true
|
|
537
|
+
const expected = this.expectedIdentity(number, options)
|
|
538
|
+
return (
|
|
539
|
+
armed.method === expected.method &&
|
|
540
|
+
armed.headline === expected.headline &&
|
|
541
|
+
armed.body.trimEnd() === expected.body.trimEnd()
|
|
542
|
+
)
|
|
435
543
|
}
|
|
436
544
|
|
|
437
545
|
/** Inspect native state in seam/integration assertions. */
|
|
@@ -478,6 +586,10 @@ export class FakeForge implements Forge {
|
|
|
478
586
|
return sha
|
|
479
587
|
}
|
|
480
588
|
|
|
589
|
+
async remoteBranchExists(branch: string): Promise<boolean> {
|
|
590
|
+
return this.remoteBranches.has(branch)
|
|
591
|
+
}
|
|
592
|
+
|
|
481
593
|
async readFile(path: string, ref?: string): Promise<string> {
|
|
482
594
|
const key = `${ref ?? 'default'}\0${path}`
|
|
483
595
|
const content = this.files.get(key)
|
|
@@ -525,21 +637,49 @@ export class FakeForge implements Forge {
|
|
|
525
637
|
title: string
|
|
526
638
|
body: string
|
|
527
639
|
mergeMessage?: string
|
|
640
|
+
issueLinks?: readonly IssueLink[]
|
|
528
641
|
}): Promise<PrRef> {
|
|
529
642
|
// Idempotent by head branch, mirroring GitHubForge (SPEC §8.7).
|
|
530
643
|
for (let i = this.opened.length - 1; i >= 0; i -= 1) {
|
|
531
644
|
const number = i + 1
|
|
532
645
|
if (this.opened[i]!.head !== opts.head || this.opened[i]!.base !== opts.base) continue
|
|
533
646
|
if (this.prs.get(number)?.state !== 'open') continue
|
|
647
|
+
const adopted = this.opened[i]!
|
|
648
|
+
const links = this.closesIssues === true ? (opts.issueLinks ?? []) : []
|
|
649
|
+
if (links.length > 0) {
|
|
650
|
+
// Converge like GitHubForge: neutralize the kept title and recompose
|
|
651
|
+
// the body's keyword lines; the merge message is never replaced.
|
|
652
|
+
this.issueLinkAdoptions.push({ number, issueLinks: links.map((link) => ({ ...link })) })
|
|
653
|
+
adopted.title = neutralizeClosingReferences(adopted.title, links)
|
|
654
|
+
adopted.body = withIssueKeywords(adopted.body, links, { trailers: false })
|
|
655
|
+
}
|
|
534
656
|
return {
|
|
535
657
|
number,
|
|
536
658
|
url: `https://fake.forge/pr/${number}`,
|
|
537
659
|
headSha: this.headShas.get(number)!,
|
|
538
660
|
}
|
|
539
661
|
}
|
|
662
|
+
this.openPrAttempts += 1
|
|
663
|
+
const rejection = this.openPrRejections.shift()
|
|
664
|
+
if (rejection !== undefined)
|
|
665
|
+
throw new ForgeRejection(rejection.forgeMessage, {
|
|
666
|
+
forge: rejection.forge,
|
|
667
|
+
status: rejection.status,
|
|
668
|
+
forgeMessage: rejection.forgeMessage,
|
|
669
|
+
})
|
|
540
670
|
const number = this.nextNumber++
|
|
541
|
-
|
|
671
|
+
const { issueLinks, ...record } = opts
|
|
672
|
+
const links = this.closesIssues === true ? (issueLinks ?? []) : []
|
|
673
|
+
this.opened.push({
|
|
674
|
+
...record,
|
|
675
|
+
title: neutralizeClosingReferences(record.title, links),
|
|
676
|
+
body: withIssueKeywords(record.body, links, { trailers: false }),
|
|
677
|
+
...(record.mergeMessage !== undefined
|
|
678
|
+
? { mergeMessage: withIssueKeywords(record.mergeMessage, links) }
|
|
679
|
+
: {}),
|
|
680
|
+
})
|
|
542
681
|
this.registerPr(number, { state: 'open', mergeable: null })
|
|
682
|
+
this.metadata.set(number, { title: this.opened.at(-1)!.title, body: this.opened.at(-1)!.body })
|
|
543
683
|
return {
|
|
544
684
|
number,
|
|
545
685
|
url: `https://fake.forge/pr/${number}`,
|
|
@@ -566,9 +706,15 @@ export class FakeForge implements Forge {
|
|
|
566
706
|
this.assertPr(number)
|
|
567
707
|
const currentlyEnabled = this.autoMerge.get(number) ?? false
|
|
568
708
|
|
|
709
|
+
if (enabled && currentlyEnabled && options !== undefined) {
|
|
710
|
+
this.identityReads.push(number)
|
|
711
|
+
if (!this.identityMatches(number, options))
|
|
712
|
+
return this.repairIdentity(workspacePath, number, options)
|
|
713
|
+
}
|
|
569
714
|
if (!enabled || currentlyEnabled) {
|
|
570
715
|
const changed = currentlyEnabled !== enabled
|
|
571
716
|
this.autoMerge.set(number, enabled)
|
|
717
|
+
if (!enabled) this.armed.delete(number)
|
|
572
718
|
this.autoMergeCalls.push({ workspacePath, number, enabled, changed })
|
|
573
719
|
return { kind: 'applied' }
|
|
574
720
|
}
|
|
@@ -590,11 +736,14 @@ export class FakeForge implements Forge {
|
|
|
590
736
|
if (options?.canApply !== undefined && !(await options.canApply()))
|
|
591
737
|
return { kind: 'deferred' }
|
|
592
738
|
this.autoMerge.set(number, true)
|
|
739
|
+
const armed = options && this.expectedIdentity(number, options)
|
|
740
|
+
if (armed) this.armed.set(number, armed)
|
|
593
741
|
this.autoMergeCalls.push({
|
|
594
742
|
workspacePath,
|
|
595
743
|
number,
|
|
596
744
|
enabled: true,
|
|
597
745
|
changed: true,
|
|
746
|
+
...(armed ? { armed: { ...armed } } : {}),
|
|
598
747
|
})
|
|
599
748
|
return { kind: 'applied' }
|
|
600
749
|
}
|
|
@@ -623,6 +772,32 @@ export class FakeForge implements Forge {
|
|
|
623
772
|
}
|
|
624
773
|
}
|
|
625
774
|
|
|
775
|
+
/** Replace a mismatched armed request in GitHub's order: gate inspection,
|
|
776
|
+
* then the consent check, then disable and re-arm with the identity. */
|
|
777
|
+
private async repairIdentity(
|
|
778
|
+
workspacePath: string,
|
|
779
|
+
number: number,
|
|
780
|
+
options: BuildLandingOptions,
|
|
781
|
+
): Promise<AutoMergeResult> {
|
|
782
|
+
const gate = this.gates.get(number) ?? this.defaultGatePresence
|
|
783
|
+
const reason = typeof gate === 'object' ? gate : this.nativeDeferrals.get(number)
|
|
784
|
+
if (reason !== undefined) {
|
|
785
|
+
this.autoMergeCalls.push({ workspacePath, number, enabled: true, changed: false })
|
|
786
|
+
return { kind: 'deferred', reason }
|
|
787
|
+
}
|
|
788
|
+
if (options.canApply !== undefined && !(await options.canApply())) return { kind: 'deferred' }
|
|
789
|
+
const armed = this.expectedIdentity(number, options)
|
|
790
|
+
this.armed.set(number, armed)
|
|
791
|
+
this.autoMergeCalls.push({
|
|
792
|
+
workspacePath,
|
|
793
|
+
number,
|
|
794
|
+
enabled: true,
|
|
795
|
+
changed: true,
|
|
796
|
+
armed: { ...armed },
|
|
797
|
+
})
|
|
798
|
+
return { kind: 'applied' }
|
|
799
|
+
}
|
|
800
|
+
|
|
626
801
|
async squashMerge(
|
|
627
802
|
workspacePath: string,
|
|
628
803
|
number: number,
|
|
@@ -662,7 +837,13 @@ export class FakeForge implements Forge {
|
|
|
662
837
|
const message = this.opened[number - 1]?.mergeMessage ?? this.opened[number - 1]?.body ?? ''
|
|
663
838
|
this.commitMessages.set(
|
|
664
839
|
this.resolveMergeSha(number),
|
|
665
|
-
options === undefined
|
|
840
|
+
options === undefined
|
|
841
|
+
? message
|
|
842
|
+
: landingMessage(
|
|
843
|
+
message,
|
|
844
|
+
options.buildSlug,
|
|
845
|
+
this.closesIssues === true ? (options.issueLinks ?? []) : [],
|
|
846
|
+
),
|
|
666
847
|
)
|
|
667
848
|
this.prs.set(number, { state: 'merged', sha: this.resolveMergeSha(number) })
|
|
668
849
|
}
|
|
@@ -181,10 +181,12 @@ export function gitRewrite(
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
if (!local) {
|
|
184
|
-
// Fetch by the exact archive ref, never by an unadvertised object id
|
|
184
|
+
// Fetch by the exact archive ref, never by an unadvertised object id,
|
|
185
|
+
// and never shallow: a depth limit would write a persistent boundary
|
|
186
|
+
// that truncates ancestry the workspace already holds.
|
|
185
187
|
await git(input.workspacePath, [
|
|
186
188
|
'fetch',
|
|
187
|
-
...(missing ? ['--
|
|
189
|
+
...(missing ? ['--refmap='] : []),
|
|
188
190
|
'--no-tags',
|
|
189
191
|
'--no-write-fetch-head',
|
|
190
192
|
'origin',
|
|
@@ -14,8 +14,13 @@ import {
|
|
|
14
14
|
import { inspectGitHubReadiness } from './github-readiness'
|
|
15
15
|
import type { ForgeReadinessInput } from './readiness'
|
|
16
16
|
import { gitRewrite, publishBranch, remoteBranchHead, refreshBranchCache } from './git-rewrite'
|
|
17
|
-
import { historyContainsBuild
|
|
18
|
-
import {
|
|
17
|
+
import { historyContainsBuild } from '../../kernel/build-identity'
|
|
18
|
+
import {
|
|
19
|
+
landingMessage,
|
|
20
|
+
neutralizeClosingReferences,
|
|
21
|
+
withIssueKeywords,
|
|
22
|
+
} from '../../kernel/issue-keywords'
|
|
23
|
+
import { ForgeRejection, NoCommitsBetweenBranchesError, type BuildLandingOptions } from '../types'
|
|
19
24
|
import { findSummaryMarker } from './summary-marker'
|
|
20
25
|
/**
|
|
21
26
|
* GitHubForge (SPEC §3.2): the Forge adapter for GitHub, speaking the GitHub
|
|
@@ -69,6 +74,7 @@ import type {
|
|
|
69
74
|
ClosePrResult,
|
|
70
75
|
PrAttachmentHosting,
|
|
71
76
|
Forge,
|
|
77
|
+
IssueLink,
|
|
72
78
|
PrRef,
|
|
73
79
|
PrState,
|
|
74
80
|
} from '../types'
|
|
@@ -652,6 +658,7 @@ export class GitHubForge implements Forge {
|
|
|
652
658
|
}
|
|
653
659
|
}
|
|
654
660
|
readonly name = 'github'
|
|
661
|
+
readonly closesIssues = true
|
|
655
662
|
readonly prAttachments: PrAttachmentHosting
|
|
656
663
|
|
|
657
664
|
private readonly transport: GitHubRequest
|
|
@@ -938,6 +945,7 @@ export class GitHubForge implements Forge {
|
|
|
938
945
|
title: string
|
|
939
946
|
body: string
|
|
940
947
|
mergeMessage?: string
|
|
948
|
+
issueLinks?: readonly IssueLink[]
|
|
941
949
|
}): Promise<PrRef> {
|
|
942
950
|
// Idempotent by head branch (SPEC §8.7 crash paths): finalize's `ab done`
|
|
943
951
|
// opens the PR BEFORE appending finalize.completed, so a crash or store
|
|
@@ -962,34 +970,66 @@ export class GitHubForge implements Forge {
|
|
|
962
970
|
if (existing === undefined) return undefined
|
|
963
971
|
return { number: existing.number, url: existing.html_url, headSha: existing.head.sha }
|
|
964
972
|
}
|
|
973
|
+
const links = opts.issueLinks ?? []
|
|
974
|
+
const repository = `${owner}/${name}`
|
|
975
|
+
// An adopted PR keeps its title and prose, but its keyword lines converge
|
|
976
|
+
// to the same canonical form a fresh PR gets, so a retry, re-finalize or
|
|
977
|
+
// hand-opened PR never keeps stale or closing references.
|
|
978
|
+
const adopt = async (pr: PrRef): Promise<PrRef> => {
|
|
979
|
+
if (links.length > 0) await this.convergeIssueKeywords(pr.number, links)
|
|
980
|
+
return pr
|
|
981
|
+
}
|
|
965
982
|
const existing = await probe()
|
|
966
|
-
if (existing) return existing
|
|
983
|
+
if (existing) return adopt(existing)
|
|
967
984
|
try {
|
|
968
985
|
const created = this.parse(
|
|
969
986
|
restPrRef,
|
|
970
987
|
await this.request('POST', `${repoPath}/pulls`, {
|
|
971
|
-
body: {
|
|
988
|
+
body: {
|
|
989
|
+
title: neutralizeClosingReferences(opts.title, links, { repository }),
|
|
990
|
+
head: opts.head,
|
|
991
|
+
base: opts.base,
|
|
992
|
+
body: withIssueKeywords(opts.body, links, { repository, trailers: false }),
|
|
993
|
+
},
|
|
972
994
|
}),
|
|
973
995
|
'PR create',
|
|
974
996
|
)
|
|
975
997
|
return { number: created.number, url: created.html_url, headSha: created.head.sha }
|
|
976
998
|
} catch (error) {
|
|
977
999
|
if (isForgeFailure(error) || error instanceof ForgeRequestDeferred) throw error
|
|
978
|
-
if (error instanceof GitHubApiError
|
|
1000
|
+
if (!(error instanceof GitHubApiError) || error.status < 400 || error.status > 499)
|
|
1001
|
+
throw error
|
|
1002
|
+
if (error.status === 422) {
|
|
979
1003
|
const raced = await probe()
|
|
980
|
-
if (raced) return raced
|
|
981
|
-
const validation = z
|
|
982
|
-
.object({
|
|
983
|
-
errors: z.array(z.object({ message: z.string().optional() }).passthrough()).optional(),
|
|
984
|
-
})
|
|
985
|
-
.passthrough()
|
|
986
|
-
.safeParse(error.body)
|
|
987
|
-
const noCommits = validation.success
|
|
988
|
-
? validation.data.errors?.find((item) => /no commits between/i.test(item.message ?? ''))
|
|
989
|
-
: undefined
|
|
990
|
-
if (noCommits?.message) throw new NoCommitsBetweenBranchesError(noCommits.message)
|
|
1004
|
+
if (raced) return adopt(raced)
|
|
991
1005
|
}
|
|
992
|
-
|
|
1006
|
+
// Any other client error is a rejection a retry cannot fix. GitHub's
|
|
1007
|
+
// documented error body is `message` plus optional `errors[]` entries
|
|
1008
|
+
// that may carry their own `message`.
|
|
1009
|
+
const validation = z
|
|
1010
|
+
.object({
|
|
1011
|
+
message: z.string().optional(),
|
|
1012
|
+
errors: z.array(z.object({ message: z.string().optional() }).passthrough()).optional(),
|
|
1013
|
+
})
|
|
1014
|
+
.passthrough()
|
|
1015
|
+
.safeParse(error.body)
|
|
1016
|
+
const details = validation.success
|
|
1017
|
+
? (validation.data.errors ?? []).flatMap((item) => (item.message ? [item.message] : []))
|
|
1018
|
+
: []
|
|
1019
|
+
const summary = validation.success ? validation.data.message : undefined
|
|
1020
|
+
const forgeMessage = summary
|
|
1021
|
+
? details.length > 0
|
|
1022
|
+
? `${summary}: ${details.join('; ')}`
|
|
1023
|
+
: summary
|
|
1024
|
+
: error.message
|
|
1025
|
+
const noCommits =
|
|
1026
|
+
error.status === 422 ? details.find((item) => /no commits between/i.test(item)) : undefined
|
|
1027
|
+
if (noCommits) throw new NoCommitsBetweenBranchesError(noCommits, { forgeMessage })
|
|
1028
|
+
throw new ForgeRejection(error.message, {
|
|
1029
|
+
forge: 'GitHub',
|
|
1030
|
+
status: error.status,
|
|
1031
|
+
forgeMessage,
|
|
1032
|
+
})
|
|
993
1033
|
}
|
|
994
1034
|
}
|
|
995
1035
|
|
|
@@ -1238,6 +1278,59 @@ export class GitHubForge implements Forge {
|
|
|
1238
1278
|
this.invalidateReads()
|
|
1239
1279
|
}
|
|
1240
1280
|
|
|
1281
|
+
/** Rewrite a node PR's keyword paragraph for its set and confirm it by
|
|
1282
|
+
* readback. Prose is preserved; stale lines for linked issues are
|
|
1283
|
+
* replaced, so a later downgrade flips `Closes` to `Refs`, and a closing
|
|
1284
|
+
* reference to a `refs` issue in the title is neutralized. */
|
|
1285
|
+
async updatePrIssueLinks(
|
|
1286
|
+
_workspacePath: string,
|
|
1287
|
+
number: number,
|
|
1288
|
+
issueLinks: readonly IssueLink[],
|
|
1289
|
+
): Promise<void> {
|
|
1290
|
+
await this.convergeIssueKeywords(number, issueLinks)
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
/** Bring an open PR's title and body to the canonical keyword form for
|
|
1294
|
+
* `issueLinks`: neutralize the title, recompose the body's keyword lines,
|
|
1295
|
+
* PATCH only the fields that differ, and confirm both by readback. The
|
|
1296
|
+
* title and prose are otherwise kept. Idempotent. */
|
|
1297
|
+
private async convergeIssueKeywords(
|
|
1298
|
+
number: number,
|
|
1299
|
+
issueLinks: readonly IssueLink[],
|
|
1300
|
+
): Promise<void> {
|
|
1301
|
+
const { owner, name } = await this.requireCoordinates()
|
|
1302
|
+
const path = `repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${number}`
|
|
1303
|
+
const repository = `${owner}/${name}`
|
|
1304
|
+
const view = z.object({
|
|
1305
|
+
state: z.string(),
|
|
1306
|
+
merged: z.boolean().optional(),
|
|
1307
|
+
title: z.string(),
|
|
1308
|
+
body: z.string().nullable(),
|
|
1309
|
+
})
|
|
1310
|
+
const read = async (operation: string) =>
|
|
1311
|
+
this.parse(view, await this.request('GET', path), operation)
|
|
1312
|
+
const normalize = (body: string | null): string => (body ?? '').replace(/\r\n/g, '\n')
|
|
1313
|
+
const before = await read(`PR #${number} body`)
|
|
1314
|
+
if (before.state !== 'open' || before.merged === true)
|
|
1315
|
+
throw new Error(`PR #${number} is not open; issue keywords not updated`)
|
|
1316
|
+
const current = normalize(before.body)
|
|
1317
|
+
const desired = withIssueKeywords(current, issueLinks, { repository, trailers: false })
|
|
1318
|
+
const title = neutralizeClosingReferences(before.title, issueLinks, { repository })
|
|
1319
|
+
const patch = {
|
|
1320
|
+
...(title !== before.title ? { title } : {}),
|
|
1321
|
+
...(current.trimEnd() !== desired.trimEnd() ? { body: desired } : {}),
|
|
1322
|
+
}
|
|
1323
|
+
if (Object.keys(patch).length > 0) {
|
|
1324
|
+
await this.request('PATCH', path, { body: patch })
|
|
1325
|
+
this.invalidateReads()
|
|
1326
|
+
}
|
|
1327
|
+
const after = await read(`PR #${number} body readback`)
|
|
1328
|
+
if (after.title !== title)
|
|
1329
|
+
throw new Error(`PR #${number} title readback disagrees with issue keywords`)
|
|
1330
|
+
if (normalize(after.body).trimEnd() !== desired.trimEnd())
|
|
1331
|
+
throw new Error(`PR #${number} body readback disagrees with issue keywords`)
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1241
1334
|
async inspectLandingPr(_workspacePath: string, number: number) {
|
|
1242
1335
|
const { owner, name } = await this.requireCoordinates()
|
|
1243
1336
|
const response = await this.request(
|
|
@@ -1560,7 +1653,7 @@ export class GitHubForge implements Forge {
|
|
|
1560
1653
|
options === undefined ? undefined : await this.squashMessage(number, options.baseBranch)
|
|
1561
1654
|
if (message !== undefined && options !== undefined) {
|
|
1562
1655
|
if (message.state !== 'OPEN') return { kind: 'deferred' }
|
|
1563
|
-
if (this.identityMessageMatches(message, options
|
|
1656
|
+
if (await this.identityMessageMatches(message, options)) return { kind: 'applied' }
|
|
1564
1657
|
}
|
|
1565
1658
|
const { view, mergeState, requeries, waitedMs } = await this.inspectAutoMergeView(
|
|
1566
1659
|
repoPath,
|
|
@@ -1705,17 +1798,40 @@ export class GitHubForge implements Forge {
|
|
|
1705
1798
|
)
|
|
1706
1799
|
}
|
|
1707
1800
|
|
|
1708
|
-
|
|
1801
|
+
/** The landed squash headline and body. Writers and the identity
|
|
1802
|
+
* comparison share this one composition, so they cannot diverge. */
|
|
1803
|
+
private async landingSquashMessage(
|
|
1709
1804
|
view: z.infer<typeof squashMessageData>['repository']['pullRequest'],
|
|
1710
|
-
|
|
1711
|
-
):
|
|
1805
|
+
options: BuildLandingOptions,
|
|
1806
|
+
): Promise<{ headline: string; body: string }> {
|
|
1807
|
+
const links = options.issueLinks ?? []
|
|
1808
|
+
if (links.length === 0)
|
|
1809
|
+
return {
|
|
1810
|
+
headline: view.viewerMergeHeadlineText,
|
|
1811
|
+
body: landingMessage(view.viewerMergeBodyText, options.buildSlug, links),
|
|
1812
|
+
}
|
|
1813
|
+
const { owner, name } = await this.requireCoordinates()
|
|
1814
|
+
const repository = `${owner}/${name}`
|
|
1815
|
+
return {
|
|
1816
|
+
headline: neutralizeClosingReferences(view.viewerMergeHeadlineText, links, { repository }),
|
|
1817
|
+
body: landingMessage(view.viewerMergeBodyText, options.buildSlug, links, { repository }),
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
private async identityMessageMatches(
|
|
1822
|
+
view: z.infer<typeof squashMessageData>['repository']['pullRequest'],
|
|
1823
|
+
options: BuildLandingOptions,
|
|
1824
|
+
): Promise<boolean> {
|
|
1825
|
+
if (
|
|
1826
|
+
view.autoMergeRequest === null ||
|
|
1827
|
+
view.autoMergeRequest.mergeMethod !== 'SQUASH' ||
|
|
1828
|
+
view.autoMergeRequest.commitBody === null
|
|
1829
|
+
)
|
|
1830
|
+
return false
|
|
1831
|
+
const expected = await this.landingSquashMessage(view, options)
|
|
1712
1832
|
return (
|
|
1713
|
-
view.autoMergeRequest
|
|
1714
|
-
view.autoMergeRequest.
|
|
1715
|
-
view.autoMergeRequest.commitBody !== null &&
|
|
1716
|
-
view.autoMergeRequest.commitHeadline === view.viewerMergeHeadlineText &&
|
|
1717
|
-
view.autoMergeRequest.commitBody.trimEnd() ===
|
|
1718
|
-
withBuildTrailer(view.viewerMergeBodyText, buildSlug).trimEnd()
|
|
1833
|
+
view.autoMergeRequest.commitHeadline === expected.headline &&
|
|
1834
|
+
view.autoMergeRequest.commitBody.trimEnd() === expected.body.trimEnd()
|
|
1719
1835
|
)
|
|
1720
1836
|
}
|
|
1721
1837
|
|
|
@@ -1726,10 +1842,10 @@ export class GitHubForge implements Forge {
|
|
|
1726
1842
|
message: z.infer<typeof squashMessageData>['repository']['pullRequest'],
|
|
1727
1843
|
): Promise<AutoMergeResult> {
|
|
1728
1844
|
const expectedBase = message.baseRefName
|
|
1729
|
-
const matches = (view: typeof message): boolean =>
|
|
1730
|
-
this.identityMessageMatches(view, options
|
|
1845
|
+
const matches = (view: typeof message): Promise<boolean> =>
|
|
1846
|
+
this.identityMessageMatches(view, options)
|
|
1731
1847
|
if (message.state !== 'OPEN' || message.headRefOid !== expectedHead) return { kind: 'deferred' }
|
|
1732
|
-
if (matches(message)) return { kind: 'applied' }
|
|
1848
|
+
if (await matches(message)) return { kind: 'applied' }
|
|
1733
1849
|
if (options.canApply !== undefined && !(await options.canApply())) return { kind: 'deferred' }
|
|
1734
1850
|
if (message.autoMergeRequest !== null) {
|
|
1735
1851
|
await this.graphql(
|
|
@@ -1748,6 +1864,7 @@ export class GitHubForge implements Forge {
|
|
|
1748
1864
|
return { kind: 'deferred' }
|
|
1749
1865
|
}
|
|
1750
1866
|
if (options.canApply !== undefined && !(await options.canApply())) return { kind: 'deferred' }
|
|
1867
|
+
const landing = await this.landingSquashMessage(message, options)
|
|
1751
1868
|
await this.graphql(
|
|
1752
1869
|
'enablePullRequestAutoMerge',
|
|
1753
1870
|
enableAutoMergeData,
|
|
@@ -1756,15 +1873,15 @@ export class GitHubForge implements Forge {
|
|
|
1756
1873
|
pullRequestId: message.id,
|
|
1757
1874
|
mergeMethod: 'SQUASH',
|
|
1758
1875
|
expectedHeadOid: message.headRefOid,
|
|
1759
|
-
commitHeadline:
|
|
1760
|
-
commitBody:
|
|
1876
|
+
commitHeadline: landing.headline,
|
|
1877
|
+
commitBody: landing.body,
|
|
1761
1878
|
},
|
|
1762
1879
|
)
|
|
1763
1880
|
const after = await this.squashMessage(number, message.baseRefName)
|
|
1764
1881
|
return after.state === 'OPEN' &&
|
|
1765
1882
|
after.headRefOid === message.headRefOid &&
|
|
1766
1883
|
after.baseRefName === expectedBase &&
|
|
1767
|
-
matches(after)
|
|
1884
|
+
(await matches(after))
|
|
1768
1885
|
? { kind: 'applied' }
|
|
1769
1886
|
: {
|
|
1770
1887
|
kind: 'deferred',
|
|
@@ -1826,6 +1943,10 @@ export class GitHubForge implements Forge {
|
|
|
1826
1943
|
) {
|
|
1827
1944
|
throw new Error('GitHub squash message head changed; retry inspection')
|
|
1828
1945
|
}
|
|
1946
|
+
const landing =
|
|
1947
|
+
message !== undefined && options !== undefined
|
|
1948
|
+
? await this.landingSquashMessage(message, options)
|
|
1949
|
+
: undefined
|
|
1829
1950
|
await this.request(
|
|
1830
1951
|
'PUT',
|
|
1831
1952
|
`repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/pulls/${number}/merge`,
|
|
@@ -1833,11 +1954,8 @@ export class GitHubForge implements Forge {
|
|
|
1833
1954
|
body: {
|
|
1834
1955
|
merge_method: 'squash',
|
|
1835
1956
|
sha: expectedHeadSha,
|
|
1836
|
-
...(
|
|
1837
|
-
? {
|
|
1838
|
-
commit_title: message.viewerMergeHeadlineText,
|
|
1839
|
-
commit_message: withBuildTrailer(message.viewerMergeBodyText, options.buildSlug),
|
|
1840
|
-
}
|
|
1957
|
+
...(landing !== undefined
|
|
1958
|
+
? { commit_title: landing.headline, commit_message: landing.body }
|
|
1841
1959
|
: {}),
|
|
1842
1960
|
},
|
|
1843
1961
|
},
|
|
@@ -1990,6 +2108,25 @@ export class GitHubForge implements Forge {
|
|
|
1990
2108
|
})
|
|
1991
2109
|
}
|
|
1992
2110
|
|
|
2111
|
+
/** Exact-match branch existence on the remote. 404 is proven absence; any
|
|
2112
|
+
* other failure throws. Deliberately unmemoized: a cached answer would hide
|
|
2113
|
+
* a branch another store publishes later. */
|
|
2114
|
+
async remoteBranchExists(branch: string): Promise<boolean> {
|
|
2115
|
+
if (!isValidGitBranchName(branch)) throw new Error(`invalid branch ${branch}`)
|
|
2116
|
+
const { owner, name } = await this.requireCoordinates()
|
|
2117
|
+
try {
|
|
2118
|
+
await this.request(
|
|
2119
|
+
'GET',
|
|
2120
|
+
`repos/${encodeURIComponent(owner)}/${encodeURIComponent(name)}/git/ref/heads/${encodeURIComponent(branch)}`,
|
|
2121
|
+
)
|
|
2122
|
+
return true
|
|
2123
|
+
} catch (error) {
|
|
2124
|
+
if (isForgeFailure(error) || error instanceof ForgeRequestDeferred) throw error
|
|
2125
|
+
if (error instanceof GitHubApiError && error.status === 404) return false
|
|
2126
|
+
throw error
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
|
|
1993
2130
|
/** Raw file bytes from the repository. Ref omitted → the repository's
|
|
1994
2131
|
* default branch. Throws (including 404) when the path does not exist. */
|
|
1995
2132
|
async readFile(path: string, ref?: string): Promise<string> {
|
|
@@ -81,6 +81,20 @@ export class LocalGitForge implements Forge {
|
|
|
81
81
|
return result.stdout.trim()
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
async remoteBranchExists(branch: string): Promise<boolean> {
|
|
85
|
+
if (this.repoRoot === undefined) {
|
|
86
|
+
throw new Error('local-git forge has no repository root for remote branch reads')
|
|
87
|
+
}
|
|
88
|
+
const result = await this.command(
|
|
89
|
+
['rev-parse', '--verify', '--quiet', `refs/heads/${branch}`],
|
|
90
|
+
this.repoRoot,
|
|
91
|
+
true,
|
|
92
|
+
)
|
|
93
|
+
if (result.exitCode === 0) return true
|
|
94
|
+
if (result.exitCode === 1) return false
|
|
95
|
+
throw new Error(`local-git branch probe failed: ${result.stderr.trim()}`)
|
|
96
|
+
}
|
|
97
|
+
|
|
84
98
|
async isCommitAncestor(ancestor: string, descendant: string): Promise<boolean> {
|
|
85
99
|
if (!this.repoRoot) throw new Error('local-git ancestry requires repoRoot')
|
|
86
100
|
if (!gitOid.safeParse(ancestor).success || !gitOid.safeParse(descendant).success)
|