@aviaratech/ai-delivery 0.3.34 → 0.3.36
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/CONTRIBUTING.md +12 -206
- package/README.md +57 -506
- package/dist/agent.d.ts +0 -2
- package/dist/agent.js +76 -16
- package/dist/agent.js.map +7 -1
- package/dist/agentReadiness.test.js +73 -67
- package/dist/agentReadiness.test.js.map +7 -1
- package/dist/boardReconcile.test.js +1746 -0
- package/dist/boardReconcile.test.js.map +7 -0
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +105 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +406 -485
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -25
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +434 -297
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +320 -14
- package/dist/config/deliveryConfig.js +472 -385
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +775 -584
- package/dist/config/deliveryConfig.test.js.map +7 -1
- package/dist/contributorChecks.test.js +1694 -916
- package/dist/contributorChecks.test.js.map +7 -1
- package/dist/currentConsumer.test.js +819 -737
- package/dist/currentConsumer.test.js.map +7 -1
- package/dist/currentTrackingScenario.test.js +499 -477
- package/dist/currentTrackingScenario.test.js.map +7 -1
- package/dist/delivery/common.js +160 -172
- package/dist/delivery/common.js.map +7 -1
- package/dist/delivery/delivery.test.js +509 -431
- package/dist/delivery/delivery.test.js.map +7 -1
- package/dist/delivery/evidence.d.ts +2 -2
- package/dist/delivery/evidence.js +133 -120
- package/dist/delivery/evidence.js.map +7 -1
- package/dist/delivery/index.js +7 -2
- package/dist/delivery/index.js.map +7 -1
- package/dist/delivery/legacy.js +65 -5
- package/dist/delivery/legacy.js.map +7 -1
- package/dist/delivery/policy.d.ts +10 -10
- package/dist/delivery/policy.js +211 -238
- package/dist/delivery/policy.js.map +7 -1
- package/dist/delivery/stage.d.ts +18 -18
- package/dist/delivery/stage.js +220 -235
- package/dist/delivery/stage.js.map +7 -1
- package/dist/deliveryBoard.d.ts +74 -0
- package/dist/deliveryBoard.js +644 -0
- package/dist/deliveryBoard.js.map +7 -0
- package/dist/deliveryBoard.test.d.ts +1 -0
- package/dist/deliveryBoard.test.js +649 -0
- package/dist/deliveryBoard.test.js.map +7 -0
- package/dist/deliveryHealth.test.js +179 -155
- package/dist/deliveryHealth.test.js.map +7 -1
- package/dist/dependencyCompatibility.test.js +154 -140
- package/dist/dependencyCompatibility.test.js.map +7 -1
- package/dist/directoryIndependent.test.js +417 -383
- package/dist/directoryIndependent.test.js.map +7 -1
- package/dist/dispatch.d.ts +17 -12
- package/dist/dispatch.js +330 -322
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +16 -3
- package/dist/errors.js +104 -82
- package/dist/errors.js.map +7 -1
- package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
- package/dist/fixtures/deliveryBoardReplay.js +617 -0
- package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
- package/dist/fixtures/discovery.d.ts +59 -19
- package/dist/fixtures/discovery.js +96 -90
- package/dist/fixtures/discovery.js.map +7 -1
- package/dist/fixtures/inertEntrypointChild.js +57 -56
- package/dist/fixtures/inertEntrypointChild.js.map +7 -1
- package/dist/fixtures/inertEntrypoints.d.ts +1 -1
- package/dist/fixtures/inertEntrypoints.js +321 -276
- package/dist/fixtures/inertEntrypoints.js.map +7 -1
- package/dist/fixtures/inertTarget.d.ts +78 -7
- package/dist/fixtures/inertTarget.js +769 -691
- package/dist/fixtures/inertTarget.js.map +7 -1
- package/dist/fixtures/issue63.d.ts +4 -3
- package/dist/fixtures/issue63.js +260 -274
- package/dist/fixtures/issue63.js.map +7 -1
- package/dist/fixtures/issueProjectItems.d.ts +20 -0
- package/dist/fixtures/issueProjectItems.js +15 -0
- package/dist/fixtures/issueProjectItems.js.map +7 -0
- package/dist/fixtures/readView.d.ts +120 -0
- package/dist/fixtures/readView.js +172 -0
- package/dist/fixtures/readView.js.map +7 -0
- package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
- package/dist/fixtures/recordedGitHubFlows.js +109 -0
- package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
- package/dist/genericCompatibility.test.js +64 -55
- package/dist/genericCompatibility.test.js.map +7 -1
- package/dist/git.js +73 -67
- package/dist/git.js.map +7 -1
- package/dist/gitProcess.d.ts +1 -1
- package/dist/gitProcess.js +58 -53
- package/dist/gitProcess.js.map +7 -1
- package/dist/github/client.d.ts +2 -2
- package/dist/github/client.js +484 -379
- package/dist/github/client.js.map +7 -1
- package/dist/github/commandIdentityPolicy.js +44 -51
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +3 -0
- package/dist/github/discovery.js +197 -201
- package/dist/github/discovery.js.map +7 -1
- package/dist/github/discovery.test.js +223 -177
- package/dist/github/discovery.test.js.map +7 -1
- package/dist/github/issueHistory.d.ts +2 -2
- package/dist/github/issueHistory.js +117 -125
- package/dist/github/issueHistory.js.map +7 -1
- package/dist/github/machineAuth.d.ts +1 -1
- package/dist/github/machineAuth.js +126 -117
- package/dist/github/machineAuth.js.map +7 -1
- package/dist/github/machineAuth.test.js +755 -639
- package/dist/github/machineAuth.test.js.map +7 -1
- package/dist/github/nativeIssueMetadata.js +286 -273
- package/dist/github/nativeIssueMetadata.js.map +7 -1
- package/dist/github/projectDelivery.d.ts +53 -1
- package/dist/github/projectDelivery.js +623 -460
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.d.ts +5 -2
- package/dist/github/relationships.js +434 -333
- package/dist/github/relationships.js.map +7 -1
- package/dist/github/repo.d.ts +1 -0
- package/dist/github/repo.js +123 -96
- package/dist/github/repo.js.map +7 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +7 -1
- package/dist/issue.d.ts +103 -7
- package/dist/issue.js +2104 -1547
- package/dist/issue.js.map +7 -1
- package/dist/issue63History.test.js +40 -42
- package/dist/issue63History.test.js.map +7 -1
- package/dist/issue63Routes.test.js +154 -143
- package/dist/issue63Routes.test.js.map +7 -1
- package/dist/issueBatchUpdate.test.js +1004 -683
- package/dist/issueBatchUpdate.test.js.map +7 -1
- package/dist/issueBlockerGuard.test.js +262 -226
- package/dist/issueBlockerGuard.test.js.map +7 -1
- package/dist/issueContract.d.ts +23 -4
- package/dist/issueContract.js +416 -395
- package/dist/issueContract.js.map +7 -1
- package/dist/issueContract.test.d.ts +4 -3
- package/dist/issueContract.test.js +358 -321
- package/dist/issueContract.test.js.map +7 -1
- package/dist/issueDates.test.js +235 -233
- package/dist/issueDates.test.js.map +7 -1
- package/dist/issueInfoReadback.test.js +304 -190
- package/dist/issueInfoReadback.test.js.map +7 -1
- package/dist/issueIntake.test.js +1945 -1732
- package/dist/issueIntake.test.js.map +7 -1
- package/dist/issueJournal.d.ts +40 -19
- package/dist/issueJournal.js +229 -138
- package/dist/issueJournal.js.map +7 -1
- package/dist/issueJournal.test.js +605 -422
- package/dist/issueJournal.test.js.map +7 -1
- package/dist/issueRollup.test.d.ts +1 -0
- package/dist/issueRollup.test.js +476 -0
- package/dist/issueRollup.test.js.map +7 -0
- package/dist/issueTracking.test.js +1088 -593
- package/dist/issueTracking.test.js.map +7 -1
- package/dist/issueWriteRecovery.test.d.ts +1 -0
- package/dist/issueWriteRecovery.test.js +260 -0
- package/dist/issueWriteRecovery.test.js.map +7 -0
- package/dist/lifecycle.test.js +112 -441
- package/dist/lifecycle.test.js.map +7 -1
- package/dist/logger.js +80 -74
- package/dist/logger.js.map +7 -1
- package/dist/mcp/index.js +116 -90
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +790 -220
- package/dist/mcp/tools.js +267 -333
- package/dist/mcp/tools.js.map +7 -1
- package/dist/pluginAuthProbe.js +63 -52
- package/dist/pluginAuthProbe.js.map +7 -1
- package/dist/pluginAuthProbe.test.js +85 -62
- package/dist/pluginAuthProbe.test.js.map +7 -1
- package/dist/pluginCredentials.test.js +282 -259
- package/dist/pluginCredentials.test.js.map +7 -1
- package/dist/pluginDoctor.test.js +653 -588
- package/dist/pluginDoctor.test.js.map +7 -1
- package/dist/pluginInstaller.d.ts +7 -5
- package/dist/pluginInstaller.js +1173 -1231
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1822 -1283
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +485 -305
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +132 -94
- package/dist/pr.js +1521 -1323
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +1678 -632
- package/dist/pr.test.js.map +7 -1
- package/dist/prAssociation.test.js +2419 -1788
- package/dist/prAssociation.test.js.map +7 -1
- package/dist/prDispatch.test.js +150 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +183 -0
- package/dist/readView.js +217 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +119 -0
- package/dist/readView.test.js.map +7 -0
- package/dist/releaseReconciliation.test.js +267 -288
- package/dist/releaseReconciliation.test.js.map +7 -1
- package/dist/releaseWorkflow.test.js +2493 -422
- package/dist/releaseWorkflow.test.js.map +7 -1
- package/dist/review.d.ts +738 -2
- package/dist/review.js +601 -348
- package/dist/review.js.map +7 -1
- package/dist/review.test.js +1218 -812
- package/dist/review.test.js.map +7 -1
- package/dist/reviewSubmit.test.d.ts +1 -0
- package/dist/reviewSubmit.test.js +747 -0
- package/dist/reviewSubmit.test.js.map +7 -0
- package/dist/services/agentReadinessService.js +42 -37
- package/dist/services/agentReadinessService.js.map +7 -1
- package/dist/services/blockerGuardService.js +188 -188
- package/dist/services/blockerGuardService.js.map +7 -1
- package/dist/services/boardReconcileService.d.ts +1204 -0
- package/dist/services/boardReconcileService.js +1445 -0
- package/dist/services/boardReconcileService.js.map +7 -0
- package/dist/services/deliveryAdmission.d.ts +2 -0
- package/dist/services/deliveryAdmission.js +129 -152
- package/dist/services/deliveryAdmission.js.map +7 -1
- package/dist/services/deliveryHealthService.js +197 -199
- package/dist/services/deliveryHealthService.js.map +7 -1
- package/dist/services/legacyIssueMigration.js +263 -277
- package/dist/services/legacyIssueMigration.js.map +7 -1
- package/dist/services/worktreeRegistry.d.ts +27 -119
- package/dist/services/worktreeRegistry.js +765 -1182
- package/dist/services/worktreeRegistry.js.map +7 -1
- package/dist/stagedChecks.test.js +396 -194
- package/dist/stagedChecks.test.js.map +7 -1
- package/dist/start.test.js +99 -95
- package/dist/start.test.js.map +7 -1
- package/dist/stdoutRegression.test.js +354 -350
- package/dist/stdoutRegression.test.js.map +7 -1
- package/dist/targetPolicyDiscovery.test.js +141 -143
- package/dist/targetPolicyDiscovery.test.js.map +7 -1
- package/dist/targetPolicyEntrypoints.test.js +308 -269
- package/dist/targetPolicyEntrypoints.test.js.map +7 -1
- package/dist/targetPolicyLocal.test.js +580 -1051
- package/dist/targetPolicyLocal.test.js.map +7 -1
- package/dist/targetPolicyRoutes.test.js +305 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +463 -0
- package/dist/targetRepositoryExecution.test.js.map +7 -0
- package/dist/terminalMessages.js +41 -35
- package/dist/terminalMessages.js.map +7 -1
- package/dist/toolOutput.d.ts +2 -0
- package/dist/toolOutput.js +36 -0
- package/dist/toolOutput.js.map +7 -0
- package/dist/toolOutput.test.d.ts +1 -0
- package/dist/toolOutput.test.js +240 -0
- package/dist/toolOutput.test.js.map +7 -0
- package/dist/utils/atomicJson.js +84 -76
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.js +15 -18
- package/dist/utils/filesystem.js.map +7 -1
- package/dist/utils/lockfile.js +68 -71
- package/dist/utils/lockfile.js.map +7 -1
- package/dist/verification.d.ts +1 -19
- package/dist/verification.js +1020 -1929
- package/dist/verification.js.map +7 -1
- package/dist/verificationGate.test.js +127 -117
- package/dist/verificationGate.test.js.map +7 -1
- package/dist/version.d.ts +6 -0
- package/dist/version.js +24 -10
- package/dist/version.js.map +7 -1
- package/dist/worktree.d.ts +3 -15
- package/dist/worktree.js +97 -177
- package/dist/worktree.js.map +7 -1
- package/package.json +10 -8
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +47 -156
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +261 -43
- package/plugins/ai-delivery/runtime/dist/cli.js +369 -125
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
- package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
- package/dist/investigationCompletion.test.js +0 -728
- package/dist/investigationCompletion.test.js.map +0 -1
- package/dist/setup.d.ts +0 -60
- package/dist/setup.js +0 -585
- package/dist/setup.js.map +0 -1
- package/dist/setup.test.js +0 -3058
- package/dist/setup.test.js.map +0 -1
- package/dist/worktreeTransition.d.ts +0 -211
- package/dist/worktreeTransition.js +0 -1037
- package/dist/worktreeTransition.js.map +0 -1
- package/dist/worktreeTransition.test.js +0 -1191
- package/dist/worktreeTransition.test.js.map +0 -1
- /package/dist/{investigationCompletion.test.d.ts → boardReconcile.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → callerErrors.test.d.ts} +0 -0
package/dist/pr.js
CHANGED
|
@@ -1,1410 +1,1608 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { DeliveryError } from "./errors.js";
|
|
4
|
+
import * as githubClients from "./github/client.js";
|
|
5
|
+
import { getNativeBlockerRelationships } from "./github/relationships.js";
|
|
6
|
+
import { issueBranch, linkedIssueBranches, startIssueBranch } from "./issue.js";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { primaryGitRoot, defaultBaseRef, gitExitCode, git } from "./git.js";
|
|
9
|
+
import { resolveRepoFromRemote } from "./github/repo.js";
|
|
10
|
+
import { removeFinishedIssueSource } from "./worktree.js";
|
|
11
|
+
import {
|
|
12
|
+
listWorktreesStrict,
|
|
13
|
+
getIssueWorktreeStrict,
|
|
14
|
+
reconcileCompletedIssueWorktreeDelivery
|
|
15
|
+
} from "./services/worktreeRegistry.js";
|
|
16
|
+
import {
|
|
17
|
+
parseReviewArtifact,
|
|
18
|
+
readRequiredReviewState,
|
|
19
|
+
ReviewSubmissionError,
|
|
20
|
+
submitReview
|
|
21
|
+
} from "./review.js";
|
|
22
|
+
import { parseIssueBody } from "./issueContract.js";
|
|
17
23
|
const Sha = /^[a-f0-9]{40}$/u;
|
|
18
24
|
const Branch = /^(?!.*(?:\.\.|@\{|\/\/))[A-Za-z0-9._/-]+$/u;
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
const DeliveryPrFooter = "\n\n<!-- ai-delivery:pr@1 -->";
|
|
26
|
+
function activeMarkerPositions(text, pattern) {
|
|
27
|
+
const ignored = [];
|
|
28
|
+
const uncertain = [];
|
|
29
|
+
const inline = [];
|
|
30
|
+
let paragraph = null;
|
|
31
|
+
let fence = null;
|
|
32
|
+
let comment = false;
|
|
33
|
+
let htmlEnd = null;
|
|
34
|
+
let container = false;
|
|
35
|
+
let quoted = false;
|
|
36
|
+
let blank = true;
|
|
37
|
+
const flush = (end) => {
|
|
38
|
+
if (paragraph !== null) inline.push([paragraph, end]);
|
|
39
|
+
paragraph = null;
|
|
40
|
+
};
|
|
41
|
+
for (const line of text.matchAll(/[^\n]*(?:\n|$)/gu)) {
|
|
42
|
+
if (!line[0]) continue;
|
|
43
|
+
const start = line.index;
|
|
44
|
+
const end = start + line[0].length;
|
|
45
|
+
const content = line[0].replace(/\r?\n$/u, "");
|
|
46
|
+
if (comment) {
|
|
47
|
+
const closing = content.indexOf("-->");
|
|
48
|
+
ignored.push([start, closing < 0 ? end : start + closing + 3]);
|
|
49
|
+
if (closing >= 0) comment = false;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (htmlEnd !== null) {
|
|
53
|
+
if (htmlEnd === "blank" && !content.trim()) htmlEnd = null;
|
|
54
|
+
else {
|
|
55
|
+
uncertain.push([start, end]);
|
|
56
|
+
if (htmlEnd !== "blank" && htmlEnd.test(content)) htmlEnd = null;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const edge = /^ {0,3}(`{3,}|~{3,})(.*)$/u.exec(content);
|
|
61
|
+
if (fence !== null) {
|
|
62
|
+
ignored.push([start, end]);
|
|
63
|
+
if (edge && edge[1][0] === fence[0] && edge[1].length >= fence.length && !edge[2].trim()) fence = null;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (!content.trim()) {
|
|
67
|
+
flush(start);
|
|
68
|
+
quoted = false;
|
|
69
|
+
blank = true;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (/^ {0,3}>/u.test(content)) {
|
|
73
|
+
flush(start);
|
|
74
|
+
ignored.push([start, end]);
|
|
75
|
+
quoted = true;
|
|
76
|
+
blank = false;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (blank && /^\S/u.test(content) && !/^[-+*\d]/u.test(content)) container = false;
|
|
80
|
+
const indented = /^(?: {4}| {0,3}\t)/u.test(content);
|
|
81
|
+
if (indented && paragraph === null) {
|
|
82
|
+
(container || quoted ? uncertain : ignored).push([start, end]);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (edge && (edge[1][0] !== "`" || !edge[2].includes("`"))) {
|
|
86
|
+
flush(start);
|
|
87
|
+
if (container || quoted) uncertain.push([start, text.length]);
|
|
88
|
+
ignored.push([start, end]);
|
|
89
|
+
fence = edge[1];
|
|
90
|
+
} else if (/^ {0,3}<!--/u.test(content)) {
|
|
91
|
+
flush(start);
|
|
92
|
+
const opening = content.indexOf("<!--");
|
|
93
|
+
const closing = content.indexOf("-->", opening + 4);
|
|
94
|
+
ignored.push([start + opening + 4, closing < 0 ? end : start + closing + 3]);
|
|
95
|
+
if (closing < 0) comment = true;
|
|
96
|
+
} else if (/^ {0,3}<\/?[A-Za-z!?]/u.test(content)) {
|
|
97
|
+
flush(start);
|
|
98
|
+
uncertain.push([start, end]);
|
|
99
|
+
const closing = /^ {0,3}<\?/u.test(content) ? /\?>/u : /^ {0,3}<!\[CDATA\[/u.test(content) ? /\]\]>/u : /^ {0,3}<!/u.test(content) ? />/u : /^ {0,3}<(?:pre|script|style|textarea)(?:[ \t>]|$)/iu.test(content) ? /<\/(?:pre|script|style|textarea)>/iu : null;
|
|
100
|
+
htmlEnd = closing === null ? "blank" : closing.test(content) ? null : closing;
|
|
101
|
+
} else if (/^ {0,3}(?:#{1,6}(?:[ \t]|$)|(?:[-+*]|\d+[.)])[ \t])/u.test(content) || /^ {0,3}(?:=+|-+)[ \t]*$/u.test(content) || /^ {0,3}(?:(?:\*[ \t]*){3,}|(?:_[ \t]*){3,}|(?:-[ \t]*){3,})$/u.test(content)) {
|
|
102
|
+
flush(start);
|
|
103
|
+
inline.push([start, end]);
|
|
104
|
+
container = /^ {0,3}(?:[-+*]|\d+[.)])[ \t]/u.test(content);
|
|
105
|
+
} else {
|
|
106
|
+
if (quoted || container) uncertain.push([start, end]);
|
|
107
|
+
paragraph ??= start;
|
|
108
|
+
}
|
|
109
|
+
blank = false;
|
|
110
|
+
}
|
|
111
|
+
flush(text.length);
|
|
112
|
+
for (const [start, end] of inline) {
|
|
113
|
+
const unit = text.slice(start, end);
|
|
114
|
+
const tokens = /\\[\\`<]|`+|<!--/gu;
|
|
115
|
+
for (let token = tokens.exec(unit); token; token = tokens.exec(unit)) {
|
|
116
|
+
if (token[0].startsWith("\\")) {
|
|
117
|
+
ignored.push([start + token.index + 1, start + tokens.lastIndex]);
|
|
118
|
+
} else if (token[0] === "<!--") {
|
|
119
|
+
const closing = unit.indexOf("-->", tokens.lastIndex);
|
|
120
|
+
if (closing < 0) uncertain.push([start + token.index, end]);
|
|
121
|
+
else {
|
|
122
|
+
ignored.push([start + tokens.lastIndex, start + closing + 3]);
|
|
123
|
+
tokens.lastIndex = closing + 3;
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
const ticks = /`+/gu;
|
|
127
|
+
ticks.lastIndex = tokens.lastIndex;
|
|
128
|
+
for (let closing = ticks.exec(unit); closing; closing = ticks.exec(unit)) {
|
|
129
|
+
if (closing[0].length !== token[0].length) continue;
|
|
130
|
+
ignored.push([start + token.index, start + ticks.lastIndex]);
|
|
131
|
+
tokens.lastIndex = ticks.lastIndex;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const candidates = [...text.matchAll(pattern)].map((match) => match.index);
|
|
138
|
+
if (candidates.some((position) => uncertain.some(([start, end]) => position >= start && position < end))) return null;
|
|
139
|
+
return candidates.filter((position) => !ignored.some(([start, end]) => position >= start && position < end));
|
|
140
|
+
}
|
|
141
|
+
function hasDeliveryPrMarker(body) {
|
|
142
|
+
if (!body.endsWith(DeliveryPrFooter)) return false;
|
|
143
|
+
const prefix = body.slice(0, -DeliveryPrFooter.length);
|
|
144
|
+
const active = activeMarkerPositions(body, /<!--\s*ai-delivery:pr@[^\n]*?(?:-->|$)/gmu);
|
|
145
|
+
return Boolean(prefix.trim()) && active?.length === 1 && active[0] === prefix.length + 2;
|
|
146
|
+
}
|
|
147
|
+
function hasDeliveryMergeTrailer(message) {
|
|
148
|
+
const trailer = /\n\nDelivered-by: ai-delivery\n?$/u.exec(message);
|
|
149
|
+
if (!trailer || !message.slice(0, trailer.index).trim()) return false;
|
|
150
|
+
const active = activeMarkerPositions(message, /^Delivered-by: ai-delivery[ \t]*$/gmu);
|
|
151
|
+
return active?.length === 1 && active[0] === trailer.index + 2;
|
|
152
|
+
}
|
|
153
|
+
function publicationBody(body, previous) {
|
|
154
|
+
function marked(value) {
|
|
155
|
+
const active = activeMarkerPositions(value, /<!--\s*ai-delivery:pr@[^\n]*?(?:-->|$)/gmu);
|
|
156
|
+
if (active === null || active.length > 0 && !hasDeliveryPrMarker(value))
|
|
157
|
+
throw new DeliveryError("PR marker footer is malformed, misplaced or ambiguous; reconcile without repair.");
|
|
158
|
+
return active.length === 1;
|
|
159
|
+
}
|
|
160
|
+
const previousMarked = typeof previous === "string" && marked(previous);
|
|
161
|
+
const requestedMarked = marked(body);
|
|
162
|
+
if (previous !== void 0 && !previousMarked) {
|
|
163
|
+
if (requestedMarked) throw new DeliveryError("Historical unmarked PRs cannot receive a marker footer backfill.");
|
|
164
|
+
return body;
|
|
165
|
+
}
|
|
166
|
+
if (requestedMarked) return body;
|
|
167
|
+
const decorated = body + DeliveryPrFooter;
|
|
168
|
+
if (!hasDeliveryPrMarker(decorated))
|
|
169
|
+
throw new DeliveryError("PR marker footer would be ambiguous; retain the original body without repair.");
|
|
170
|
+
return decorated;
|
|
171
|
+
}
|
|
172
|
+
function deliverySquashMessage(body) {
|
|
173
|
+
const substantive = hasDeliveryPrMarker(body) ? body.slice(0, -DeliveryPrFooter.length) : body;
|
|
174
|
+
if (hasDeliveryMergeTrailer(substantive)) return substantive;
|
|
175
|
+
const message = `${substantive}
|
|
176
|
+
|
|
177
|
+
Delivered-by: ai-delivery`;
|
|
178
|
+
if (!hasDeliveryMergeTrailer(message))
|
|
179
|
+
throw new DeliveryError("Squash delivery trailer would be ambiguous; reconcile the message without repair.");
|
|
180
|
+
return message;
|
|
181
|
+
}
|
|
182
|
+
function hasClosingLink(body, issueNumber) {
|
|
183
|
+
const line = `Closes #${issueNumber}`;
|
|
184
|
+
return body === line || body?.startsWith(`${line}
|
|
185
|
+
`) === true || body?.startsWith(`${line}\r
|
|
186
|
+
`) === true;
|
|
187
|
+
}
|
|
188
|
+
function closingBody(issue, requested) {
|
|
189
|
+
const line = `Closes #${issue.number}`;
|
|
190
|
+
if (requested !== void 0)
|
|
191
|
+
return requested.startsWith(`${line}
|
|
192
|
+
`) || requested === line ? requested : `${line}
|
|
193
|
+
|
|
194
|
+
${requested}`;
|
|
195
|
+
const { outcome, acceptanceCriteria } = parseIssueBody(issue.body ?? "", { title: issue.title }).issue;
|
|
196
|
+
return [
|
|
197
|
+
line,
|
|
198
|
+
...outcome ? [`## Outcome
|
|
199
|
+
|
|
200
|
+
${outcome}`] : [],
|
|
201
|
+
...acceptanceCriteria.length ? [
|
|
202
|
+
`## Acceptance criteria
|
|
203
|
+
|
|
204
|
+
${acceptanceCriteria.map((ac) => `- [ ] ${ac.behavior}
|
|
205
|
+
Verified by: ${ac.verifiedBy}`).join("\n")}`
|
|
206
|
+
] : []
|
|
207
|
+
].join("\n\n");
|
|
208
|
+
}
|
|
21
209
|
function refuseClosingDirective(text) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
210
|
+
if (typeof text !== "string") throw new DeliveryError("Incomplete non-closing message readback.");
|
|
211
|
+
const normalized = text.replace(/\[[^\]\r\n]*\]\(([^()\s]+)\)/gu, "$1").replace(/[*_~`\\<>[\]]/gu, "");
|
|
212
|
+
if (/(?<![\p{L}\p{N}_-])(?:close[sd]?|fix(?:es|ed)?|resolve[sd]?)(?:\s*:\s*|\s+)(?:#[0-9]+|[A-Za-z0-9.-]+\/[A-Za-z0-9.-]+#[0-9]+|https?:\/\/(?:www\.)?github\.com\/[A-Za-z0-9.-]+\/[A-Za-z0-9.-]+\/(?:issues|pull)\/[0-9]+)/iu.test(
|
|
213
|
+
normalized
|
|
214
|
+
))
|
|
215
|
+
throw new DeliveryError("Non-closing delivery refuses closing directives in body, title or commit messages.");
|
|
27
216
|
}
|
|
28
217
|
function referenceLine(context, issueNumber) {
|
|
29
|
-
|
|
218
|
+
return `References ${context.config.repository}#${issueNumber}`;
|
|
30
219
|
}
|
|
31
220
|
function nonClosingBody(context, issueNumber, requested) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
221
|
+
refuseClosingDirective(requested);
|
|
222
|
+
const line = referenceLine(context, issueNumber);
|
|
223
|
+
const body = requested.startsWith(`${line}
|
|
224
|
+
`) || requested === line ? requested : `${line}
|
|
225
|
+
|
|
226
|
+
${requested}`;
|
|
227
|
+
verifyReferenceBody(context, issueNumber, body);
|
|
228
|
+
return body;
|
|
229
|
+
}
|
|
230
|
+
function hasReferenceBody(context, issueNumber, body) {
|
|
231
|
+
try {
|
|
35
232
|
verifyReferenceBody(context, issueNumber, body);
|
|
36
|
-
return
|
|
233
|
+
return true;
|
|
234
|
+
} catch {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
37
237
|
}
|
|
38
238
|
function verifyReferenceBody(context, issueNumber, body) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
throw new DeliveryError('Non-closing PR body must retain one leading canonical References line.');
|
|
239
|
+
refuseClosingDirective(body);
|
|
240
|
+
const lines = body.split(/\r?\n/u);
|
|
241
|
+
if (lines[0] !== referenceLine(context, issueNumber) || lines.filter((line) => /^References\s/iu.test(line)).length !== 1)
|
|
242
|
+
throw new DeliveryError("Non-closing PR body must retain one leading canonical References line.");
|
|
44
243
|
}
|
|
45
244
|
function pageCursor(connection, seen) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
throw new DeliveryError('Non-closing native pagination did not advance.');
|
|
55
|
-
seen.add(info.endCursor);
|
|
56
|
-
return info.endCursor;
|
|
245
|
+
const info = connection.pageInfo;
|
|
246
|
+
if (!info || typeof info.hasNextPage !== "boolean" || !(info.endCursor === null || typeof info.endCursor === "string"))
|
|
247
|
+
throw new DeliveryError("Incomplete non-closing native pagination.");
|
|
248
|
+
if (!info.hasNextPage) return null;
|
|
249
|
+
if (!info.endCursor || seen.has(info.endCursor))
|
|
250
|
+
throw new DeliveryError("Non-closing native pagination did not advance.");
|
|
251
|
+
seen.add(info.endCursor);
|
|
252
|
+
return info.endCursor;
|
|
57
253
|
}
|
|
58
254
|
async function openReferenceIssue(context, issueNumber) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
typeof issue.node_id !== 'string' ||
|
|
64
|
-
!issue.node_id ||
|
|
65
|
-
typeof issue.title !== 'string' ||
|
|
66
|
-
typeof issue.body !== 'string' ||
|
|
67
|
-
issue.html_url?.toLowerCase() !==
|
|
68
|
-
`https://github.com/${context.config.repository}/issues/${issueNumber}`.toLowerCase())
|
|
69
|
-
throw new DeliveryError('Non-closing delivery requires the exact canonical OPEN issue and complete title/body.');
|
|
70
|
-
return issue;
|
|
255
|
+
const issue = (await context.clients.rest.issues.get({ ...context.repo, issue_number: issueNumber })).data;
|
|
256
|
+
if (issue.number !== issueNumber || "pull_request" in issue || issue.state !== "open" || typeof issue.node_id !== "string" || !issue.node_id || typeof issue.title !== "string" || typeof issue.body !== "string" || issue.html_url?.toLowerCase() !== `https://github.com/${context.config.repository}/issues/${issueNumber}`.toLowerCase())
|
|
257
|
+
throw new DeliveryError("Non-closing delivery requires the exact canonical OPEN issue and complete title/body.");
|
|
258
|
+
return issue;
|
|
71
259
|
}
|
|
72
260
|
function sameReferencePr(before, after, expectedMerge = false) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
after.state !== 'closed' ||
|
|
78
|
-
after.draft ||
|
|
79
|
-
!after.merged
|
|
80
|
-
: before.state !== after.state || before.draft !== after.draft || before.merged !== after.merged)
|
|
81
|
-
throw new DeliveryError('Non-closing PR state/draft/merged readback drifted; reconcile read-only.');
|
|
82
|
-
if (before.node_id !== after.node_id ||
|
|
83
|
-
before.head.sha !== after.head.sha ||
|
|
84
|
-
before.head.ref !== after.head.ref ||
|
|
85
|
-
before.base.sha !== after.base.sha ||
|
|
86
|
-
before.base.ref !== after.base.ref ||
|
|
87
|
-
before.body !== after.body ||
|
|
88
|
-
before.title !== after.title ||
|
|
89
|
-
before.user.login.toLowerCase() !== after.user.login.toLowerCase())
|
|
90
|
-
throw new DeliveryError('Non-closing PR identity, reference, message or head/base drifted; reconcile read-only.');
|
|
261
|
+
if (expectedMerge ? before.state !== "open" || before.draft || before.merged || after.state !== "closed" || after.draft || !after.merged : before.state !== after.state || before.draft !== after.draft || before.merged !== after.merged)
|
|
262
|
+
throw new DeliveryError("Non-closing PR state/draft/merged readback drifted; reconcile read-only.");
|
|
263
|
+
if (before.node_id !== after.node_id || before.head.sha !== after.head.sha || before.head.ref !== after.head.ref || before.base.sha !== after.base.sha || before.base.ref !== after.base.ref || before.body !== after.body || before.title !== after.title || before.user.login.toLowerCase() !== after.user.login.toLowerCase())
|
|
264
|
+
throw new DeliveryError("Non-closing PR identity, reference, message or head/base drifted; reconcile read-only.");
|
|
91
265
|
}
|
|
92
266
|
function sameReferenceIssue(before, after) {
|
|
93
|
-
|
|
94
|
-
|
|
267
|
+
if (before.node_id !== after.node_id || before.title !== after.title || before.body !== after.body)
|
|
268
|
+
throw new DeliveryError("Non-closing issue identity/title/criteria drifted; reconcile read-only.");
|
|
95
269
|
}
|
|
96
270
|
function nonClosingMode(value) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return value === true;
|
|
271
|
+
if (value !== void 0 && typeof value !== "boolean") throw new DeliveryError("nonClosing must be a boolean.");
|
|
272
|
+
return value === true;
|
|
100
273
|
}
|
|
101
274
|
async function nonClosingRoute(context, base) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
275
|
+
const authorContext = context.clients.role === "author" ? context : {
|
|
276
|
+
...context,
|
|
277
|
+
clients: await githubClients.createDeliveryGitHubClients({
|
|
278
|
+
config: context.config,
|
|
279
|
+
...context.credentialEnvironment === void 0 ? {} : { env: context.credentialEnvironment },
|
|
280
|
+
identity: context.config.roles.author.identity,
|
|
281
|
+
role: "author"
|
|
282
|
+
}),
|
|
283
|
+
reviewerClients: context.clients
|
|
284
|
+
};
|
|
285
|
+
const route = await preflightReviewRoute(authorContext, base);
|
|
286
|
+
if (route.rules.visibility !== "complete" || route.approvalEligibility === "insufficient-permission")
|
|
287
|
+
throw new DeliveryError(
|
|
288
|
+
"Non-closing delivery requires complete native rule visibility and an independent reviewer route."
|
|
289
|
+
);
|
|
290
|
+
return route;
|
|
117
291
|
}
|
|
118
292
|
async function verifyNonClosingCommits(context, pr) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
!validSha(commit.oid) ||
|
|
146
|
-
commits.has(commit.oid) ||
|
|
147
|
-
!commit.parents ||
|
|
148
|
-
!Array.isArray(commit.parents.nodes) ||
|
|
149
|
-
commit.parents.nodes.length > 100 ||
|
|
150
|
-
!Number.isSafeInteger(commit.parents.totalCount) ||
|
|
151
|
-
commit.parents.totalCount < 1 ||
|
|
152
|
-
commit.parents.totalCount !== commit.parents.nodes.length ||
|
|
153
|
-
commit.parents.pageInfo?.hasNextPage !== false ||
|
|
154
|
-
commit.parents.nodes.some((parent) => !validSha(parent?.oid)))
|
|
155
|
-
throw new DeliveryError('Incomplete, duplicate or truncated introduced commit identity/parents.');
|
|
156
|
-
refuseClosingDirective(commit.message);
|
|
157
|
-
commits.set(commit.oid, commit.message);
|
|
158
|
-
}
|
|
159
|
-
cursor = pageCursor(connection, cursors);
|
|
160
|
-
if (cursor === null) {
|
|
161
|
-
if (commits.size !== total || !commits.has(pr.head.sha))
|
|
162
|
-
throw new DeliveryError('Introduced commit count/head is incomplete.');
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
293
|
+
let cursor = null;
|
|
294
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
295
|
+
const commits = /* @__PURE__ */ new Map();
|
|
296
|
+
let total;
|
|
297
|
+
for (let page = 0; page < 20; page++) {
|
|
298
|
+
const data = await context.clients.graphql(
|
|
299
|
+
"query DeliveryNonClosingCommits($owner:String!,$repo:String!,$number:Int!,$cursor:String){repository(owner:$owner,name:$repo){nameWithOwner pullRequest(number:$number){id number headRefOid baseRefOid baseRefName commits(first:100,after:$cursor){totalCount nodes{commit{oid message parents(first:100){totalCount nodes{oid} pageInfo{hasNextPage endCursor}}}} pageInfo{hasNextPage endCursor}}}}}",
|
|
300
|
+
{ ...context.repo, number: pr.number, cursor }
|
|
301
|
+
);
|
|
302
|
+
const live = data.repository?.pullRequest;
|
|
303
|
+
const connection = live?.commits;
|
|
304
|
+
if (data.repository?.nameWithOwner?.toLowerCase() !== context.config.repository.toLowerCase() || live?.id !== pr.node_id || live.number !== pr.number || live.headRefOid !== pr.head.sha || live.baseRefOid !== pr.base.sha || live.baseRefName !== pr.base.ref || !connection || !Array.isArray(connection.nodes) || connection.nodes.length > 100 || !Number.isSafeInteger(connection.totalCount) || connection.totalCount < 1 || connection.totalCount > 2e3 || total !== void 0 && total !== connection.totalCount)
|
|
305
|
+
throw new DeliveryError("Incomplete or moved introduced commit graph at the non-closing head/base.");
|
|
306
|
+
total = connection.totalCount;
|
|
307
|
+
for (const node of connection.nodes) {
|
|
308
|
+
const commit = node?.commit;
|
|
309
|
+
if (!commit || !validSha(commit.oid) || commits.has(commit.oid) || !commit.parents || !Array.isArray(commit.parents.nodes) || commit.parents.nodes.length > 100 || !Number.isSafeInteger(commit.parents.totalCount) || commit.parents.totalCount < 1 || commit.parents.totalCount !== commit.parents.nodes.length || commit.parents.pageInfo?.hasNextPage !== false || commit.parents.nodes.some((parent) => !validSha(parent?.oid)))
|
|
310
|
+
throw new DeliveryError("Incomplete, duplicate or truncated introduced commit identity/parents.");
|
|
311
|
+
refuseClosingDirective(commit.message);
|
|
312
|
+
commits.set(commit.oid, commit.message);
|
|
313
|
+
}
|
|
314
|
+
cursor = pageCursor(connection, cursors);
|
|
315
|
+
if (cursor === null) {
|
|
316
|
+
if (commits.size !== total || !commits.has(pr.head.sha))
|
|
317
|
+
throw new DeliveryError("Introduced commit count/head is incomplete.");
|
|
318
|
+
return;
|
|
165
319
|
}
|
|
166
|
-
|
|
320
|
+
}
|
|
321
|
+
throw new DeliveryError("Non-closing commit graph exceeds the bounded readback window.");
|
|
167
322
|
}
|
|
168
323
|
async function verifyUnpublishedCommits(context, baseSha, headSha) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
comparison.commits.length > 100)
|
|
187
|
-
throw new DeliveryError('Incomplete introduced commit range before non-closing publication.');
|
|
188
|
-
total = comparison.total_commits;
|
|
189
|
-
for (const commit of comparison.commits) {
|
|
190
|
-
if (!validSha(commit.sha) ||
|
|
191
|
-
commits.has(commit.sha) ||
|
|
192
|
-
!Array.isArray(commit.parents) ||
|
|
193
|
-
commit.parents.length < 1 ||
|
|
194
|
-
commit.parents.length > 100 ||
|
|
195
|
-
commit.parents.some((parent) => !validSha(parent.sha)))
|
|
196
|
-
throw new DeliveryError('Incomplete or duplicate introduced commit identity.');
|
|
197
|
-
refuseClosingDirective(commit.commit?.message);
|
|
198
|
-
commits.add(commit.sha);
|
|
199
|
-
}
|
|
200
|
-
if (commits.size === total && commits.has(headSha))
|
|
201
|
-
return;
|
|
202
|
-
if (comparison.commits.length < 100)
|
|
203
|
-
throw new DeliveryError('Truncated introduced commit range before publication.');
|
|
324
|
+
const commits = /* @__PURE__ */ new Set();
|
|
325
|
+
let total;
|
|
326
|
+
for (let page = 1; page <= 20; page++) {
|
|
327
|
+
const comparison = (await context.clients.rest.repos.compareCommitsWithBasehead({
|
|
328
|
+
...context.repo,
|
|
329
|
+
basehead: `${baseSha}...${headSha}`,
|
|
330
|
+
per_page: 100,
|
|
331
|
+
page
|
|
332
|
+
})).data;
|
|
333
|
+
if (comparison.base_commit?.sha !== baseSha || !validSha(comparison.merge_base_commit?.sha) || !["ahead", "diverged"].includes(comparison.status) || !Number.isSafeInteger(comparison.total_commits) || comparison.total_commits < 1 || comparison.total_commits > 2e3 || total !== void 0 && total !== comparison.total_commits || !Array.isArray(comparison.commits) || comparison.commits.length > 100)
|
|
334
|
+
throw new DeliveryError("Incomplete introduced commit range before non-closing publication.");
|
|
335
|
+
total = comparison.total_commits;
|
|
336
|
+
for (const commit of comparison.commits) {
|
|
337
|
+
if (!validSha(commit.sha) || commits.has(commit.sha) || !Array.isArray(commit.parents) || commit.parents.length < 1 || commit.parents.length > 100 || commit.parents.some((parent) => !validSha(parent.sha)))
|
|
338
|
+
throw new DeliveryError("Incomplete or duplicate introduced commit identity.");
|
|
339
|
+
refuseClosingDirective(commit.commit?.message);
|
|
340
|
+
commits.add(commit.sha);
|
|
204
341
|
}
|
|
205
|
-
|
|
342
|
+
if (commits.size === total && commits.has(headSha)) return;
|
|
343
|
+
if (comparison.commits.length < 100)
|
|
344
|
+
throw new DeliveryError("Truncated introduced commit range before publication.");
|
|
345
|
+
}
|
|
346
|
+
throw new DeliveryError("Introduced commit range exceeds the bounded readback window.");
|
|
206
347
|
}
|
|
207
|
-
async function
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const signature = JSON.stringify([
|
|
264
|
-
source.__typename,
|
|
265
|
-
source.id,
|
|
266
|
-
source.number,
|
|
267
|
-
source.repository.id,
|
|
268
|
-
source.repository.nameWithOwner.toLowerCase(),
|
|
269
|
-
referenced.id,
|
|
270
|
-
referenced.number,
|
|
271
|
-
referenced.repository.id,
|
|
272
|
-
referenced.repository.nameWithOwner.toLowerCase(),
|
|
273
|
-
event.actor.login.toLowerCase(),
|
|
274
|
-
event.isCrossRepository,
|
|
275
|
-
event.willCloseTarget,
|
|
276
|
-
]);
|
|
277
|
-
if (events.has(event.id) && events.get(event.id) !== signature)
|
|
278
|
-
throw new DeliveryError('Conflicting duplicate native reference event.');
|
|
279
|
-
events.set(event.id, signature);
|
|
280
|
-
if (source.id === pr.node_id ||
|
|
281
|
-
(source.__typename === 'PullRequest' &&
|
|
282
|
-
source.number === pr.number &&
|
|
283
|
-
source.repository.nameWithOwner.toLowerCase() === context.config.repository.toLowerCase())) {
|
|
284
|
-
if (source.__typename !== 'PullRequest' ||
|
|
285
|
-
source.id !== pr.node_id ||
|
|
286
|
-
source.number !== pr.number ||
|
|
287
|
-
source.repository.id !== repository.node_id ||
|
|
288
|
-
source.repository.nameWithOwner.toLowerCase() !== context.config.repository.toLowerCase() ||
|
|
289
|
-
event.isCrossRepository ||
|
|
290
|
-
event.willCloseTarget !== false ||
|
|
291
|
-
event.actor.login.toLowerCase() !== route.author.actorLogin.toLowerCase())
|
|
292
|
-
throw new DeliveryError('Conflicting, closing or unauthorized native PR reference.');
|
|
293
|
-
matched = true;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
cursor = pageCursor(connection, cursors);
|
|
297
|
-
if (cursor === null)
|
|
298
|
-
break;
|
|
299
|
-
if (page === 19)
|
|
300
|
-
throw new DeliveryError('Native non-closing references exceed the bounded readback window.');
|
|
348
|
+
async function readNonClosingReference(context, issueNumber, pr, forReview = false) {
|
|
349
|
+
if (typeof pr.node_id !== "string" || !pr.node_id || pr.html_url?.toLowerCase() !== `https://github.com/${context.config.repository}/pull/${pr.number}`.toLowerCase())
|
|
350
|
+
throw new DeliveryError("Incomplete non-closing PR node identity.");
|
|
351
|
+
verifyReferenceBody(context, issueNumber, pr.body);
|
|
352
|
+
refuseClosingDirective(pr.title);
|
|
353
|
+
const issue = await openReferenceIssue(context, issueNumber);
|
|
354
|
+
const repository = (await context.clients.rest.repos.get({ ...context.repo })).data;
|
|
355
|
+
if (repository.full_name?.toLowerCase() !== context.config.repository.toLowerCase() || pr.base.ref !== repository.default_branch || typeof repository.node_id !== "string" || !repository.node_id)
|
|
356
|
+
throw new DeliveryError("Non-closing PR must target the canonical default repository/base.");
|
|
357
|
+
const route = await nonClosingRoute(context, pr.base.ref);
|
|
358
|
+
if (pr.user.login.toLowerCase() !== route.author.actorLogin.toLowerCase())
|
|
359
|
+
throw new DeliveryError("Non-closing PR author differs from the configured author.");
|
|
360
|
+
let cursor = null;
|
|
361
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
362
|
+
const events = /* @__PURE__ */ new Map();
|
|
363
|
+
let matched = false;
|
|
364
|
+
let closesTarget;
|
|
365
|
+
for (let page = 0; page < 20; page++) {
|
|
366
|
+
const data = await context.clients.graphql(
|
|
367
|
+
"query DeliveryNonClosingReferences($owner:String!,$repo:String!,$number:Int!,$cursor:String){repository(owner:$owner,name:$repo){id nameWithOwner issue(number:$number){id number state timelineItems(first:100,after:$cursor,itemTypes:[CROSS_REFERENCED_EVENT]){nodes{... on CrossReferencedEvent{id actor{login} isCrossRepository willCloseTarget source{__typename ... on Issue{id number repository{id nameWithOwner}} ... on PullRequest{id number repository{id nameWithOwner}}} target{__typename ... on Issue{id number repository{id nameWithOwner}} ... on PullRequest{id number repository{id nameWithOwner}}}}} pageInfo{hasNextPage endCursor}}}}}",
|
|
368
|
+
{ ...context.repo, number: issueNumber, cursor }
|
|
369
|
+
);
|
|
370
|
+
const target = data.repository?.issue;
|
|
371
|
+
const connection = target?.timelineItems;
|
|
372
|
+
if (data.repository?.id !== repository.node_id || data.repository.nameWithOwner?.toLowerCase() !== context.config.repository.toLowerCase() || target?.id !== issue.node_id || target.number !== issueNumber || target.state !== "OPEN" || !connection || !Array.isArray(connection.nodes) || connection.nodes.length > 100)
|
|
373
|
+
throw new DeliveryError("Incomplete or conflicting native non-closing issue identity.");
|
|
374
|
+
for (const event of connection.nodes) {
|
|
375
|
+
const source = event?.source;
|
|
376
|
+
const referenced = event?.target;
|
|
377
|
+
if (!event || !nativeId(event.id) || !source || !referenced || !["Issue", "PullRequest"].includes(source.__typename) || !nativeId(source.id) || !Number.isSafeInteger(source.number) || source.number <= 0 || !nativeId(source.repository?.id) || typeof source.repository.nameWithOwner !== "string" || referenced.__typename !== "Issue" || referenced.id !== issue.node_id || referenced.number !== issueNumber || referenced.repository?.id !== repository.node_id || referenced.repository.nameWithOwner?.toLowerCase() !== context.config.repository.toLowerCase() || typeof event.isCrossRepository !== "boolean" || typeof event.willCloseTarget !== "boolean" || !nativeId(event.actor?.login))
|
|
378
|
+
throw new DeliveryError("Incomplete native cross-reference event identity/actor.");
|
|
379
|
+
const signature = JSON.stringify([
|
|
380
|
+
source.__typename,
|
|
381
|
+
source.id,
|
|
382
|
+
source.number,
|
|
383
|
+
source.repository.id,
|
|
384
|
+
source.repository.nameWithOwner.toLowerCase(),
|
|
385
|
+
referenced.id,
|
|
386
|
+
referenced.number,
|
|
387
|
+
referenced.repository.id,
|
|
388
|
+
referenced.repository.nameWithOwner.toLowerCase(),
|
|
389
|
+
event.actor.login.toLowerCase(),
|
|
390
|
+
event.isCrossRepository,
|
|
391
|
+
event.willCloseTarget
|
|
392
|
+
]);
|
|
393
|
+
if (events.has(event.id) && events.get(event.id) !== signature)
|
|
394
|
+
throw new DeliveryError("Conflicting duplicate native reference event.");
|
|
395
|
+
events.set(event.id, signature);
|
|
396
|
+
if (source.id === pr.node_id || source.__typename === "PullRequest" && source.number === pr.number && source.repository.nameWithOwner.toLowerCase() === context.config.repository.toLowerCase()) {
|
|
397
|
+
if (source.__typename !== "PullRequest" || source.id !== pr.node_id || source.number !== pr.number || source.repository.id !== repository.node_id || source.repository.nameWithOwner.toLowerCase() !== context.config.repository.toLowerCase() || event.isCrossRepository || event.actor.login.toLowerCase() !== route.author.actorLogin.toLowerCase())
|
|
398
|
+
throw new DeliveryError("Conflicting, closing or unauthorized native PR reference.");
|
|
399
|
+
if (closesTarget !== void 0 && closesTarget !== event.willCloseTarget)
|
|
400
|
+
throw new DeliveryError("Conflicting native PR closing-reference semantics.");
|
|
401
|
+
closesTarget = event.willCloseTarget;
|
|
402
|
+
matched = true;
|
|
403
|
+
}
|
|
301
404
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
405
|
+
cursor = pageCursor(connection, cursors);
|
|
406
|
+
if (cursor === null) break;
|
|
407
|
+
if (page === 19) throw new DeliveryError("Native non-closing references exceed the bounded readback window.");
|
|
408
|
+
}
|
|
409
|
+
if (!matched) throw new DeliveryError("Missing authorized native non-closing PR-to-issue reference.");
|
|
410
|
+
const allClosing = await readClosingReferenceIds(context, issueNumber, issue.node_id, repository.node_id, pr);
|
|
411
|
+
const manualClosing = await readClosingReferenceIds(
|
|
412
|
+
context,
|
|
413
|
+
issueNumber,
|
|
414
|
+
issue.node_id,
|
|
415
|
+
repository.node_id,
|
|
416
|
+
pr,
|
|
417
|
+
true
|
|
418
|
+
);
|
|
419
|
+
await verifyNonClosingCommits(context, pr);
|
|
420
|
+
if (!pr.merged) {
|
|
421
|
+
const ref = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${pr.base.ref}` })).data;
|
|
422
|
+
if (ref.ref !== `refs/heads/${pr.base.ref}` || ref.object.type !== "commit" || !validSha(ref.object.sha) || !forReview && ref.object.sha !== pr.base.sha)
|
|
423
|
+
throw new DeliveryError("Non-closing default base has moved or is incomplete.");
|
|
424
|
+
}
|
|
425
|
+
const after = await openReferenceIssue(context, issueNumber);
|
|
426
|
+
sameReferenceIssue(issue, after);
|
|
427
|
+
sameReferencePr(pr, await getPr(context, pr.number));
|
|
428
|
+
return { issue, closesTarget, allClosing, manualClosing };
|
|
429
|
+
}
|
|
430
|
+
async function readClosingReferenceIds(context, issueNumber, issueId, repositoryId, pr, manual = false) {
|
|
431
|
+
let cursor = null;
|
|
432
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
433
|
+
const ids = /* @__PURE__ */ new Set();
|
|
434
|
+
for (let page = 0; page < 20; page++) {
|
|
435
|
+
const result = await context.clients.graphql(
|
|
436
|
+
`query DeliveryClosingIssues($owner:String!,$repo:String!,$number:Int!,$cursor:String){repository(owner:$owner,name:$repo){nameWithOwner pullRequest(number:$number){id number closingIssuesReferences(first:100,after:$cursor${manual ? ",userLinkedOnly:true" : ""}){nodes{__typename id number repository{id nameWithOwner}} pageInfo{hasNextPage endCursor}}}}}`,
|
|
437
|
+
{ ...context.repo, number: pr.number, cursor }
|
|
438
|
+
);
|
|
439
|
+
const connection = result.repository?.pullRequest?.closingIssuesReferences;
|
|
440
|
+
if (result.repository?.nameWithOwner?.toLowerCase() !== context.config.repository.toLowerCase() || result.repository.pullRequest?.id !== pr.node_id || result.repository.pullRequest.number !== pr.number || !connection || !Array.isArray(connection.nodes) || connection.nodes.length > 100)
|
|
441
|
+
throw new DeliveryError("Incomplete or conflicting native closing-reference graph.");
|
|
442
|
+
for (const issue of connection.nodes) {
|
|
443
|
+
if (!issue || issue.__typename !== "Issue" || issue.id !== issueId || issue.number !== issueNumber || issue.repository?.id !== repositoryId || issue.repository.nameWithOwner?.toLowerCase() !== context.config.repository.toLowerCase() || ids.has(issue.id))
|
|
444
|
+
throw new DeliveryError(
|
|
445
|
+
"Non-closing PR has an unintended, duplicate or incomplete native closing association."
|
|
446
|
+
);
|
|
447
|
+
ids.add(issue.id);
|
|
310
448
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
449
|
+
cursor = pageCursor(connection, cursors);
|
|
450
|
+
if (cursor === null) return [...ids];
|
|
451
|
+
}
|
|
452
|
+
throw new DeliveryError("Native closing-reference graph exceeds the bounded readback window.");
|
|
453
|
+
}
|
|
454
|
+
async function verifyNonClosingReference(context, issueNumber, pr, forReview = false) {
|
|
455
|
+
const graph = await readNonClosingReference(context, issueNumber, pr, forReview);
|
|
456
|
+
if (graph.closesTarget || graph.allClosing.length || graph.manualClosing.length)
|
|
457
|
+
throw new DeliveryError("Non-closing PR has a closing native PR reference/association.");
|
|
458
|
+
return graph.issue;
|
|
315
459
|
}
|
|
316
460
|
function nativeId(value) {
|
|
317
|
-
|
|
461
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
318
462
|
}
|
|
319
463
|
function validSha(value) {
|
|
320
|
-
|
|
464
|
+
return typeof value === "string" && Sha.test(value);
|
|
321
465
|
}
|
|
322
466
|
function validBranch(value) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
value.startsWith('/') ||
|
|
326
|
-
value.endsWith('/') ||
|
|
327
|
-
value.endsWith('.lock'))
|
|
328
|
-
throw new DeliveryError('Invalid GitHub branch name.');
|
|
467
|
+
if (typeof value !== "string" || !Branch.test(value) || value.startsWith("/") || value.endsWith("/") || value.endsWith(".lock"))
|
|
468
|
+
throw new DeliveryError("Invalid GitHub branch name.");
|
|
329
469
|
}
|
|
330
470
|
async function getPr(context, prNumber) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
!validSha(pr.head.sha) ||
|
|
340
|
-
!validSha(pr.base.sha) ||
|
|
341
|
-
(pr.state !== 'open' && pr.state !== 'closed') ||
|
|
342
|
-
typeof pr.merged !== 'boolean' ||
|
|
343
|
-
typeof pr.draft !== 'boolean' ||
|
|
344
|
-
(pr.merged && pr.state !== 'closed'))
|
|
345
|
-
throw new DeliveryError('GitHub PR identity or exact head readback is invalid.');
|
|
346
|
-
validBranch(pr.head.ref);
|
|
347
|
-
validBranch(pr.base.ref);
|
|
348
|
-
return pr;
|
|
471
|
+
if (context.config.repository.toLowerCase() !== `${context.repo.owner}/${context.repo.repo}`.toLowerCase())
|
|
472
|
+
throw new DeliveryError("Configured and selected GitHub repository identities disagree.");
|
|
473
|
+
const pr = (await context.clients.rest.pulls.get({ ...context.repo, pull_number: prNumber })).data;
|
|
474
|
+
if (pr.number !== prNumber || typeof pr.base.repo?.full_name !== "string" || typeof pr.head.repo?.full_name !== "string" || pr.base.repo?.full_name.toLowerCase() !== context.config.repository.toLowerCase() || pr.head.repo?.full_name.toLowerCase() !== context.config.repository.toLowerCase() || !validSha(pr.head.sha) || !validSha(pr.base.sha) || pr.state !== "open" && pr.state !== "closed" || typeof pr.merged !== "boolean" || typeof pr.draft !== "boolean" || pr.merged && pr.state !== "closed")
|
|
475
|
+
throw new DeliveryError("GitHub PR identity or exact head readback is invalid.");
|
|
476
|
+
validBranch(pr.head.ref);
|
|
477
|
+
validBranch(pr.base.ref);
|
|
478
|
+
return pr;
|
|
349
479
|
}
|
|
350
|
-
async function verifyPrIssueAssociation(context, prNumber, issueNumber,
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
!nativeId(expectedRepositoryId) ||
|
|
374
|
-
issue.repository?.id !== expectedRepositoryId))
|
|
375
|
-
throw new DeliveryError('Incomplete or conflicting typed closing issue/repository identity before body transition.');
|
|
376
|
-
if (nonClosing)
|
|
377
|
-
throw new DeliveryError('Non-closing PR has an unintended native closing association.');
|
|
378
|
-
if (!issue ||
|
|
379
|
-
!Number.isSafeInteger(issue.number) ||
|
|
380
|
-
issue.number <= 0 ||
|
|
381
|
-
typeof issue.repository?.nameWithOwner !== 'string' ||
|
|
382
|
-
!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(issue.repository.nameWithOwner))
|
|
383
|
-
throw new DeliveryError('Incomplete native PR closing-issue identity.');
|
|
384
|
-
if (issue.number === issueNumber &&
|
|
385
|
-
issue.repository.nameWithOwner.toLowerCase() === context.config.repository.toLowerCase())
|
|
386
|
-
matches++;
|
|
387
|
-
else if (onlyIntended)
|
|
388
|
-
throw new DeliveryError('Existing PR has conflicting closing associations; body transition refused.');
|
|
389
|
-
}
|
|
390
|
-
if (!connection.pageInfo.hasNextPage) {
|
|
391
|
-
if (!nonClosing && matches !== 1)
|
|
392
|
-
throw new DeliveryError('Native GitHub PR closing-issue association does not identify the intended issue.');
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
const next = connection.pageInfo.endCursor;
|
|
396
|
-
if (!next || cursors.has(next))
|
|
397
|
-
throw new DeliveryError('Native PR issue pagination did not advance.');
|
|
398
|
-
cursors.add(next);
|
|
399
|
-
cursor = next;
|
|
480
|
+
async function verifyPrIssueAssociation(context, prNumber, issueNumber, expectedPrId, onlyIntended = false, expectedIssueId, expectedRepositoryId, options = {}) {
|
|
481
|
+
let cursor = null;
|
|
482
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
483
|
+
let matches = 0;
|
|
484
|
+
for (let page = 0; page < 20; page++) {
|
|
485
|
+
const result = await context.clients.graphql(
|
|
486
|
+
"query DeliveryClosingIssues($owner:String!,$repo:String!,$number:Int!,$cursor:String){repository(owner:$owner,name:$repo){nameWithOwner pullRequest(number:$number){id number closingIssuesReferences(first:100,after:$cursor){nodes{__typename id number repository{id nameWithOwner}} pageInfo{hasNextPage endCursor}}}}}",
|
|
487
|
+
{ ...context.repo, number: prNumber, cursor }
|
|
488
|
+
);
|
|
489
|
+
const connection = result.repository?.pullRequest?.closingIssuesReferences;
|
|
490
|
+
if (typeof result.repository?.nameWithOwner !== "string" || result.repository.nameWithOwner.toLowerCase() !== context.config.repository.toLowerCase() || result.repository?.pullRequest?.number !== prNumber || expectedPrId !== void 0 && result.repository?.pullRequest?.id !== expectedPrId || !connection || !Array.isArray(connection.nodes) || connection.nodes.length > 100 || typeof connection.pageInfo?.hasNextPage !== "boolean" || !(connection.pageInfo.endCursor === null || typeof connection.pageInfo.endCursor === "string"))
|
|
491
|
+
throw new DeliveryError("Incomplete or conflicting native GitHub PR issue association readback.");
|
|
492
|
+
for (const issue of connection.nodes) {
|
|
493
|
+
if (onlyIntended && (!issue || issue.__typename !== "Issue" || !nativeId(expectedIssueId) || issue.id !== expectedIssueId || !nativeId(expectedRepositoryId) || issue.repository?.id !== expectedRepositoryId))
|
|
494
|
+
throw new DeliveryError(
|
|
495
|
+
"Incomplete or conflicting typed closing issue/repository identity before body transition."
|
|
496
|
+
);
|
|
497
|
+
if (!issue || !Number.isSafeInteger(issue.number) || issue.number <= 0 || typeof issue.repository?.nameWithOwner !== "string" || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(issue.repository.nameWithOwner))
|
|
498
|
+
throw new DeliveryError("Incomplete native PR closing-issue identity.");
|
|
499
|
+
if (issue.number === issueNumber && issue.repository.nameWithOwner.toLowerCase() === context.config.repository.toLowerCase())
|
|
500
|
+
matches++;
|
|
501
|
+
else if (onlyIntended)
|
|
502
|
+
throw new DeliveryError("Existing PR has conflicting closing associations; body transition refused.");
|
|
400
503
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
...context.repo,
|
|
408
|
-
head: `${context.repo.owner}:${branch}`,
|
|
409
|
-
...(base === undefined ? {} : { base }),
|
|
410
|
-
state: 'all',
|
|
411
|
-
page,
|
|
412
|
-
per_page: 100,
|
|
413
|
-
})).data;
|
|
414
|
-
if (!Array.isArray(batch) || batch.some((pr) => !pr || !Number.isSafeInteger(pr.number) || pr.number <= 0))
|
|
415
|
-
throw new DeliveryError('Incomplete GitHub PR match readback.');
|
|
416
|
-
matches.push(...batch);
|
|
417
|
-
if (batch.length < 100)
|
|
418
|
-
return matches;
|
|
504
|
+
if (!connection.pageInfo.hasNextPage) {
|
|
505
|
+
if (matches !== 1 && !(matches === 0 && options.allowMissing))
|
|
506
|
+
throw new DeliveryError(
|
|
507
|
+
matches === 0 && options.missingMessage ? options.missingMessage : "Native GitHub PR closing-issue association does not identify the intended issue."
|
|
508
|
+
);
|
|
509
|
+
return matches;
|
|
419
510
|
}
|
|
420
|
-
|
|
511
|
+
const next = connection.pageInfo.endCursor;
|
|
512
|
+
if (!next || cursors.has(next)) throw new DeliveryError("Native PR issue pagination did not advance.");
|
|
513
|
+
cursors.add(next);
|
|
514
|
+
cursor = next;
|
|
515
|
+
}
|
|
516
|
+
throw new DeliveryError("Native PR issue association exceeds the bounded readback window.");
|
|
421
517
|
}
|
|
422
|
-
async function
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
|
|
518
|
+
async function matchingPrs(context, branch, base, state = "all") {
|
|
519
|
+
const matches = [];
|
|
520
|
+
for (let page = 1; page <= 20; page++) {
|
|
521
|
+
const batch = (await context.clients.rest.pulls.list({
|
|
522
|
+
...context.repo,
|
|
523
|
+
head: `${context.repo.owner}:${branch}`,
|
|
524
|
+
...base === void 0 ? {} : { base },
|
|
525
|
+
state,
|
|
526
|
+
page,
|
|
527
|
+
per_page: 100
|
|
528
|
+
})).data;
|
|
529
|
+
if (!Array.isArray(batch) || batch.some((pr) => !pr || !Number.isSafeInteger(pr.number) || pr.number <= 0))
|
|
530
|
+
throw new DeliveryError("Incomplete GitHub PR match readback.");
|
|
531
|
+
matches.push(...batch);
|
|
532
|
+
if (batch.length < 100) return matches;
|
|
533
|
+
}
|
|
534
|
+
throw new DeliveryError("GitHub PR match history exceeds the bounded readback window.");
|
|
434
535
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
url: pr.html_url,
|
|
458
|
-
state: pr.state,
|
|
459
|
-
draft: pr.draft,
|
|
460
|
-
headSha: pr.head.sha,
|
|
461
|
-
headBranch: pr.head.ref,
|
|
462
|
-
baseBranch: pr.base.ref,
|
|
463
|
-
merged: pr.merged,
|
|
464
|
-
};
|
|
536
|
+
async function verifyIssuePr(context, issueNumber, prNumber, nonClosing = false, forReview = false) {
|
|
537
|
+
const pr = await getPr(context, prNumber);
|
|
538
|
+
if (nonClosing) await verifyNonClosingReference(context, issueNumber, pr, forReview);
|
|
539
|
+
else
|
|
540
|
+
await verifyPrIssueAssociation(
|
|
541
|
+
context,
|
|
542
|
+
prNumber,
|
|
543
|
+
issueNumber,
|
|
544
|
+
void 0,
|
|
545
|
+
false,
|
|
546
|
+
void 0,
|
|
547
|
+
void 0,
|
|
548
|
+
forReview && !hasClosingLink(pr.body, issueNumber) ? {
|
|
549
|
+
missingMessage: `Missing \`Closes #${issueNumber}\` in PR #${prNumber}. Restore it with issue_pr_create(${JSON.stringify({ repo: context.config.repository, issueNumber, head: pr.head.ref })}).`
|
|
550
|
+
} : {}
|
|
551
|
+
);
|
|
552
|
+
if (!pr.merged) {
|
|
553
|
+
const ref = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${pr.head.ref}` })).data;
|
|
554
|
+
if (ref.ref !== `refs/heads/${pr.head.ref}` || ref.object.type !== "commit" || ref.object.sha !== pr.head.sha)
|
|
555
|
+
throw new DeliveryError("Current remote PR head/ref readback is incomplete or has moved.");
|
|
556
|
+
}
|
|
557
|
+
return pr;
|
|
465
558
|
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
559
|
+
async function prInfo(context, input) {
|
|
560
|
+
const nonClosing = nonClosingMode(input.nonClosing);
|
|
561
|
+
if (nonClosing && (input.issueNumber === void 0 || input.prNumber === void 0))
|
|
562
|
+
throw new DeliveryError("Non-closing inspection requires explicit canonical issue and PR numbers.");
|
|
563
|
+
let number = input.prNumber;
|
|
564
|
+
if (number === void 0) {
|
|
565
|
+
if (input.issueNumber === void 0) throw new DeliveryError("prNumber or issueNumber is required.");
|
|
566
|
+
const branches = await linkedIssueBranches(context, input.issueNumber);
|
|
567
|
+
if (branches.length !== 1)
|
|
568
|
+
throw new DeliveryError(
|
|
569
|
+
"Issue-only PR inspection requires one GitHub-linked issue branch. After publication, supply the exact issue and PR numbers (CLI --issue and --pr) to verify the native PR closing-issue association."
|
|
570
|
+
);
|
|
571
|
+
const branch = branches[0].name;
|
|
572
|
+
const matches = await matchingPrs(context, branch);
|
|
573
|
+
if (matches.length !== 1)
|
|
574
|
+
throw new DeliveryError("Select an explicit PR number when the remote issue branch has zero or multiple PRs.");
|
|
575
|
+
number = matches[0].number;
|
|
576
|
+
}
|
|
577
|
+
const pr = input.issueNumber === void 0 ? await getPr(context, number) : await verifyIssuePr(context, input.issueNumber, number, nonClosing);
|
|
578
|
+
return {
|
|
579
|
+
prNumber: pr.number,
|
|
580
|
+
url: pr.html_url,
|
|
581
|
+
state: pr.state,
|
|
582
|
+
draft: pr.draft,
|
|
583
|
+
headSha: pr.head.sha,
|
|
584
|
+
headBranch: pr.head.ref,
|
|
585
|
+
baseBranch: pr.base.ref,
|
|
586
|
+
merged: pr.merged
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
async function listPrs(context, state = "open") {
|
|
590
|
+
const prs = await context.clients.rest.paginate(context.clients.rest.pulls.list, {
|
|
591
|
+
...context.repo,
|
|
592
|
+
state,
|
|
593
|
+
per_page: 100
|
|
594
|
+
});
|
|
595
|
+
return {
|
|
596
|
+
schemaVersion: "ai-delivery.pr-list@1",
|
|
597
|
+
pullRequests: prs.map((pr) => ({
|
|
598
|
+
number: pr.number,
|
|
599
|
+
state: pr.state,
|
|
600
|
+
draft: pr.draft ?? false,
|
|
601
|
+
headSha: pr.head.sha,
|
|
602
|
+
baseSha: pr.base.sha,
|
|
603
|
+
url: pr.html_url
|
|
604
|
+
}))
|
|
605
|
+
};
|
|
483
606
|
}
|
|
484
|
-
/** Enumerate configured requirements even when a check has never reported. */
|
|
485
607
|
async function readRequiredCheckNames(context, base) {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
608
|
+
const sources = await branchRuleSources(context, base);
|
|
609
|
+
const { confirmedUnprotected, confirmedRulesetOnly } = await corroborateClassicProtectionAbsence(
|
|
610
|
+
context,
|
|
611
|
+
base,
|
|
612
|
+
sources
|
|
613
|
+
);
|
|
614
|
+
const names = /* @__PURE__ */ new Set();
|
|
615
|
+
const required = /* @__PURE__ */ new Map();
|
|
616
|
+
let complete = true;
|
|
617
|
+
for (const [index, result] of sources.entries()) {
|
|
618
|
+
if (index === 1 && (confirmedUnprotected || confirmedRulesetOnly)) continue;
|
|
619
|
+
if (result.status !== "fulfilled" || result.value.status !== 200 || !result.value.headers || result.value.headers.link) {
|
|
620
|
+
complete = false;
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
const data = result.value.data;
|
|
624
|
+
const lists = [];
|
|
625
|
+
if (index === 0) {
|
|
626
|
+
if (!Array.isArray(data)) {
|
|
627
|
+
complete = false;
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
for (const rule of data) {
|
|
631
|
+
if (typeof rule?.type !== "string") complete = false;
|
|
632
|
+
if (rule?.type === "required_status_checks") lists.push(rule.parameters?.required_status_checks);
|
|
633
|
+
}
|
|
634
|
+
} else if (Array.isArray(data) || !data || typeof data !== "object") complete = false;
|
|
635
|
+
else if (data.required_status_checks === null) lists.push([]);
|
|
636
|
+
else {
|
|
637
|
+
const checks = data?.required_status_checks;
|
|
638
|
+
if (Array.isArray(checks?.checks)) lists.push(checks.checks);
|
|
639
|
+
if (Array.isArray(checks?.contexts))
|
|
640
|
+
lists.push(
|
|
641
|
+
checks.contexts.filter(
|
|
642
|
+
(context2) => !Array.isArray(checks?.checks) || !checks.checks.some((check) => check?.context === context2)
|
|
643
|
+
).map((context2) => ({ context: context2 }))
|
|
644
|
+
);
|
|
645
|
+
if (!Array.isArray(checks?.checks) && !Array.isArray(checks?.contexts)) complete = false;
|
|
646
|
+
}
|
|
647
|
+
for (const list of lists) {
|
|
648
|
+
const parsed = z.array(
|
|
649
|
+
z.object({
|
|
650
|
+
context: z.string().min(1),
|
|
651
|
+
app_id: z.number().int().nullable().optional(),
|
|
652
|
+
integration_id: z.number().int().nullable().optional()
|
|
653
|
+
})
|
|
654
|
+
).safeParse(list);
|
|
655
|
+
if (!parsed.success) complete = false;
|
|
656
|
+
else
|
|
657
|
+
for (const check of parsed.data) {
|
|
658
|
+
names.add(check.context);
|
|
659
|
+
const selected = index === 0 ? check.integration_id : check.app_id;
|
|
660
|
+
if (selected !== void 0 && selected !== null && selected !== -1 && selected <= 0) complete = false;
|
|
661
|
+
const appId = selected === void 0 || selected === null || selected === -1 ? null : selected;
|
|
662
|
+
required.set(JSON.stringify([check.context, appId]), { name: check.context, appId });
|
|
531
663
|
}
|
|
532
664
|
}
|
|
533
|
-
|
|
665
|
+
}
|
|
666
|
+
return { names: [...names].sort(), complete, required: [...required.values()] };
|
|
534
667
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
668
|
+
async function queueChecks(context, base, sha) {
|
|
669
|
+
return readRequiredCheckProof(context, base, sha, false);
|
|
670
|
+
}
|
|
671
|
+
async function readRequiredCheckProof(context, base, sha, allowEmpty) {
|
|
672
|
+
const requirements = await readRequiredCheckNames(context, base);
|
|
673
|
+
if (!requirements.complete || !allowEmpty && requirements.required.length === 0)
|
|
674
|
+
return { state: "waiting", reason: "Required queue checks are absent or incompletely discovered." };
|
|
675
|
+
if (requirements.required.length === 0)
|
|
676
|
+
return { state: "passed", reason: "Native requirements are completely observed and empty.", proof: [] };
|
|
677
|
+
const [runs, statuses] = await Promise.all([
|
|
678
|
+
context.clients.rest.checks.listForRef({ ...context.repo, ref: sha, filter: "latest", per_page: 100 }),
|
|
679
|
+
context.clients.rest.repos.getCombinedStatusForRef({ ...context.repo, ref: sha, per_page: 100 })
|
|
680
|
+
]);
|
|
681
|
+
if (runs.status !== 200 || statuses.status !== 200 || !runs.headers || !statuses.headers || runs.headers?.link || statuses.headers?.link || runs.data.total_count !== runs.data.check_runs.length || statuses.data.total_count !== statuses.data.statuses.length || statuses.data.sha !== sha || runs.data.check_runs.some((run) => run.head_sha !== sha))
|
|
682
|
+
return { state: "waiting", reason: "Queue SHA check/status pagination or identity is incomplete." };
|
|
683
|
+
const proof = [];
|
|
684
|
+
for (const required of requirements.required) {
|
|
685
|
+
const status = statuses.data.statuses.filter((s) => s.context === required.name).sort((a, b) => b.id - a.id)[0];
|
|
686
|
+
let waiting;
|
|
687
|
+
if (status) {
|
|
688
|
+
if (required.appId !== null) waiting = `Queue status ${required.name} required App source cannot be established.`;
|
|
689
|
+
else if (!Number.isSafeInteger(status.id) || status.id <= 0)
|
|
690
|
+
waiting = `Queue status ${required.name} attempt is unknown.`;
|
|
691
|
+
else if (status.state === "failure" || status.state === "error")
|
|
692
|
+
return { state: "failed", reason: `Queue status ${required.name} is ${status.state}.` };
|
|
693
|
+
else if (status.state !== "success")
|
|
694
|
+
waiting = `Queue status ${required.name} is ${status.state === "pending" ? "pending" : "unknown"}.`;
|
|
695
|
+
else proof.push({ ...required, id: status.id });
|
|
696
|
+
}
|
|
697
|
+
const candidates = runs.data.check_runs.filter((run2) => run2.name === required.name && (required.appId === null || run2.app?.id === required.appId)).sort((a, b) => b.id - a.id);
|
|
698
|
+
const run = candidates[0];
|
|
699
|
+
if (run) {
|
|
700
|
+
if (!Number.isSafeInteger(run.id) || run.id <= 0 || !run.app?.id)
|
|
701
|
+
return { state: "waiting", reason: `Queue check ${required.name} producer/attempt is unknown.` };
|
|
702
|
+
if (run.status !== "completed")
|
|
703
|
+
return { state: "waiting", reason: `Queue check ${required.name} is pending.` };
|
|
704
|
+
if (run.conclusion !== "success" && !["failure", "cancelled", "timed_out", "action_required", "startup_failure", "stale"].includes(
|
|
705
|
+
run.conclusion ?? ""
|
|
706
|
+
))
|
|
707
|
+
return {
|
|
708
|
+
state: "waiting",
|
|
709
|
+
reason: `Queue check ${required.name} conclusion is unknown or not successful.`
|
|
710
|
+
};
|
|
711
|
+
if (run.conclusion !== "success")
|
|
712
|
+
return {
|
|
713
|
+
state: "failed",
|
|
714
|
+
reason: `Queue check ${required.name} concluded ${run.conclusion ?? "unknown"}.`
|
|
715
|
+
};
|
|
716
|
+
proof.push({ ...required, id: run.id });
|
|
717
|
+
} else if (!status) waiting = `Queue check ${required.name} has not reported from its required source.`;
|
|
718
|
+
if (waiting) return { state: "waiting", reason: waiting };
|
|
719
|
+
}
|
|
720
|
+
return { state: "passed", reason: "Current required queue SHA checks passed.", proof };
|
|
721
|
+
}
|
|
722
|
+
async function readPrBoardFacts(context, prNumber) {
|
|
723
|
+
const repository = `${context.repo.owner}/${context.repo.repo}`;
|
|
724
|
+
const pr = (await context.clients.rest.pulls.get({ ...context.repo, pull_number: prNumber })).data;
|
|
725
|
+
const baseRepo = pr.base.repo;
|
|
726
|
+
const headRepo = pr.head.repo;
|
|
727
|
+
if (pr.number !== prNumber || !nativeId(pr.node_id) || pr.html_url?.toLowerCase() !== `https://github.com/${repository}/pull/${prNumber}`.toLowerCase() || typeof pr.title !== "string" || pr.body !== null && typeof pr.body !== "string" || pr.state !== "open" && pr.state !== "closed" || typeof pr.draft !== "boolean" || typeof pr.merged !== "boolean" || !baseRepo || !headRepo || !nativeId(baseRepo.node_id) || !nativeId(headRepo.node_id) || typeof baseRepo.full_name !== "string" || typeof headRepo.full_name !== "string" || baseRepo.full_name.toLowerCase() !== repository.toLowerCase() || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(headRepo.full_name) || typeof pr.head.ref !== "string" || !pr.head.ref || typeof pr.base.ref !== "string" || !pr.base.ref || !validSha(pr.head.sha) || !validSha(pr.base.sha))
|
|
728
|
+
throw new DeliveryError("Incomplete native PR identity for board display.");
|
|
729
|
+
const baseRepository = { id: baseRepo.node_id, name: baseRepo.full_name };
|
|
730
|
+
const headRepository = { id: headRepo.node_id, name: headRepo.full_name };
|
|
731
|
+
const closingLinks = { complete: false, issues: [] };
|
|
732
|
+
let native = null;
|
|
733
|
+
try {
|
|
734
|
+
let cursor = null;
|
|
735
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
736
|
+
const issues = /* @__PURE__ */ new Set();
|
|
737
|
+
const issueNumbers = /* @__PURE__ */ new Set();
|
|
738
|
+
for (let page = 0; page < 20; page++) {
|
|
739
|
+
const data = await context.clients.graphql(
|
|
740
|
+
"query DeliveryBoardPr($owner:String!,$repo:String!,$number:Int!,$cursor:String){repository(owner:$owner,name:$repo){id nameWithOwner pullRequest(number:$number){id number state isDraft headRefOid baseRefOid headRefName baseRefName baseRepository{id nameWithOwner} headRepository{id nameWithOwner} mergeable mergeStateStatus closingIssuesReferences(first:100,after:$cursor){nodes{__typename id number repository{id nameWithOwner}} pageInfo{hasNextPage endCursor}}}}}",
|
|
741
|
+
{ ...context.repo, number: prNumber, cursor }
|
|
742
|
+
);
|
|
743
|
+
const live = data.repository?.pullRequest;
|
|
744
|
+
const links = live?.closingIssuesReferences;
|
|
745
|
+
if (data.repository?.id !== baseRepository.id || data.repository.nameWithOwner?.toLowerCase() !== repository.toLowerCase() || live?.id !== pr.node_id || live.number !== prNumber || live.headRefOid !== pr.head.sha || live.baseRefOid !== pr.base.sha || live.headRefName !== pr.head.ref || live.baseRefName !== pr.base.ref || live.baseRepository?.id !== baseRepository.id || live.baseRepository.nameWithOwner?.toLowerCase() !== baseRepository.name.toLowerCase() || live.headRepository?.id !== headRepository.id || live.headRepository.nameWithOwner?.toLowerCase() !== headRepository.name.toLowerCase() || live.state !== (pr.merged ? "MERGED" : pr.state.toUpperCase()) || live.isDraft !== pr.draft || !["MERGEABLE", "CONFLICTING", "UNKNOWN"].includes(live.mergeable) || typeof live.mergeStateStatus !== "string" || native !== null && (native.mergeable !== live.mergeable || native.mergeStateStatus !== live.mergeStateStatus) || !links || !Array.isArray(links.nodes) || links.nodes.length > 100)
|
|
746
|
+
throw new DeliveryError("Native PR board snapshot is incomplete or changed.");
|
|
747
|
+
native = live;
|
|
748
|
+
for (const issue of links.nodes) {
|
|
749
|
+
if (issue?.__typename !== "Issue" || !nativeId(issue.id) || !Number.isSafeInteger(issue.number) || issue.number <= 0 || !nativeId(issue.repository?.id) || typeof issue.repository.nameWithOwner !== "string" || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(issue.repository.nameWithOwner) || issues.has(issue.id) || issueNumbers.has(`${issue.repository.nameWithOwner.toLowerCase()}#${issue.number}`) || issue.repository.nameWithOwner.toLowerCase() === repository.toLowerCase() && issue.repository.id !== baseRepository.id)
|
|
750
|
+
throw new DeliveryError("Native closing-issue board identity is incomplete.");
|
|
751
|
+
issues.add(issue.id);
|
|
752
|
+
issueNumbers.add(`${issue.repository.nameWithOwner.toLowerCase()}#${issue.number}`);
|
|
753
|
+
closingLinks.issues.push({
|
|
754
|
+
id: issue.id,
|
|
755
|
+
number: issue.number,
|
|
756
|
+
repository: { id: issue.repository.id, name: issue.repository.nameWithOwner }
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
cursor = pageCursor(links, cursors);
|
|
760
|
+
if (cursor === null) {
|
|
761
|
+
closingLinks.complete = true;
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
} catch {
|
|
766
|
+
native = null;
|
|
767
|
+
}
|
|
768
|
+
const [decision, proof] = await Promise.allSettled([
|
|
769
|
+
readRequiredReviewState(context, prNumber, pr.head.sha),
|
|
770
|
+
readRequiredCheckProof(context, pr.base.ref, pr.head.sha, true)
|
|
771
|
+
]);
|
|
772
|
+
const review = decision.status === "fulfilled" ? { ...decision.value, observed: decision.value.observed === true } : {
|
|
773
|
+
observed: false,
|
|
774
|
+
reviewDecision: null,
|
|
775
|
+
status: "unknown",
|
|
776
|
+
submittedReviewAuthorCanPushToRepository: null,
|
|
777
|
+
nextAction: "Refresh exact-head native review evidence."
|
|
778
|
+
};
|
|
779
|
+
const checks = {
|
|
780
|
+
...proof.status === "fulfilled" ? proof.value : { state: "waiting", reason: "Native required-check evidence is unavailable." },
|
|
781
|
+
complete: proof.status === "fulfilled" && proof.value.state === "passed"
|
|
782
|
+
};
|
|
783
|
+
const [current, reread] = await Promise.allSettled([
|
|
784
|
+
context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${pr.base.ref}` }),
|
|
785
|
+
context.clients.rest.pulls.get({ ...context.repo, pull_number: prNumber })
|
|
786
|
+
]);
|
|
787
|
+
const ref = current.status === "fulfilled" ? current.value.data : null;
|
|
788
|
+
const currentBaseSha = ref?.ref === `refs/heads/${pr.base.ref}` && ref.object.type === "commit" && validSha(ref.object.sha) ? ref.object.sha : null;
|
|
789
|
+
const final = reread.status === "fulfilled" ? reread.value.data : null;
|
|
790
|
+
const stable = final !== null && final.node_id === pr.node_id && final.number === pr.number && final.head.sha === pr.head.sha && final.base.sha === pr.base.sha && final.head.ref === pr.head.ref && final.base.ref === pr.base.ref && final.head.repo?.node_id === headRepository.id && final.head.repo.full_name?.toLowerCase() === headRepository.name.toLowerCase() && final.base.repo?.node_id === baseRepository.id && final.base.repo.full_name?.toLowerCase() === baseRepository.name.toLowerCase() && final.state === pr.state && final.merged === pr.merged && final.draft === pr.draft && final.body === pr.body && final.title === pr.title && final.mergeable === pr.mergeable && final.mergeable_state === pr.mergeable_state;
|
|
791
|
+
const reference = /^References ([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)#[1-9]\d*(?:\r?\n|$)/u.exec(pr.body ?? "");
|
|
792
|
+
const nonClosing = reference?.[1]?.toLowerCase() === repository.toLowerCase();
|
|
793
|
+
const reasons = [];
|
|
794
|
+
if (pr.state !== "open" || pr.merged) reasons.push("pr-closed");
|
|
795
|
+
if (pr.draft) reasons.push("draft");
|
|
796
|
+
if (nonClosing) reasons.push("non-closing");
|
|
797
|
+
if (!native) reasons.push("native-eligibility-unknown");
|
|
798
|
+
else if (native.mergeable !== "MERGEABLE" || native.mergeStateStatus !== "CLEAN" || pr.mergeable !== true || pr.mergeable_state !== "clean")
|
|
799
|
+
reasons.push("native-not-clean");
|
|
800
|
+
if (!review.observed) reasons.push("review-unknown");
|
|
801
|
+
else if (review.reviewDecision !== "APPROVED" && review.reviewDecision !== null)
|
|
802
|
+
reasons.push(review.reviewDecision === "CHANGES_REQUESTED" ? "changes-requested" : "review-required");
|
|
803
|
+
if (checks.state !== "passed") reasons.push(checks.state === "failed" ? "checks-failed" : "checks-unproven");
|
|
804
|
+
if (!closingLinks.complete) reasons.push("closing-links-unknown");
|
|
805
|
+
else if (!closingLinks.issues.some(
|
|
806
|
+
(issue) => issue.repository.id === baseRepository.id && issue.repository.name.toLowerCase() === repository.toLowerCase()
|
|
807
|
+
))
|
|
808
|
+
reasons.push("no-closing-issue");
|
|
809
|
+
if (!stable) reasons.push("pr-drift-or-unavailable");
|
|
810
|
+
if (currentBaseSha !== pr.base.sha) reasons.push("base-moved-or-unavailable");
|
|
811
|
+
return {
|
|
812
|
+
repository: baseRepository,
|
|
813
|
+
headRepository,
|
|
814
|
+
number: pr.number,
|
|
815
|
+
url: pr.html_url,
|
|
816
|
+
title: pr.title,
|
|
817
|
+
state: pr.state,
|
|
818
|
+
draft: pr.draft,
|
|
819
|
+
nonClosing,
|
|
820
|
+
headSha: pr.head.sha,
|
|
821
|
+
baseSha: pr.base.sha,
|
|
822
|
+
headRef: pr.head.ref,
|
|
823
|
+
baseRef: pr.base.ref,
|
|
824
|
+
currentBaseSha,
|
|
825
|
+
mergeable: native?.mergeable ?? null,
|
|
826
|
+
mergeStateStatus: native?.mergeStateStatus ?? null,
|
|
827
|
+
review,
|
|
828
|
+
checks,
|
|
829
|
+
closingLinks,
|
|
830
|
+
stable,
|
|
831
|
+
ready: reasons.length === 0,
|
|
832
|
+
reasons
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
async function prChecks(context, prNumber) {
|
|
836
|
+
const pr = await getPr(context, prNumber);
|
|
837
|
+
const requirements = await readRequiredCheckNames(context, pr.base.ref);
|
|
838
|
+
const [checks, status, reviewState] = await Promise.all([
|
|
839
|
+
context.clients.rest.checks.listForRef({ ...context.repo, ref: pr.head.sha, per_page: 100 }),
|
|
840
|
+
context.clients.rest.repos.getCombinedStatusForRef({ ...context.repo, ref: pr.head.sha, per_page: 100 }),
|
|
841
|
+
readRequiredReviewState(context, prNumber, pr.head.sha)
|
|
842
|
+
]);
|
|
843
|
+
const headChecksComplete = checks.data.total_count === checks.data.check_runs.length && status.data.total_count === status.data.statuses.length;
|
|
844
|
+
return {
|
|
845
|
+
schemaVersion: "ai-delivery.pr-checks@1",
|
|
846
|
+
prNumber: pr.number,
|
|
847
|
+
headSha: pr.head.sha,
|
|
848
|
+
combinedStatus: status.data.state,
|
|
849
|
+
mergeStateStatus: pr.mergeable_state ?? "unknown",
|
|
850
|
+
requiredCheckDiscovery: requirements.complete ? "complete" : "partial",
|
|
851
|
+
headChecksComplete,
|
|
852
|
+
requiredChecks: requirements.names.map((name) => {
|
|
853
|
+
const states = [
|
|
854
|
+
...checks.data.check_runs.filter((check) => check.name === name).map((check) => `check: ${check.status}/${check.conclusion ?? "pending"}`),
|
|
855
|
+
...status.data.statuses.filter((check) => check.context === name).map((check) => `status: ${check.state}`)
|
|
856
|
+
];
|
|
857
|
+
return { name, headState: states.join("; ") || (headChecksComplete ? "not-reported" : "unknown") };
|
|
858
|
+
}),
|
|
859
|
+
reviewState,
|
|
860
|
+
checkRuns: checks.data.check_runs.map((check) => ({
|
|
861
|
+
name: check.name,
|
|
862
|
+
status: check.status,
|
|
863
|
+
conclusion: check.conclusion
|
|
864
|
+
}))
|
|
865
|
+
};
|
|
569
866
|
}
|
|
570
867
|
function requiredApprovalCount(value) {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
return typeof count === 'number' && Number.isSafeInteger(count) && count >= 0 ? count : null;
|
|
868
|
+
if (typeof value !== "object" || value === null) return null;
|
|
869
|
+
const count = value.required_approving_review_count;
|
|
870
|
+
return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 ? count : null;
|
|
575
871
|
}
|
|
576
872
|
function completeRulePage(response) {
|
|
577
|
-
|
|
578
|
-
Array.isArray(response.data) &&
|
|
579
|
-
response.headers !== undefined &&
|
|
580
|
-
response.headers !== null &&
|
|
581
|
-
(response.headers.link === undefined || response.headers.link === ''));
|
|
873
|
+
return response.status === 200 && Array.isArray(response.data) && response.headers !== void 0 && response.headers !== null && (response.headers.link === void 0 || response.headers.link === "");
|
|
582
874
|
}
|
|
583
|
-
/** Absence is proved only by an empty successful first page with no continuation evidence. */
|
|
584
875
|
function emptyRulePage(response) {
|
|
585
|
-
|
|
876
|
+
return completeRulePage(response) && Array.isArray(response.data) && response.data.length === 0;
|
|
586
877
|
}
|
|
587
878
|
function branchRuleSources(context, base, control) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
879
|
+
return Promise.allSettled([
|
|
880
|
+
context.clients.rest.request("GET /repos/{owner}/{repo}/rules/branches/{branch}", {
|
|
881
|
+
...context.repo,
|
|
882
|
+
branch: base,
|
|
883
|
+
...control === void 0 ? {} : { request: { signal: control.signal } }
|
|
884
|
+
}),
|
|
885
|
+
context.clients.rest.request("GET /repos/{owner}/{repo}/branches/{branch}/protection", {
|
|
886
|
+
...context.repo,
|
|
887
|
+
branch: base,
|
|
888
|
+
...control === void 0 ? {} : { request: { signal: control.signal } }
|
|
889
|
+
})
|
|
890
|
+
]);
|
|
600
891
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
if (
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
throw new DeliveryError('Author GitHub identity readback is incomplete.');
|
|
630
|
-
}
|
|
631
|
-
const reviewer = selectedReviewer ??
|
|
632
|
-
context.reviewerClients ??
|
|
633
|
-
(await githubClients.createDeliveryGitHubClients({
|
|
634
|
-
config: context.config,
|
|
635
|
-
identity: context.config.roles.reviewer.identity,
|
|
636
|
-
role: 'reviewer',
|
|
637
|
-
selectedAuthor: context.clients,
|
|
638
|
-
...(control === undefined ? {} : { signal: control.signal }),
|
|
639
|
-
}));
|
|
640
|
-
await check();
|
|
641
|
-
if (reviewer.role !== 'reviewer' || reviewer.authSource !== 'app' || !reviewer.appActorLogin) {
|
|
642
|
-
throw new DeliveryError('Configured reviewer GitHub App identity is unavailable.');
|
|
643
|
-
}
|
|
644
|
-
const reviewerActor = await reviewer.appActorLogin(control?.signal);
|
|
645
|
-
await check();
|
|
646
|
-
if (!reviewerActor)
|
|
647
|
-
throw new DeliveryError('Reviewer GitHub App actor lookup is incomplete.');
|
|
648
|
-
if (author.actorLogin.toLowerCase() === reviewerActor.toLowerCase()) {
|
|
649
|
-
throw new DeliveryError('Author and reviewer resolve to the same GitHub actor; select distinct configured credentials.');
|
|
892
|
+
async function corroborateClassicProtectionAbsence(context, base, [rulesetResult, protectionResult], control) {
|
|
893
|
+
let confirmedUnprotected = false;
|
|
894
|
+
let confirmedRulesetOnly = false;
|
|
895
|
+
if (rulesetResult.status === "fulfilled" && completeRulePage(rulesetResult.value) && protectionResult.status === "rejected" && githubClients.hasBranchProtectionAbsence(protectionResult.reason, context.clients, context.repo, base)) {
|
|
896
|
+
const parameters = { ...context.repo, ...control === void 0 ? {} : { request: { signal: control.signal } } };
|
|
897
|
+
const [repository, branch, rulesets] = await Promise.allSettled([
|
|
898
|
+
context.clients.rest.request("GET /repos/{owner}/{repo}", parameters),
|
|
899
|
+
context.clients.rest.request("GET /repos/{owner}/{repo}/branches/{branch}", { ...parameters, branch: base }),
|
|
900
|
+
context.clients.rest.request("GET /repos/{owner}/{repo}/rulesets", {
|
|
901
|
+
...parameters,
|
|
902
|
+
includes_parents: true,
|
|
903
|
+
per_page: 100,
|
|
904
|
+
page: 1
|
|
905
|
+
})
|
|
906
|
+
]);
|
|
907
|
+
await control?.checkResources();
|
|
908
|
+
control?.signal.throwIfAborted();
|
|
909
|
+
if (repository.status === "fulfilled" && branch.status === "fulfilled" && rulesets.status === "fulfilled") {
|
|
910
|
+
const repoData = repository.value.data;
|
|
911
|
+
const branchData = branch.value.data;
|
|
912
|
+
const corroborated = repository.value.status === 200 && branch.value.status === 200 && typeof repoData?.full_name === "string" && repoData.full_name.toLowerCase() === `${context.repo.owner}/${context.repo.repo}`.toLowerCase() && (repoData.permissions?.push === true || repoData.permissions?.admin === true) && branchData?.name === base;
|
|
913
|
+
confirmedUnprotected = corroborated && emptyRulePage(rulesetResult.value) && branchData?.protected === false && branchData.protection?.enabled === false && emptyRulePage(rulesets.value);
|
|
914
|
+
confirmedRulesetOnly = corroborated && branchData?.protected === true && typeof branchData.protection?.enabled === "boolean" && completeRulePage(rulesets.value) && rulesetResult.value.data.length > 0 && rulesetResult.value.data.every((rule) => {
|
|
915
|
+
if (typeof rule !== "object" || rule === null || typeof rule.type !== "string" || !rule.type || typeof rule.ruleset_id !== "number" || !Number.isSafeInteger(rule.ruleset_id) || rule.ruleset_id <= 0 || typeof rule.ruleset_source !== "string" || (rule.ruleset_source_type === "Repository" ? rule.ruleset_source.toLowerCase() !== `${context.repo.owner}/${context.repo.repo}`.toLowerCase() : rule.ruleset_source_type !== "Organization" || rule.ruleset_source.toLowerCase() !== context.repo.owner.toLowerCase()) || rule.type === "pull_request" && requiredApprovalCount(rule.parameters) === null)
|
|
916
|
+
return false;
|
|
917
|
+
const matches = rulesets.value.data.filter((ruleset) => ruleset?.id === rule.ruleset_id);
|
|
918
|
+
return matches.length === 1 && matches[0]?.source_type === rule.ruleset_source_type && matches[0]?.source === rule.ruleset_source && matches[0]?.enforcement === "active";
|
|
919
|
+
});
|
|
650
920
|
}
|
|
921
|
+
}
|
|
922
|
+
return { confirmedUnprotected, confirmedRulesetOnly };
|
|
923
|
+
}
|
|
924
|
+
async function routeAuthor(context, purpose, check = async () => {
|
|
925
|
+
}, signal) {
|
|
926
|
+
const configuredAuthorSource = context.config.roles.author.authSource ?? "app";
|
|
927
|
+
const personalDevelopmentOverride = purpose === "development" && configuredAuthorSource === "app" && context.clients.authSource === "personal";
|
|
928
|
+
if (context.clients.authSource !== configuredAuthorSource && !personalDevelopmentOverride) {
|
|
929
|
+
throw new DeliveryError(
|
|
930
|
+
purpose === "publication" ? "PR publication requires the configured author credential; configure the personal author role for personal publication." : "Development access preflight requires the configured author credential or the explicit personal author override."
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
if (context.clients.role !== "author" || !context.clients.authenticatedAuthor) {
|
|
934
|
+
throw new DeliveryError("Delivery access preflight requires authenticated author identity readback.");
|
|
935
|
+
}
|
|
936
|
+
const author = await context.clients.authenticatedAuthor(signal);
|
|
937
|
+
await check();
|
|
938
|
+
if (!author.actorLogin || !author.credentialIdentity) {
|
|
939
|
+
throw new DeliveryError("Author GitHub identity readback is incomplete.");
|
|
940
|
+
}
|
|
941
|
+
return {
|
|
942
|
+
actorLogin: author.actorLogin,
|
|
943
|
+
authSource: context.clients.authSource,
|
|
944
|
+
credentialSource: context.clients.credentialSource ?? "unreported",
|
|
945
|
+
identity: personalDevelopmentOverride ? "personal" : context.config.roles.author.identity
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
async function preflightReviewRoute(context, base, selectedReviewer, purpose = "publication", control) {
|
|
949
|
+
if (base === void 0) {
|
|
651
950
|
try {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
})).data;
|
|
656
|
-
await check();
|
|
657
|
-
if (repository.full_name.toLowerCase() !== `${context.repo.owner}/${context.repo.repo}`.toLowerCase()) {
|
|
658
|
-
throw new DeliveryError('Reviewer GitHub App repository readback disagrees with the selected checkout.');
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
catch (error) {
|
|
662
|
-
if (error instanceof DeliveryError)
|
|
663
|
-
throw error;
|
|
664
|
-
throw new DeliveryError('Reviewer GitHub App cannot read the selected repository; verify its installation and repository access.');
|
|
951
|
+
base = (await context.clients.rest.repos.get({ ...context.repo })).data.default_branch;
|
|
952
|
+
} catch {
|
|
953
|
+
throw new DeliveryError("Author cannot read the selected GitHub repository; verify configured access.");
|
|
665
954
|
}
|
|
666
|
-
|
|
955
|
+
}
|
|
956
|
+
const check = async () => {
|
|
957
|
+
await control?.checkResources();
|
|
958
|
+
control?.signal.throwIfAborted();
|
|
959
|
+
};
|
|
960
|
+
await check();
|
|
961
|
+
const author = await routeAuthor(context, purpose, check, control?.signal);
|
|
962
|
+
const reviewer = selectedReviewer ?? context.reviewerClients ?? await githubClients.createDeliveryGitHubClients({
|
|
963
|
+
config: context.config,
|
|
964
|
+
identity: context.config.roles.reviewer.identity,
|
|
965
|
+
role: "reviewer",
|
|
966
|
+
selectedAuthor: context.clients,
|
|
967
|
+
...control === void 0 ? {} : { signal: control.signal }
|
|
968
|
+
});
|
|
969
|
+
await check();
|
|
970
|
+
if (reviewer.role !== "reviewer" || reviewer.authSource !== "app" || !reviewer.appActorLogin) {
|
|
971
|
+
throw new DeliveryError("Configured reviewer GitHub App identity is unavailable.");
|
|
972
|
+
}
|
|
973
|
+
const reviewerActor = await reviewer.appActorLogin(control?.signal);
|
|
974
|
+
await check();
|
|
975
|
+
if (!reviewerActor) throw new DeliveryError("Reviewer GitHub App actor lookup is incomplete.");
|
|
976
|
+
if (author.actorLogin.toLowerCase() === reviewerActor.toLowerCase()) {
|
|
977
|
+
throw new DeliveryError(
|
|
978
|
+
"Author and reviewer resolve to the same GitHub actor; select distinct configured credentials."
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
try {
|
|
982
|
+
const repository = (await reviewer.rest.repos.get({
|
|
983
|
+
...context.repo,
|
|
984
|
+
...control === void 0 ? {} : { request: { signal: control.signal } }
|
|
985
|
+
})).data;
|
|
667
986
|
await check();
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
if (rulesetResult.status === 'fulfilled' &&
|
|
671
|
-
completeRulePage(rulesetResult.value) &&
|
|
672
|
-
protectionResult.status === 'rejected' &&
|
|
673
|
-
githubClients.hasBranchProtectionAbsence(protectionResult.reason, context.clients, context.repo, base)) {
|
|
674
|
-
// A generic/permission 404 is never absence. Corroborate the named branch,
|
|
675
|
-
// selected author's write access, and all repository/parent rulesets.
|
|
676
|
-
const parameters = { ...context.repo, ...(control === undefined ? {} : { request: { signal: control.signal } }) };
|
|
677
|
-
const [repository, branch, rulesets] = await Promise.allSettled([
|
|
678
|
-
context.clients.rest.request('GET /repos/{owner}/{repo}', parameters),
|
|
679
|
-
context.clients.rest.request('GET /repos/{owner}/{repo}/branches/{branch}', { ...parameters, branch: base }),
|
|
680
|
-
context.clients.rest.request('GET /repos/{owner}/{repo}/rulesets', {
|
|
681
|
-
...parameters,
|
|
682
|
-
includes_parents: true,
|
|
683
|
-
per_page: 100,
|
|
684
|
-
page: 1,
|
|
685
|
-
}),
|
|
686
|
-
]);
|
|
687
|
-
await check();
|
|
688
|
-
if (repository.status === 'fulfilled' && branch.status === 'fulfilled' && rulesets.status === 'fulfilled') {
|
|
689
|
-
const repoData = repository.value.data;
|
|
690
|
-
const branchData = branch.value.data;
|
|
691
|
-
const corroborated = repository.value.status === 200 &&
|
|
692
|
-
branch.value.status === 200 &&
|
|
693
|
-
typeof repoData?.full_name === 'string' &&
|
|
694
|
-
repoData.full_name.toLowerCase() === `${context.repo.owner}/${context.repo.repo}`.toLowerCase() &&
|
|
695
|
-
(repoData.permissions?.push === true || repoData.permissions?.admin === true) &&
|
|
696
|
-
branchData?.name === base;
|
|
697
|
-
confirmedUnprotected =
|
|
698
|
-
corroborated &&
|
|
699
|
-
emptyRulePage(rulesetResult.value) &&
|
|
700
|
-
branchData?.protected === false &&
|
|
701
|
-
branchData.protection?.enabled === false &&
|
|
702
|
-
emptyRulePage(rulesets.value);
|
|
703
|
-
// The applicable-rules endpoint includes all active repository/parent
|
|
704
|
-
// rules. A classic-protection 404 needs independent identity and active
|
|
705
|
-
// ruleset readbacks, not just an observed approval count. The aggregate
|
|
706
|
-
// protected flag and nested enabled summary need not be equal.
|
|
707
|
-
confirmedRulesetOnly =
|
|
708
|
-
corroborated &&
|
|
709
|
-
branchData?.protected === true &&
|
|
710
|
-
typeof branchData.protection?.enabled === 'boolean' &&
|
|
711
|
-
completeRulePage(rulesets.value) &&
|
|
712
|
-
rulesetResult.value.data.length > 0 &&
|
|
713
|
-
rulesetResult.value.data.every((rule) => {
|
|
714
|
-
if (typeof rule !== 'object' ||
|
|
715
|
-
rule === null ||
|
|
716
|
-
typeof rule.type !== 'string' ||
|
|
717
|
-
!rule.type ||
|
|
718
|
-
typeof rule.ruleset_id !== 'number' ||
|
|
719
|
-
!Number.isSafeInteger(rule.ruleset_id) ||
|
|
720
|
-
rule.ruleset_id <= 0 ||
|
|
721
|
-
typeof rule.ruleset_source !== 'string' ||
|
|
722
|
-
(rule.ruleset_source_type === 'Repository'
|
|
723
|
-
? rule.ruleset_source.toLowerCase() !== `${context.repo.owner}/${context.repo.repo}`.toLowerCase()
|
|
724
|
-
: rule.ruleset_source_type !== 'Organization' ||
|
|
725
|
-
rule.ruleset_source.toLowerCase() !== context.repo.owner.toLowerCase()) ||
|
|
726
|
-
(rule.type === 'pull_request' && requiredApprovalCount(rule.parameters) === null))
|
|
727
|
-
return false;
|
|
728
|
-
const matches = rulesets.value.data.filter((ruleset) => ruleset?.id === rule.ruleset_id);
|
|
729
|
-
return (matches.length === 1 &&
|
|
730
|
-
matches[0]?.source_type === rule.ruleset_source_type &&
|
|
731
|
-
matches[0]?.source === rule.ruleset_source &&
|
|
732
|
-
matches[0]?.enforcement === 'active');
|
|
733
|
-
});
|
|
734
|
-
}
|
|
987
|
+
if (repository.full_name.toLowerCase() !== `${context.repo.owner}/${context.repo.repo}`.toLowerCase()) {
|
|
988
|
+
throw new DeliveryError("Reviewer GitHub App repository readback disagrees with the selected checkout.");
|
|
735
989
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
990
|
+
} catch (error) {
|
|
991
|
+
if (error instanceof DeliveryError) throw error;
|
|
992
|
+
throw new DeliveryError(
|
|
993
|
+
"Reviewer GitHub App cannot read the selected repository; verify its installation and repository access."
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
const [rulesetResult, protectionResult] = await branchRuleSources(context, base, control);
|
|
997
|
+
await check();
|
|
998
|
+
const { confirmedUnprotected, confirmedRulesetOnly } = await corroborateClassicProtectionAbsence(
|
|
999
|
+
context,
|
|
1000
|
+
base,
|
|
1001
|
+
[rulesetResult, protectionResult],
|
|
1002
|
+
control
|
|
1003
|
+
);
|
|
1004
|
+
const counts = [];
|
|
1005
|
+
let countsKnown = rulesetResult.status === "fulfilled" && completeRulePage(rulesetResult.value);
|
|
1006
|
+
if (rulesetResult.status === "fulfilled" && Array.isArray(rulesetResult.value.data)) {
|
|
1007
|
+
for (const rule of rulesetResult.value.data) {
|
|
1008
|
+
if (typeof rule !== "object" || rule === null || typeof rule.type !== "string" || !rule.type) countsKnown = false;
|
|
1009
|
+
if (rule?.type === "pull_request") {
|
|
1010
|
+
const count = requiredApprovalCount(rule.parameters);
|
|
1011
|
+
if (count === null) countsKnown = false;
|
|
1012
|
+
else counts.push(count);
|
|
1013
|
+
}
|
|
760
1014
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
reviewer: {
|
|
787
|
-
actorLogin: reviewerActor,
|
|
788
|
-
credentialSource: reviewer.credentialSource ?? 'unreported',
|
|
789
|
-
effectiveContentsPermission: reviewer.effectiveContentsPermission ?? 'unknown',
|
|
790
|
-
identity: context.config.roles.reviewer.identity,
|
|
791
|
-
repositoryAccess: 'readable',
|
|
792
|
-
},
|
|
793
|
-
rules: { observedRequiredApprovals, visibility },
|
|
794
|
-
approvalEligibility: insufficientPermission ? 'insufficient-permission' : 'unknown',
|
|
795
|
-
nextAction: insufficientPermission
|
|
796
|
-
? 'The reviewer App token has Contents: read, but the visible rule requires approval from a reviewer with repository write access. To use the App for required approval, grant Contents: write, accept the installation permission change, and obtain a fresh token before publication.'
|
|
797
|
-
: visibility === 'complete' && observedRequiredApprovals === null
|
|
798
|
-
? 'No required approving review was observed in the visible rules. Confirm the live PR review decision after exact-head submission.'
|
|
799
|
-
: visibility === 'complete'
|
|
800
|
-
? 'Confirm whether the reviewer approval counts after exact-head submission; installation scopes do not prove required-review eligibility.'
|
|
801
|
-
: 'Inspect the active branch review rule with an authorized repository view and confirm whether the reviewer approval counts after exact-head submission.',
|
|
802
|
-
};
|
|
1015
|
+
}
|
|
1016
|
+
if (protectionResult.status === "fulfilled") {
|
|
1017
|
+
const protection = protectionResult.value.data;
|
|
1018
|
+
const count = typeof protection === "object" && protection !== null && !Array.isArray(protection) ? requiredApprovalCount(protection.required_pull_request_reviews) : null;
|
|
1019
|
+
if (protectionResult.value.status !== 200 || count === null) countsKnown = false;
|
|
1020
|
+
if (count !== null) counts.push(count);
|
|
1021
|
+
} else if (!confirmedUnprotected && !confirmedRulesetOnly) countsKnown = false;
|
|
1022
|
+
const rulesVisible = rulesetResult.status === "fulfilled" && Array.isArray(rulesetResult.value.data) && (rulesetResult.value.headers?.link === void 0 || rulesetResult.value.headers.link === "");
|
|
1023
|
+
const visible = Number(rulesVisible) + Number(protectionResult.status === "fulfilled" || confirmedUnprotected || confirmedRulesetOnly);
|
|
1024
|
+
const visibility = visible === 2 ? "complete" : visible === 1 ? "partial" : "unknown";
|
|
1025
|
+
const observedRequiredApprovals = counts.length > 0 && (countsKnown || counts.some((count) => count > 0)) ? Math.max(...counts) : countsKnown && confirmedUnprotected ? 0 : null;
|
|
1026
|
+
const insufficientPermission = observedRequiredApprovals !== null && observedRequiredApprovals > 0 && reviewer.effectiveContentsPermission === "read";
|
|
1027
|
+
return {
|
|
1028
|
+
author,
|
|
1029
|
+
reviewer: {
|
|
1030
|
+
actorLogin: reviewerActor,
|
|
1031
|
+
credentialSource: reviewer.credentialSource ?? "unreported",
|
|
1032
|
+
effectiveContentsPermission: reviewer.effectiveContentsPermission ?? "unknown",
|
|
1033
|
+
identity: context.config.roles.reviewer.identity,
|
|
1034
|
+
repositoryAccess: "readable"
|
|
1035
|
+
},
|
|
1036
|
+
rules: { observedRequiredApprovals, visibility },
|
|
1037
|
+
approvalEligibility: insufficientPermission ? "insufficient-permission" : "unknown",
|
|
1038
|
+
nextAction: insufficientPermission ? "The reviewer App token has Contents: read, but the visible rule requires approval from a reviewer with repository write access. To use the App for required approval, grant Contents: write, accept the installation permission change, and obtain a fresh token before publication." : visibility === "complete" && observedRequiredApprovals === null ? "No required approving review was observed in the visible rules. Confirm the live PR review decision after exact-head submission." : visibility === "complete" ? "Confirm whether the reviewer approval counts after exact-head submission; installation scopes do not prove required-review eligibility." : "Inspect the active branch review rule with an authorized repository view and confirm whether the reviewer approval counts after exact-head submission."
|
|
1039
|
+
};
|
|
803
1040
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
current.base.ref !== base ||
|
|
894
|
-
current.base.sha !== existing.base.sha ||
|
|
895
|
-
current.user.login.toLowerCase() !== reviewRoute.author.actorLogin.toLowerCase() ||
|
|
896
|
-
(transition && !promotionApplied && current.draft !== transitionDraft) ||
|
|
897
|
-
current.body !== expectedBody ||
|
|
898
|
-
current.title !== existing.title)
|
|
899
|
-
throw new DeliveryError('Existing PR publication head, identity, intent or author readback drifted.');
|
|
900
|
-
if (pendingTransition) {
|
|
901
|
-
await verifyPrIssueAssociation(context, current.number, input.issueNumber, false, current.node_id, true, issue.node_id, repository.node_id);
|
|
902
|
-
refuseClosingDirective(current.title);
|
|
903
|
-
await verifyNonClosingCommits(context, current);
|
|
904
|
-
const baseRef = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${base}` })).data;
|
|
905
|
-
if (baseRef.ref !== `refs/heads/${base}` ||
|
|
906
|
-
baseRef.object.type !== 'commit' ||
|
|
907
|
-
baseRef.object.sha !== current.base.sha)
|
|
908
|
-
throw new DeliveryError('Non-closing transition default base drifted.');
|
|
909
|
-
sameReferencePr(current, await getPr(context, current.number));
|
|
910
|
-
}
|
|
911
|
-
await preserveIssue();
|
|
912
|
-
return current;
|
|
913
|
-
};
|
|
914
|
-
const readNew = async () => {
|
|
915
|
-
const baseRef = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${base}` })).data;
|
|
916
|
-
if (baseRef.ref !== `refs/heads/${base}` || baseRef.object.type !== 'commit' || !validSha(baseRef.object.sha))
|
|
917
|
-
throw new DeliveryError('Incomplete publication default base.');
|
|
918
|
-
if (publicationBaseSha !== undefined && publicationBaseSha !== baseRef.object.sha)
|
|
919
|
-
throw new DeliveryError('Publication default base drifted before creation.');
|
|
920
|
-
publicationBaseSha = baseRef.object.sha;
|
|
921
|
-
if (nonClosing)
|
|
922
|
-
await verifyUnpublishedCommits(context, baseRef.object.sha, ref.object.sha);
|
|
923
|
-
const afterHead = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${branch}` })).data;
|
|
924
|
-
const afterBase = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${base}` })).data;
|
|
925
|
-
if (afterHead.ref !== ref.ref ||
|
|
926
|
-
afterHead.object.type !== 'commit' ||
|
|
927
|
-
afterHead.object.sha !== ref.object.sha ||
|
|
928
|
-
afterBase.ref !== baseRef.ref ||
|
|
929
|
-
afterBase.object.type !== 'commit' ||
|
|
930
|
-
afterBase.object.sha !== baseRef.object.sha)
|
|
931
|
-
throw new DeliveryError('Non-closing publication head/base drifted.');
|
|
932
|
-
await preserveIssue();
|
|
933
|
-
};
|
|
934
|
-
if (pr)
|
|
935
|
-
pr = await readExisting();
|
|
936
|
-
else
|
|
937
|
-
await readNew();
|
|
938
|
-
if (input.dryRun)
|
|
939
|
-
return {
|
|
940
|
-
dryRun: true,
|
|
941
|
-
...(pr === undefined ? {} : { prNumber: pr.number, draft: pr.draft }),
|
|
942
|
-
...(nonClosing
|
|
943
|
-
? {
|
|
944
|
-
nonClosing: true,
|
|
945
|
-
nonClosingVerified: pr !== undefined && !pendingTransition,
|
|
946
|
-
body,
|
|
947
|
-
bodyTransition: pendingTransition,
|
|
948
|
-
}
|
|
949
|
-
: {}),
|
|
950
|
-
headSha: ref.object.sha,
|
|
951
|
-
headBranch: branch,
|
|
952
|
-
baseBranch: base,
|
|
953
|
-
reviewRoute,
|
|
954
|
-
};
|
|
955
|
-
let created = false;
|
|
956
|
-
if (pr) {
|
|
957
|
-
if (pendingTransition) {
|
|
958
|
-
pr = await readExisting();
|
|
959
|
-
await context.clients.rest.pulls.update({ ...context.repo, pull_number: pr.number, body });
|
|
960
|
-
pendingTransition = false;
|
|
961
|
-
expectedBody = body;
|
|
962
|
-
pr = await readExisting();
|
|
963
|
-
}
|
|
964
|
-
if (input.draft === false && pr.draft) {
|
|
965
|
-
pr = await readExisting();
|
|
966
|
-
if (pr.draft) {
|
|
967
|
-
const promoted = await context.clients.graphql('mutation DeliveryReadyPr($id:ID!){markPullRequestReadyForReview(input:{pullRequestId:$id}){pullRequest{id isDraft}}}', { id: pr.node_id });
|
|
968
|
-
if (promoted?.markPullRequestReadyForReview?.pullRequest?.id !== pr.node_id ||
|
|
969
|
-
promoted.markPullRequestReadyForReview.pullRequest.isDraft !== false)
|
|
970
|
-
throw new DeliveryError('PR promotion mutation readback is incomplete or conflicting; reconcile this PR.');
|
|
971
|
-
promotionApplied = true;
|
|
972
|
-
}
|
|
973
|
-
pr = await readExisting();
|
|
974
|
-
if (pr.draft)
|
|
975
|
-
throw new DeliveryError('PR promotion readback is still draft.');
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
else {
|
|
979
|
-
await readNew();
|
|
980
|
-
let response;
|
|
981
|
-
try {
|
|
982
|
-
response = await context.clients.rest.pulls.create({
|
|
983
|
-
...context.repo,
|
|
984
|
-
head: branch,
|
|
985
|
-
base,
|
|
986
|
-
title: creationTitle,
|
|
987
|
-
body,
|
|
988
|
-
draft: input.draft !== false,
|
|
989
|
-
});
|
|
990
|
-
}
|
|
991
|
-
catch (error) {
|
|
992
|
-
throw new DeliveryError(`PR creation acknowledgement is uncertain; reconcile the remote head read-only before any new mutation. ${error instanceof Error ? error.message : 'Unknown failure'}`);
|
|
993
|
-
}
|
|
994
|
-
if (!Number.isSafeInteger(response.data.number) || response.data.number <= 0)
|
|
995
|
-
throw new DeliveryError('PR creation acknowledgement lacks a valid PR identity; reconcile the remote head read-only, do not create again.');
|
|
996
|
-
created = true;
|
|
997
|
-
try {
|
|
998
|
-
pr = await getPr(context, response.data.number);
|
|
999
|
-
}
|
|
1000
|
-
catch (error) {
|
|
1001
|
-
throw new DeliveryError(`GitHub returned created PR #${response.data.number}; identity readback is unresolved. Reconcile read-only; do not create again. ${error instanceof Error ? error.message : 'Unknown failure'}`);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1041
|
+
async function publishPr(context, input) {
|
|
1042
|
+
const nonClosing = nonClosingMode(input.nonClosing);
|
|
1043
|
+
const reconcileReference = nonClosingMode(input.reconcileNonClosingReference);
|
|
1044
|
+
if (reconcileReference) {
|
|
1045
|
+
if (context.clients.role !== "author" || context.clients.authSource !== (context.config.roles.author.authSource ?? "app") || !context.clients.authenticatedAuthor)
|
|
1046
|
+
throw new DeliveryError("Reference reconciliation requires the configured authenticated author role.");
|
|
1047
|
+
if (!nonClosing || input.draft === false || !validSha(input.expectedHeadSha) || !validSha(input.expectedBaseSha) || typeof input.body !== "string" || !input.body.trim())
|
|
1048
|
+
throw new DeliveryError(
|
|
1049
|
+
"Reference reconciliation requires nonClosing, DRAFT, explicit safe body and exact expected head/base SHAs."
|
|
1050
|
+
);
|
|
1051
|
+
refuseClosingDirective(input.body);
|
|
1052
|
+
} else if (input.expectedHeadSha !== void 0 || input.expectedBaseSha !== void 0)
|
|
1053
|
+
throw new DeliveryError("Expected head/base inputs require explicit reconcileNonClosingReference.");
|
|
1054
|
+
if (input.prNumber !== void 0 && (!Number.isSafeInteger(input.prNumber) || input.prNumber <= 0))
|
|
1055
|
+
throw new DeliveryError("Existing PR selector must be a positive safe integer.");
|
|
1056
|
+
const issue = nonClosing ? await openReferenceIssue(context, input.issueNumber) : (await context.clients.rest.issues.get({ ...context.repo, issue_number: input.issueNumber })).data;
|
|
1057
|
+
if ("pull_request" in issue || issue.number !== input.issueNumber || issue.state !== "open")
|
|
1058
|
+
throw new DeliveryError("PR creation requires the requested open GitHub issue.");
|
|
1059
|
+
const repository = (await context.clients.rest.repos.get({ ...context.repo })).data;
|
|
1060
|
+
if (repository.full_name?.toLowerCase() !== context.config.repository.toLowerCase() || context.config.repository.toLowerCase() !== `${context.repo.owner}/${context.repo.repo}`.toLowerCase())
|
|
1061
|
+
throw new DeliveryError("Configured and selected GitHub repository identities disagree.");
|
|
1062
|
+
if (nonClosing && !nativeId(repository.node_id))
|
|
1063
|
+
throw new DeliveryError("Incomplete canonical non-closing repository node identity.");
|
|
1064
|
+
const base = input.baseBranch ?? repository.default_branch;
|
|
1065
|
+
if (base !== repository.default_branch)
|
|
1066
|
+
throw new DeliveryError("PR delivery requires the repository default branch for durable issue association.");
|
|
1067
|
+
validBranch(base);
|
|
1068
|
+
if (input.headBranch !== void 0) validBranch(input.headBranch);
|
|
1069
|
+
const explicit = input.prNumber === void 0 ? void 0 : await getPr(context, input.prNumber);
|
|
1070
|
+
const explicitPromotion = nonClosing && input.draft === false && input.headBranch !== void 0;
|
|
1071
|
+
const selectedMatches = explicitPromotion ? await matchingPrs(context, input.headBranch, base) : void 0;
|
|
1072
|
+
const branch = explicit ? explicit.head.ref : nonClosing ? explicitPromotion && selectedMatches.length > 0 ? input.headBranch : await issueBranch(context, input.issueNumber, input.headBranch) : input.headBranch ?? await issueBranch(context, input.issueNumber);
|
|
1073
|
+
if (input.headBranch !== void 0 && branch !== input.headBranch)
|
|
1074
|
+
throw new DeliveryError("Explicit PR and head selectors disagree.");
|
|
1075
|
+
validBranch(branch);
|
|
1076
|
+
const ref = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${branch}` })).data;
|
|
1077
|
+
if (ref.ref !== `refs/heads/${branch}` || ref.object.type !== "commit" || !validSha(ref.object.sha))
|
|
1078
|
+
throw new DeliveryError("Remote issue branch head/ref readback is invalid.");
|
|
1079
|
+
const matches = selectedMatches ?? await matchingPrs(context, branch, base, nonClosing ? "all" : "open");
|
|
1080
|
+
if (matches.length > 1 || explicit && (matches.length !== 1 || matches[0].number !== explicit.number))
|
|
1081
|
+
throw new DeliveryError("Remote issue branch has conflicting PR matches.");
|
|
1082
|
+
let pr = explicit ?? (matches[0] === void 0 ? void 0 : await getPr(context, matches[0].number));
|
|
1083
|
+
if (pr && input.draft === false && input.headBranch === void 0 && input.prNumber === void 0 && (await linkedIssueBranches(context, input.issueNumber)).filter((entry) => entry.name === branch).length !== 1)
|
|
1084
|
+
throw new DeliveryError("Select an explicit PR or head after GitHub-linked branch references disappear.");
|
|
1085
|
+
if (reconcileReference && pr && !explicit)
|
|
1086
|
+
throw new DeliveryError(
|
|
1087
|
+
"Reference reconciliation of an existing match requires explicit --pr and caller-reconciled authority/attempt receipts."
|
|
1088
|
+
);
|
|
1089
|
+
if (nonClosing && !pr && !reconcileReference)
|
|
1090
|
+
throw new DeliveryError(
|
|
1091
|
+
"New linked-branch non-closing publication requires explicitly authorized --reconcile-non-closing-reference --expected-head SHA --expected-base SHA and --body-file PATH; bare --non-closing grants no removal authority."
|
|
1092
|
+
);
|
|
1093
|
+
if (reconcileReference && ref.object.sha !== input.expectedHeadSha)
|
|
1094
|
+
throw new DeliveryError("Reference reconciliation expected head differs from the exact remote linked head.");
|
|
1095
|
+
const requestedBody = input.body ?? pr?.body ?? (nonClosing ? referenceLine(context, input.issueNumber) : closingBody(issue));
|
|
1096
|
+
if ((nonClosing || input.body !== void 0) && !requestedBody.trim())
|
|
1097
|
+
throw new DeliveryError("PR body must contain text.");
|
|
1098
|
+
const body = publicationBody(
|
|
1099
|
+
nonClosing ? nonClosingBody(context, input.issueNumber, requestedBody) : closingBody(issue, requestedBody),
|
|
1100
|
+
pr?.body
|
|
1101
|
+
);
|
|
1102
|
+
const closingRepair = !nonClosing && pr !== void 0 && !hasClosingLink(pr.body, input.issueNumber);
|
|
1103
|
+
const transition = nonClosing && pr !== void 0 && pr.body !== body;
|
|
1104
|
+
const referenceUpdate = transition && hasReferenceBody(context, input.issueNumber, pr?.body);
|
|
1105
|
+
if (reconcileReference && transition)
|
|
1106
|
+
throw new DeliveryError("Reference reconciliation refuses body transition; retain exact original intent.");
|
|
1107
|
+
if (transition && (input.prNumber === void 0 || input.body === void 0))
|
|
1108
|
+
throw new DeliveryError("Non-closing body transition requires an explicit existing PR number and body.");
|
|
1109
|
+
if (pr && (pr.head.sha !== ref.object.sha || pr.head.ref !== branch || pr.base.ref !== base || pr.state !== "open" || pr.merged || !transition && input.body !== void 0 && pr.body !== input.body && pr.body !== body || input.title !== void 0 && pr.title !== input.title))
|
|
1110
|
+
throw new DeliveryError("Existing remote PR conflicts with the requested branch, intent or state.");
|
|
1111
|
+
const reviewRoute = nonClosing ? await nonClosingRoute(context, base) : { author: await routeAuthor(context, "publication") };
|
|
1112
|
+
if (pr && pr.user.login.toLowerCase() !== reviewRoute.author.actorLogin.toLowerCase())
|
|
1113
|
+
throw new DeliveryError("Existing PR author differs from the configured authenticated author.");
|
|
1114
|
+
if (pr && (typeof pr.node_id !== "string" || !pr.node_id))
|
|
1115
|
+
throw new DeliveryError("Existing PR publication identity is incomplete.");
|
|
1116
|
+
if (nonClosing) refuseClosingDirective(input.title ?? pr?.title ?? issue.title);
|
|
1117
|
+
const creationTitle = input.title ?? issue.title;
|
|
1118
|
+
let publicationBaseSha;
|
|
1119
|
+
const existing = pr;
|
|
1120
|
+
let pendingTransition = transition;
|
|
1121
|
+
let pendingClosingRepair = closingRepair;
|
|
1122
|
+
let expectedBody = pr?.body;
|
|
1123
|
+
const transitionDraft = pr?.draft;
|
|
1124
|
+
let promotionApplied = false;
|
|
1125
|
+
let removalState = "not attempted";
|
|
1126
|
+
const preserveIssue = async () => {
|
|
1127
|
+
if (nonClosing) sameReferenceIssue(issue, await openReferenceIssue(context, input.issueNumber));
|
|
1128
|
+
};
|
|
1129
|
+
const readReconciliation = async (selected) => {
|
|
1004
1130
|
try {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
await verifyPrIssueAssociation(context, pr.number, input.issueNumber);
|
|
1025
|
-
if (created) {
|
|
1026
|
-
const final = await getPr(context, pr.number);
|
|
1027
|
-
sameReferencePr(pr, final);
|
|
1028
|
-
pr = final;
|
|
1029
|
-
}
|
|
1131
|
+
if (selected.state !== "open" || selected.draft !== true || selected.merged || selected.head.sha !== input.expectedHeadSha || selected.base.sha !== input.expectedBaseSha || selected.head.ref !== branch || selected.base.ref !== base || selected.body !== body || selected.title !== (existing?.title ?? creationTitle) || selected.user.login.toLowerCase() !== reviewRoute.author.actorLogin.toLowerCase())
|
|
1132
|
+
throw new DeliveryError("Reference reconciliation DRAFT, exact head/base, message or author drifted.");
|
|
1133
|
+
const graph = await readNonClosingReference(context, input.issueNumber, selected);
|
|
1134
|
+
sameReferenceIssue(issue, graph.issue);
|
|
1135
|
+
const safe = !graph.closesTarget && !graph.allClosing.length && !graph.manualClosing.length;
|
|
1136
|
+
if (!safe && !(graph.closesTarget && graph.allClosing.length === 1 && graph.manualClosing.length === 1))
|
|
1137
|
+
throw new DeliveryError(
|
|
1138
|
+
"Reference removal requires only the intended manual closing pair and closing cross-reference."
|
|
1139
|
+
);
|
|
1140
|
+
const currentHead = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${branch}` })).data;
|
|
1141
|
+
if (currentHead.ref !== ref.ref || currentHead.object.type !== "commit" || currentHead.object.sha !== input.expectedHeadSha)
|
|
1142
|
+
throw new DeliveryError("Reference reconciliation source head drifted.");
|
|
1143
|
+
sameReferencePr(selected, await getPr(context, selected.number));
|
|
1144
|
+
await preserveIssue();
|
|
1145
|
+
return !safe;
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
throw new DeliveryError(
|
|
1148
|
+
`PR #${selected.number}; reference removal ${removalState}. Reconcile read-only; do not retry without caller-established authority and attempt history. ${error instanceof Error ? error.message : "Unknown failure"}`
|
|
1149
|
+
);
|
|
1030
1150
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1151
|
+
};
|
|
1152
|
+
const readExisting = async () => {
|
|
1153
|
+
const current = reconcileReference || pendingClosingRepair ? await getPr(context, existing.number) : await verifyIssuePr(
|
|
1154
|
+
context,
|
|
1155
|
+
input.issueNumber,
|
|
1156
|
+
existing.number,
|
|
1157
|
+
nonClosing && (!pendingTransition || referenceUpdate)
|
|
1158
|
+
);
|
|
1159
|
+
if (current.state !== "open" || current.merged || current.node_id !== existing.node_id || current.head.sha !== ref.object.sha || current.head.ref !== branch || current.base.ref !== base || current.base.sha !== existing.base.sha || current.user.login.toLowerCase() !== reviewRoute.author.actorLogin.toLowerCase() || (transition || closingRepair) && !promotionApplied && current.draft !== transitionDraft || current.body !== expectedBody || current.title !== existing.title)
|
|
1160
|
+
throw new DeliveryError("Existing PR publication head, identity, intent or author readback drifted.");
|
|
1161
|
+
if (reconcileReference) await readReconciliation(current);
|
|
1162
|
+
if (pendingClosingRepair) {
|
|
1163
|
+
await verifyPrIssueAssociation(
|
|
1164
|
+
context,
|
|
1165
|
+
current.number,
|
|
1166
|
+
input.issueNumber,
|
|
1167
|
+
current.node_id,
|
|
1168
|
+
true,
|
|
1169
|
+
issue.node_id,
|
|
1170
|
+
repository.node_id,
|
|
1171
|
+
{ allowMissing: true }
|
|
1172
|
+
);
|
|
1173
|
+
const currentRef = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${branch}` })).data;
|
|
1174
|
+
if (currentRef.ref !== ref.ref || currentRef.object.type !== "commit" || currentRef.object.sha !== ref.object.sha)
|
|
1175
|
+
throw new DeliveryError("Closing-link repair remote head drifted; reconcile read-only.");
|
|
1176
|
+
sameReferencePr(current, await getPr(context, current.number));
|
|
1177
|
+
}
|
|
1178
|
+
if (pendingTransition && !referenceUpdate) {
|
|
1179
|
+
await verifyPrIssueAssociation(
|
|
1180
|
+
context,
|
|
1181
|
+
current.number,
|
|
1182
|
+
input.issueNumber,
|
|
1183
|
+
current.node_id,
|
|
1184
|
+
true,
|
|
1185
|
+
issue.node_id,
|
|
1186
|
+
repository.node_id
|
|
1187
|
+
);
|
|
1188
|
+
refuseClosingDirective(current.title);
|
|
1189
|
+
await verifyNonClosingCommits(context, current);
|
|
1190
|
+
const baseRef = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${base}` })).data;
|
|
1191
|
+
if (baseRef.ref !== `refs/heads/${base}` || baseRef.object.type !== "commit" || baseRef.object.sha !== current.base.sha)
|
|
1192
|
+
throw new DeliveryError("Non-closing transition default base drifted.");
|
|
1193
|
+
sameReferencePr(current, await getPr(context, current.number));
|
|
1035
1194
|
}
|
|
1195
|
+
await preserveIssue();
|
|
1196
|
+
return current;
|
|
1197
|
+
};
|
|
1198
|
+
const readNew = async () => {
|
|
1199
|
+
const baseRef = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${base}` })).data;
|
|
1200
|
+
if (baseRef.ref !== `refs/heads/${base}` || baseRef.object.type !== "commit" || !validSha(baseRef.object.sha))
|
|
1201
|
+
throw new DeliveryError("Incomplete publication default base.");
|
|
1202
|
+
if (publicationBaseSha !== void 0 && publicationBaseSha !== baseRef.object.sha)
|
|
1203
|
+
throw new DeliveryError("Publication default base drifted before creation.");
|
|
1204
|
+
publicationBaseSha = baseRef.object.sha;
|
|
1205
|
+
if (reconcileReference && publicationBaseSha !== input.expectedBaseSha)
|
|
1206
|
+
throw new DeliveryError("Reference reconciliation expected default base differs from the remote base.");
|
|
1207
|
+
if (nonClosing) await verifyUnpublishedCommits(context, baseRef.object.sha, ref.object.sha);
|
|
1208
|
+
const afterHead = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${branch}` })).data;
|
|
1209
|
+
const afterBase = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${base}` })).data;
|
|
1210
|
+
if (afterHead.ref !== ref.ref || afterHead.object.type !== "commit" || afterHead.object.sha !== ref.object.sha || afterBase.ref !== baseRef.ref || afterBase.object.type !== "commit" || afterBase.object.sha !== baseRef.object.sha)
|
|
1211
|
+
throw new DeliveryError("Non-closing publication head/base drifted.");
|
|
1212
|
+
await preserveIssue();
|
|
1213
|
+
};
|
|
1214
|
+
if (pr) pr = await readExisting();
|
|
1215
|
+
else await readNew();
|
|
1216
|
+
if (input.dryRun)
|
|
1036
1217
|
return {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1218
|
+
dryRun: true,
|
|
1219
|
+
...pr === void 0 ? { body } : {},
|
|
1220
|
+
...pr === void 0 ? {} : { prNumber: pr.number, draft: pr.draft },
|
|
1221
|
+
...nonClosing ? {
|
|
1222
|
+
nonClosing: true,
|
|
1223
|
+
nonClosingVerified: pr !== void 0 && !pendingTransition,
|
|
1224
|
+
body,
|
|
1225
|
+
bodyTransition: pendingTransition
|
|
1226
|
+
} : {},
|
|
1227
|
+
headSha: ref.object.sha,
|
|
1228
|
+
headBranch: branch,
|
|
1229
|
+
baseBranch: base,
|
|
1230
|
+
reviewRoute,
|
|
1231
|
+
...closingRepair ? { closingLinkAdded: false, body } : {},
|
|
1232
|
+
...reconcileReference ? { referenceRemoval: "pending", nonClosingVerified: false } : {}
|
|
1043
1233
|
};
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
context,
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1234
|
+
let created = false;
|
|
1235
|
+
const warnings = [];
|
|
1236
|
+
if (pr) {
|
|
1237
|
+
if (pendingClosingRepair) {
|
|
1238
|
+
pr = await readExisting();
|
|
1239
|
+
try {
|
|
1240
|
+
await context.clients.rest.pulls.update({ ...context.repo, pull_number: pr.number, body });
|
|
1241
|
+
} catch (error) {
|
|
1242
|
+
throw new DeliveryError(
|
|
1243
|
+
`PR #${pr.number} closing-link repair acknowledgement is uncertain; reconcile this PR read-only before retrying. ${error instanceof Error ? error.message : "Unknown failure"}`
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
pendingClosingRepair = false;
|
|
1247
|
+
expectedBody = body;
|
|
1248
|
+
pr = await readExisting();
|
|
1059
1249
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
if (context.clients.role !== 'author' ||
|
|
1067
|
-
context.clients.authSource !== (context.config.roles.author.authSource ?? 'app') ||
|
|
1068
|
-
!context.clients.authenticatedAuthor)
|
|
1069
|
-
throw new DeliveryError('Merge and finish require the configured authenticated author role.');
|
|
1070
|
-
const author = await context.clients.authenticatedAuthor();
|
|
1071
|
-
if (!author.actorLogin || !author.credentialIdentity)
|
|
1072
|
-
throw new DeliveryError('Author identity readback is incomplete.');
|
|
1073
|
-
let pr = await verifyIssuePr(context, input.issueNumber, input.prNumber, nonClosing);
|
|
1074
|
-
const initialPr = pr;
|
|
1075
|
-
const issue = nonClosing ? await openReferenceIssue(context, input.issueNumber) : undefined;
|
|
1076
|
-
const squash = nonClosing
|
|
1077
|
-
? {
|
|
1078
|
-
commit_title: pr.title,
|
|
1079
|
-
commit_message: `${referenceLine(context, input.issueNumber)}\n\nDelivered by PR #${pr.number}.`,
|
|
1080
|
-
}
|
|
1081
|
-
: undefined;
|
|
1082
|
-
if (squash) {
|
|
1083
|
-
refuseClosingDirective(squash.commit_title);
|
|
1084
|
-
refuseClosingDirective(squash.commit_message);
|
|
1250
|
+
if (pendingTransition) {
|
|
1251
|
+
pr = await readExisting();
|
|
1252
|
+
await context.clients.rest.pulls.update({ ...context.repo, pull_number: pr.number, body });
|
|
1253
|
+
pendingTransition = false;
|
|
1254
|
+
expectedBody = body;
|
|
1255
|
+
pr = await readExisting();
|
|
1085
1256
|
}
|
|
1086
|
-
if (input.
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
});
|
|
1100
|
-
if (blockers.blockers.some((value) => value.state === 'OPEN'))
|
|
1101
|
-
throw new DeliveryError('GitHub issue has unresolved native blockers.');
|
|
1102
|
-
pr = await verifyIssuePr(context, input.issueNumber, input.prNumber, nonClosing);
|
|
1103
|
-
if (nonClosing) {
|
|
1104
|
-
sameReferencePr(initialPr, pr);
|
|
1105
|
-
sameReferenceIssue(issue, await openReferenceIssue(context, input.issueNumber));
|
|
1106
|
-
refuseClosingDirective(squash.commit_title);
|
|
1107
|
-
refuseClosingDirective(squash.commit_message);
|
|
1257
|
+
if (input.draft === false && pr.draft) {
|
|
1258
|
+
pr = await readExisting();
|
|
1259
|
+
if (pr.draft) {
|
|
1260
|
+
const promoted = await context.clients.graphql(
|
|
1261
|
+
"mutation DeliveryReadyPr($id:ID!){markPullRequestReadyForReview(input:{pullRequestId:$id}){pullRequest{id isDraft}}}",
|
|
1262
|
+
{ id: pr.node_id }
|
|
1263
|
+
);
|
|
1264
|
+
if (promoted?.markPullRequestReadyForReview?.pullRequest?.id !== pr.node_id || promoted.markPullRequestReadyForReview.pullRequest.isDraft !== false)
|
|
1265
|
+
throw new DeliveryError("PR promotion mutation readback is incomplete or conflicting; reconcile this PR.");
|
|
1266
|
+
promotionApplied = true;
|
|
1267
|
+
}
|
|
1268
|
+
pr = await readExisting();
|
|
1269
|
+
if (pr.draft) throw new DeliveryError("PR promotion readback is still draft.");
|
|
1108
1270
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1271
|
+
} else {
|
|
1272
|
+
await readNew();
|
|
1273
|
+
let response;
|
|
1274
|
+
try {
|
|
1275
|
+
response = await context.clients.rest.pulls.create({
|
|
1276
|
+
...context.repo,
|
|
1277
|
+
head: branch,
|
|
1278
|
+
base,
|
|
1279
|
+
title: creationTitle,
|
|
1280
|
+
body,
|
|
1281
|
+
draft: input.draft !== false
|
|
1282
|
+
});
|
|
1283
|
+
} catch (error) {
|
|
1284
|
+
throw new DeliveryError(
|
|
1285
|
+
`PR creation acknowledgement is uncertain; reconcile the remote head read-only before any new mutation. ${error instanceof Error ? error.message : "Unknown failure"}`
|
|
1286
|
+
);
|
|
1114
1287
|
}
|
|
1115
|
-
if (
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1288
|
+
if (!Number.isSafeInteger(response.data.number) || response.data.number <= 0)
|
|
1289
|
+
throw new DeliveryError(
|
|
1290
|
+
"PR creation acknowledgement lacks a valid PR identity; reconcile the remote head read-only, do not create again."
|
|
1291
|
+
);
|
|
1292
|
+
created = true;
|
|
1293
|
+
try {
|
|
1294
|
+
pr = await getPr(context, response.data.number);
|
|
1295
|
+
} catch (error) {
|
|
1296
|
+
throw new DeliveryError(
|
|
1297
|
+
`GitHub returned created PR #${response.data.number}; identity readback is unresolved. Reconcile read-only; do not create again. ${error instanceof Error ? error.message : "Unknown failure"}`
|
|
1298
|
+
);
|
|
1125
1299
|
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
if (
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
};
|
|
1137
|
-
const result = (await context.clients.rest.pulls.merge({
|
|
1138
|
-
...context.repo,
|
|
1139
|
-
pull_number: input.prNumber,
|
|
1140
|
-
sha: reviewedHead,
|
|
1141
|
-
merge_method: input.strategy ?? 'squash',
|
|
1142
|
-
...squash,
|
|
1143
|
-
})).data;
|
|
1144
|
-
if (!result.merged || !validSha(result.sha))
|
|
1145
|
-
throw new DeliveryError('GitHub refused the reviewed-head merge.');
|
|
1146
|
-
const readback = await verifyIssuePr(context, input.issueNumber, input.prNumber, nonClosing);
|
|
1300
|
+
}
|
|
1301
|
+
try {
|
|
1302
|
+
if (created && (pr.body !== body || pr.title !== creationTitle || pr.draft !== (input.draft !== false) || pr.state !== "open" || pr.merged || pr.base.sha !== publicationBaseSha))
|
|
1303
|
+
throw new DeliveryError(
|
|
1304
|
+
"Created PR body, title, draft/open state or default base differs from publication intent."
|
|
1305
|
+
);
|
|
1306
|
+
if (pr.head.sha !== ref.object.sha || pr.head.ref !== branch || pr.base.ref !== base)
|
|
1307
|
+
throw new DeliveryError("GitHub PR creation readback drifted.");
|
|
1308
|
+
if (pr.user.login.toLowerCase() !== reviewRoute.author.actorLogin.toLowerCase())
|
|
1309
|
+
throw new DeliveryError("Published PR author differs from the configured authenticated author.");
|
|
1147
1310
|
if (nonClosing) {
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
const pr = await verifyIssuePr(context, input.issueNumber, input.prNumber);
|
|
1165
|
-
if (!pr.merged || pr.state !== 'closed' || pr.merge_commit_sha !== result.mergeSha)
|
|
1166
|
-
throw new DeliveryError('Intended GitHub PR is not verifiably merged; issue remains open.');
|
|
1167
|
-
const issue = (await context.clients.rest.issues.get({ ...context.repo, issue_number: input.issueNumber })).data;
|
|
1168
|
-
if (issue.number !== input.issueNumber || 'pull_request' in issue)
|
|
1169
|
-
throw new DeliveryError('Finish target is not the intended GitHub issue.');
|
|
1170
|
-
if (issue.state !== 'closed')
|
|
1171
|
-
await context.clients.rest.issues.update({
|
|
1172
|
-
...context.repo,
|
|
1173
|
-
issue_number: input.issueNumber,
|
|
1174
|
-
state: 'closed',
|
|
1175
|
-
state_reason: 'completed',
|
|
1176
|
-
});
|
|
1177
|
-
const readback = (await context.clients.rest.issues.get({ ...context.repo, issue_number: input.issueNumber })).data;
|
|
1178
|
-
if (readback.number !== input.issueNumber || readback.state !== 'closed')
|
|
1179
|
-
throw new DeliveryError('GitHub issue closure readback disagrees.');
|
|
1180
|
-
return { ...result, issueClosed: true };
|
|
1181
|
-
}
|
|
1182
|
-
export { startIssueBranch };
|
|
1183
|
-
function investigationRoot(context) {
|
|
1184
|
-
const root = primaryGitRoot(context.root);
|
|
1185
|
-
const repo = resolveRepoFromRemote(root, 'origin');
|
|
1186
|
-
if (`${repo.owner}/${repo.repo}`.toLowerCase() !== context.config.repository.toLowerCase() ||
|
|
1187
|
-
`${context.repo.owner}/${context.repo.repo}`.toLowerCase() !== context.config.repository.toLowerCase())
|
|
1188
|
-
throw new DeliveryError('Investigation repository identity disagrees.');
|
|
1189
|
-
return root;
|
|
1190
|
-
}
|
|
1191
|
-
async function withInvestigationExclusion(root, target, operation) {
|
|
1192
|
-
const common = gitCommonDir(root);
|
|
1193
|
-
for (const directory of [join(common, 'ai-delivery'), join(common, 'ai-delivery', 'writers@1')]) {
|
|
1194
|
-
try {
|
|
1195
|
-
const metadata = lstatSync(directory);
|
|
1196
|
-
if (!metadata.isDirectory() || metadata.isSymbolicLink())
|
|
1197
|
-
throw new DeliveryError('Investigation writer namespace is unsafe.');
|
|
1198
|
-
}
|
|
1199
|
-
catch (error) {
|
|
1200
|
-
if (error.code !== 'ENOENT')
|
|
1201
|
-
throw error;
|
|
1311
|
+
if (reconcileReference && await readReconciliation(pr)) {
|
|
1312
|
+
if (await readReconciliation(pr)) {
|
|
1313
|
+
removalState = "uncertain";
|
|
1314
|
+
try {
|
|
1315
|
+
const removed = await context.clients.graphql(
|
|
1316
|
+
"mutation DeliveryRemoveClosingReference($issueId:ID!,$pullRequestIds:[ID!]!,$clientMutationId:String!){removeCloseIssueReferences(input:{issueId:$issueId,pullRequestIds:$pullRequestIds,clientMutationId:$clientMutationId}){issue{id}}}",
|
|
1317
|
+
{ issueId: issue.node_id, pullRequestIds: [pr.node_id], clientMutationId: randomUUID() }
|
|
1318
|
+
);
|
|
1319
|
+
if (removed.removeCloseIssueReferences?.issue?.id !== issue.node_id)
|
|
1320
|
+
throw new DeliveryError("Incomplete reference-removal acknowledgement.");
|
|
1321
|
+
removalState = "acknowledged";
|
|
1322
|
+
} catch (error) {
|
|
1323
|
+
throw new DeliveryError(
|
|
1324
|
+
`PR #${pr.number}; reference removal acknowledgement is uncertain. Reconcile read-only; no automatic retry or rollback. ${error instanceof Error ? error.message : "Unknown failure"}`
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1202
1327
|
}
|
|
1203
|
-
|
|
1328
|
+
}
|
|
1329
|
+
const verified = await verifyIssuePr(context, input.issueNumber, pr.number, true);
|
|
1330
|
+
sameReferencePr(pr, verified);
|
|
1331
|
+
pr = verified;
|
|
1332
|
+
await preserveIssue();
|
|
1333
|
+
} else if (
|
|
1334
|
+
// GitHub lists a new PR's closing link a few seconds after creation (aviaratech/ai#3780).
|
|
1335
|
+
await verifyPrIssueAssociation(context, pr.number, input.issueNumber, void 0, false, void 0, void 0, {
|
|
1336
|
+
allowMissing: created
|
|
1337
|
+
}) === 0
|
|
1338
|
+
)
|
|
1339
|
+
warnings.push(
|
|
1340
|
+
`GitHub has not yet listed PR #${pr.number} as closing #${input.issueNumber}; confirm with issue_pr_info.`
|
|
1341
|
+
);
|
|
1342
|
+
if (created) {
|
|
1343
|
+
const final = await getPr(context, pr.number);
|
|
1344
|
+
sameReferencePr(pr, final);
|
|
1345
|
+
pr = final;
|
|
1204
1346
|
}
|
|
1205
|
-
|
|
1347
|
+
} catch (error) {
|
|
1348
|
+
if (!created && !reconcileReference) throw error;
|
|
1349
|
+
throw new DeliveryError(
|
|
1350
|
+
`GitHub ${created ? "created" : "selected"} PR #${pr.number} (${pr.html_url}) at ${pr.head.sha}; post-publication association/identity verification is unresolved.${reconcileReference ? ` Reference removal ${removalState}.` : ""} Reconcile this PR read-only; do not create again. ${error instanceof Error ? error.message : "Unknown failure"}`
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
return {
|
|
1354
|
+
prNumber: pr.number,
|
|
1355
|
+
url: pr.html_url,
|
|
1356
|
+
headSha: pr.head.sha,
|
|
1357
|
+
state: pr.draft ? "draft" : pr.state,
|
|
1358
|
+
...closingRepair ? { closingLinkAdded: true } : {},
|
|
1359
|
+
...nonClosing ? { nonClosing: true, nonClosingVerified: true } : {},
|
|
1360
|
+
...reconcileReference ? { referenceRemoval: removalState } : {},
|
|
1361
|
+
...warnings.length ? { warnings } : {}
|
|
1362
|
+
};
|
|
1206
1363
|
}
|
|
1207
|
-
async function
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1364
|
+
async function submitFormalReview(context, input) {
|
|
1365
|
+
const nonClosing = nonClosingMode(input.nonClosing);
|
|
1366
|
+
const pr = await verifyIssuePr(context, input.issueNumber, input.prNumber, nonClosing, true);
|
|
1367
|
+
const issue = nonClosing ? await openReferenceIssue(context, input.issueNumber) : void 0;
|
|
1368
|
+
const result = await submitReview({
|
|
1369
|
+
context,
|
|
1370
|
+
artifact: parseReviewArtifact(input.artifact),
|
|
1371
|
+
issueNumber: input.issueNumber,
|
|
1372
|
+
prNumber: input.prNumber,
|
|
1373
|
+
...input.dryRun === void 0 ? {} : { dryRun: input.dryRun }
|
|
1374
|
+
});
|
|
1375
|
+
try {
|
|
1376
|
+
if (nonClosing) {
|
|
1377
|
+
sameReferencePr(pr, await verifyIssuePr(context, input.issueNumber, input.prNumber, true, true));
|
|
1378
|
+
sameReferenceIssue(issue, await openReferenceIssue(context, input.issueNumber));
|
|
1379
|
+
}
|
|
1380
|
+
if ("dryRun" in result) return result;
|
|
1381
|
+
return {
|
|
1382
|
+
...result,
|
|
1383
|
+
requiredReview: await readRequiredReviewState(context, input.prNumber, result.headSha, {
|
|
1384
|
+
id: result.githubReviewId,
|
|
1385
|
+
login: result.login,
|
|
1386
|
+
state: result.state
|
|
1387
|
+
})
|
|
1388
|
+
};
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
if ("dryRun" in result) throw error;
|
|
1391
|
+
throw new ReviewSubmissionError(
|
|
1392
|
+
error instanceof DeliveryError ? error.message : "Post-submission status is unavailable.",
|
|
1393
|
+
{
|
|
1394
|
+
artifactId: result.artifact.artifactId,
|
|
1395
|
+
repository: result.repository,
|
|
1396
|
+
headSha: result.headSha,
|
|
1397
|
+
prNumber: result.prNumber,
|
|
1398
|
+
githubReviewId: result.githubReviewId,
|
|
1399
|
+
githubReviewUrl: result.githubReviewUrl
|
|
1400
|
+
}
|
|
1401
|
+
);
|
|
1402
|
+
}
|
|
1233
1403
|
}
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1404
|
+
async function mergePr(context, input, queue) {
|
|
1405
|
+
const nonClosing = nonClosingMode(input.nonClosing);
|
|
1406
|
+
if (nonClosing && input.strategy !== void 0 && input.strategy !== "squash")
|
|
1407
|
+
throw new DeliveryError("Non-closing merge requires squash with explicit safe messages.");
|
|
1408
|
+
if (context.clients.role !== "author" || context.clients.authSource !== (context.config.roles.author.authSource ?? "app") || !context.clients.authenticatedAuthor)
|
|
1409
|
+
throw new DeliveryError("Merge and finish require the configured authenticated author role.");
|
|
1410
|
+
const author = await context.clients.authenticatedAuthor();
|
|
1411
|
+
if (!author.actorLogin || !author.credentialIdentity)
|
|
1412
|
+
throw new DeliveryError("Author identity readback is incomplete.");
|
|
1413
|
+
let pr = await verifyIssuePr(context, input.issueNumber, input.prNumber, nonClosing);
|
|
1414
|
+
const initialPr = pr;
|
|
1415
|
+
const issue = nonClosing ? await openReferenceIssue(context, input.issueNumber) : void 0;
|
|
1416
|
+
if (input.reviewedHeadSha !== void 0 && input.reviewedHeadSha !== pr.head.sha)
|
|
1417
|
+
throw new DeliveryError("Requested reviewed head differs from the GitHub PR.");
|
|
1418
|
+
if (pr.merged && pr.state === "closed" && validSha(pr.merge_commit_sha))
|
|
1419
|
+
return { mergeSha: pr.merge_commit_sha, headSha: pr.head.sha, reused: true };
|
|
1420
|
+
if (pr.state !== "open" || pr.draft) throw new DeliveryError("GitHub PR must be open and ready for merge.");
|
|
1421
|
+
if (pr.user.login.toLowerCase() !== author.actorLogin.toLowerCase())
|
|
1422
|
+
throw new DeliveryError("Merge requires the configured PR author.");
|
|
1423
|
+
const squash = (input.strategy ?? "squash") === "squash" ? {
|
|
1424
|
+
commit_title: pr.title,
|
|
1425
|
+
commit_message: deliverySquashMessage(
|
|
1426
|
+
nonClosing ? `${referenceLine(context, input.issueNumber)}
|
|
1427
|
+
|
|
1428
|
+
Delivered by PR #${pr.number}.` : pr.body || `Closes #${input.issueNumber}`
|
|
1429
|
+
)
|
|
1430
|
+
} : void 0;
|
|
1431
|
+
if (nonClosing) {
|
|
1432
|
+
refuseClosingDirective(squash.commit_title);
|
|
1433
|
+
refuseClosingDirective(squash.commit_message);
|
|
1434
|
+
}
|
|
1435
|
+
const reviewedHead = pr.head.sha;
|
|
1436
|
+
const blockers = await getNativeBlockerRelationships({
|
|
1437
|
+
graphql: context.clients.graphql,
|
|
1438
|
+
issueNumber: input.issueNumber,
|
|
1439
|
+
repo: context.repo
|
|
1440
|
+
});
|
|
1441
|
+
if (blockers.blockers.some((value) => value.state === "OPEN"))
|
|
1442
|
+
throw new DeliveryError("GitHub issue has unresolved native blockers.");
|
|
1443
|
+
pr = await verifyIssuePr(context, input.issueNumber, input.prNumber, nonClosing);
|
|
1444
|
+
if (nonClosing) {
|
|
1445
|
+
sameReferencePr(initialPr, pr);
|
|
1446
|
+
sameReferenceIssue(issue, await openReferenceIssue(context, input.issueNumber));
|
|
1447
|
+
refuseClosingDirective(squash.commit_title);
|
|
1448
|
+
refuseClosingDirective(squash.commit_message);
|
|
1449
|
+
}
|
|
1450
|
+
const decision = await readRequiredReviewState(context, input.prNumber, reviewedHead);
|
|
1451
|
+
pr = await verifyIssuePr(context, input.issueNumber, input.prNumber, nonClosing);
|
|
1452
|
+
if (nonClosing) {
|
|
1453
|
+
sameReferencePr(initialPr, pr);
|
|
1454
|
+
sameReferenceIssue(issue, await openReferenceIssue(context, input.issueNumber));
|
|
1455
|
+
}
|
|
1456
|
+
if (squash && (pr.title !== initialPr.title || pr.body !== initialPr.body))
|
|
1457
|
+
throw new DeliveryError("GitHub PR message changed; refresh squash delivery before merge.");
|
|
1458
|
+
if (pr.head.sha !== reviewedHead || pr.base.ref !== initialPr.base.ref || pr.base.sha !== initialPr.base.sha)
|
|
1459
|
+
throw new DeliveryError("GitHub head/base changed; refresh native merge eligibility.");
|
|
1460
|
+
if (pr.state !== "open" || pr.draft || pr.mergeable !== true || !["clean", "has_hooks", "unstable"].includes(pr.mergeable_state ?? "") || !decision.observed || decision.reviewDecision !== "APPROVED" && decision.reviewDecision !== null) {
|
|
1461
|
+
const requirements = await readRequiredCheckNames(context, pr.base.ref);
|
|
1462
|
+
throw new DeliveryError(
|
|
1463
|
+
`GitHub merge eligibility is ${pr.mergeable_state ?? "unknown"}; review eligibility is ${decision.status}. Required checks: ${requirements.names.join(", ") || (requirements.complete ? "none" : "unknown")}; requirement discovery is ${requirements.complete ? "complete" : "partial"}. ${decision.nextAction}`
|
|
1464
|
+
);
|
|
1465
|
+
}
|
|
1466
|
+
const currentBase = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${pr.base.ref}` })).data.object.sha;
|
|
1467
|
+
if (!validSha(currentBase) || currentBase !== pr.base.sha || queue && currentBase !== queue.expectedBase)
|
|
1468
|
+
throw new DeliveryError("GitHub base moved; refresh native merge eligibility before merge.");
|
|
1469
|
+
if (input.dryRun)
|
|
1470
|
+
return {
|
|
1471
|
+
dryRun: true,
|
|
1472
|
+
headSha: reviewedHead,
|
|
1473
|
+
prNumber: pr.number,
|
|
1474
|
+
...nonClosing ? { nonClosing: true } : {},
|
|
1475
|
+
...squash
|
|
1476
|
+
};
|
|
1477
|
+
if (queue) {
|
|
1478
|
+
await queue.checkProof();
|
|
1479
|
+
const finalBase = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${pr.base.ref}` })).data.object.sha;
|
|
1480
|
+
if (finalBase !== queue.expectedBase)
|
|
1481
|
+
throw new DeliveryError("GitHub base moved after queue proof; merge was not sent.");
|
|
1482
|
+
await queue.beforeMutation();
|
|
1483
|
+
}
|
|
1484
|
+
const result = (await context.clients.rest.pulls.merge({
|
|
1485
|
+
...context.repo,
|
|
1486
|
+
pull_number: input.prNumber,
|
|
1487
|
+
sha: reviewedHead,
|
|
1488
|
+
merge_method: input.strategy ?? "squash",
|
|
1489
|
+
...squash
|
|
1490
|
+
})).data;
|
|
1491
|
+
if (!result.merged || !validSha(result.sha)) throw new DeliveryError("GitHub refused the reviewed-head merge.");
|
|
1492
|
+
const readback = await verifyIssuePr(context, input.issueNumber, input.prNumber, nonClosing);
|
|
1493
|
+
if (nonClosing) {
|
|
1494
|
+
sameReferencePr(initialPr, readback, true);
|
|
1495
|
+
sameReferenceIssue(issue, await openReferenceIssue(context, input.issueNumber));
|
|
1496
|
+
}
|
|
1497
|
+
if (!readback.merged || readback.state !== "closed" || readback.head.sha !== reviewedHead || readback.merge_commit_sha !== result.sha)
|
|
1498
|
+
throw new DeliveryError("GitHub merged PR readback disagrees with the reviewed-head mutation.");
|
|
1499
|
+
return { mergeSha: result.sha, headSha: reviewedHead, reused: false };
|
|
1247
1500
|
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1501
|
+
async function finishIssue(context, input) {
|
|
1502
|
+
if (nonClosingMode(input.nonClosing))
|
|
1503
|
+
throw new DeliveryError("Non-closing delivery cannot finish or close its retained issue.");
|
|
1504
|
+
const result = await mergePr(context, input);
|
|
1505
|
+
if (input.dryRun) return result;
|
|
1506
|
+
const pr = await verifyIssuePr(context, input.issueNumber, input.prNumber);
|
|
1507
|
+
if (!pr.merged || pr.state !== "closed" || pr.merge_commit_sha !== result.mergeSha)
|
|
1508
|
+
throw new DeliveryError("Intended GitHub PR is not verifiably merged; issue remains open.");
|
|
1509
|
+
const issue = (await context.clients.rest.issues.get({ ...context.repo, issue_number: input.issueNumber })).data;
|
|
1510
|
+
if (issue.number !== input.issueNumber || "pull_request" in issue)
|
|
1511
|
+
throw new DeliveryError("Finish target is not the intended GitHub issue.");
|
|
1512
|
+
if (issue.state !== "closed")
|
|
1513
|
+
await context.clients.rest.issues.update({
|
|
1514
|
+
...context.repo,
|
|
1515
|
+
issue_number: input.issueNumber,
|
|
1516
|
+
state: "closed",
|
|
1517
|
+
state_reason: "completed"
|
|
1255
1518
|
});
|
|
1519
|
+
const readback = (await context.clients.rest.issues.get({ ...context.repo, issue_number: input.issueNumber })).data;
|
|
1520
|
+
if (readback.number !== input.issueNumber || readback.state !== "closed")
|
|
1521
|
+
throw new DeliveryError("GitHub issue closure readback disagrees.");
|
|
1522
|
+
return {
|
|
1523
|
+
...result,
|
|
1524
|
+
issueClosed: true,
|
|
1525
|
+
cleanup: await cleanupFinishedIssue(context, input.issueNumber, pr, result.headSha, result.mergeSha)
|
|
1526
|
+
};
|
|
1256
1527
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
const root =
|
|
1262
|
-
const
|
|
1263
|
-
if (
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
const
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1528
|
+
async function cleanupFinishedIssue(context, issueNumber, pr, headSha, mergeSha) {
|
|
1529
|
+
if (!context.root || !existsSync(context.root))
|
|
1530
|
+
return { status: "absent", reason: "No local checkout selected; no registered source was removed." };
|
|
1531
|
+
try {
|
|
1532
|
+
const root = primaryGitRoot(context.root);
|
|
1533
|
+
const repo = resolveRepoFromRemote(root, "origin");
|
|
1534
|
+
if (`${repo.owner}/${repo.repo}`.toLowerCase() !== context.config.repository.toLowerCase())
|
|
1535
|
+
throw new DeliveryError("Local repository differs from the finished repository; preserve its source.");
|
|
1536
|
+
const matches = listWorktreesStrict(root).filter((row2) => row2.type === "issue" && row2.issueNumber === issueNumber);
|
|
1537
|
+
if (matches.length === 0)
|
|
1538
|
+
return { status: "absent", reason: "No registered issue worktree exists; host-owned source was not adopted." };
|
|
1539
|
+
const row = getIssueWorktreeStrict(issueNumber, root);
|
|
1540
|
+
const authorIdentity = context.config.roles.author.identity;
|
|
1541
|
+
if (row.identity !== authorIdentity || row.prNumber !== void 0 && row.prNumber !== pr.number)
|
|
1542
|
+
throw new DeliveryError("Registered owner or PR differs from the finished delivery; preserve the source.");
|
|
1543
|
+
let attestation;
|
|
1544
|
+
const branchPresent = gitExitCode(root, "show-ref", "--verify", "--quiet", `refs/heads/${row.branch}`) === 0;
|
|
1545
|
+
if (branchPresent && gitExitCode(root, "merge-base", "--is-ancestor", row.branch, defaultBaseRef(root)) !== 0) {
|
|
1546
|
+
if (gitExitCode(root, "cat-file", "-e", `${mergeSha}^{commit}`) !== 0)
|
|
1547
|
+
throw new DeliveryError(
|
|
1548
|
+
"Merged source retention is unavailable locally; fetch the verified base before cleanup."
|
|
1549
|
+
);
|
|
1550
|
+
const mergeTree = git(root, "rev-parse", `${mergeSha}^{tree}`);
|
|
1551
|
+
if (mergeTree !== git(root, "rev-parse", `${row.branch}^{tree}`))
|
|
1552
|
+
throw new DeliveryError("Merged tree does not retain the source tree; preserve its commits.");
|
|
1553
|
+
const base = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${pr.base.ref}` })).data;
|
|
1554
|
+
let remoteHeadSha;
|
|
1555
|
+
try {
|
|
1556
|
+
remoteHeadSha = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${row.branch}` })).data.object.sha;
|
|
1557
|
+
} catch (error) {
|
|
1558
|
+
if (error.status !== 404) throw error;
|
|
1559
|
+
remoteHeadSha = null;
|
|
1560
|
+
}
|
|
1561
|
+
attestation = {
|
|
1562
|
+
baseBranch: pr.base.ref,
|
|
1563
|
+
baseSha: pr.base.sha,
|
|
1564
|
+
headBranch: pr.head.ref,
|
|
1565
|
+
headSha,
|
|
1566
|
+
mergeSha,
|
|
1567
|
+
mergeTree,
|
|
1568
|
+
remoteBaseSha: base.object.sha,
|
|
1569
|
+
remoteHeadSha,
|
|
1570
|
+
strategy: "squash"
|
|
1571
|
+
};
|
|
1281
1572
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
reviewerActor: actors.reviewerActor,
|
|
1300
|
-
};
|
|
1301
|
-
const preparation = InvestigationPreparationSchema.parse({ ...content, preparationId: digestValue(content) });
|
|
1302
|
-
await withInvestigationExclusion(root, target, () => registerInvestigationCustody(preparation, async () => {
|
|
1303
|
-
if (stableJson(investigationSourceIdentity(root, input.issueNumber)) !== stableJson(observed))
|
|
1304
|
-
throw new DeliveryError('Investigation source changed before preparation acknowledgement.');
|
|
1305
|
-
await investigationNativeSource(context, input.issueNumber, observed.head.sha, 'open');
|
|
1306
|
-
const { commentId, url, body } = await commentIssue(context, {
|
|
1307
|
-
issueNumber: input.issueNumber,
|
|
1308
|
-
body: investigationPreparationBody(preparation),
|
|
1309
|
-
});
|
|
1310
|
-
if (stableJson(investigationSourceIdentity(root, input.issueNumber)) !== stableJson(observed))
|
|
1311
|
-
throw new DeliveryError('Investigation source changed during preparation acknowledgement.');
|
|
1312
|
-
return { commentId, url, body };
|
|
1313
|
-
}));
|
|
1314
|
-
return { preparation, acknowledgement: readInvestigationAcknowledgement(root, input.issueNumber), registered: true };
|
|
1315
|
-
}
|
|
1316
|
-
/** One non-mergeable completion path. No PR, issue close, reviewer submission or branch deletion occurs. */
|
|
1317
|
-
export async function finishInvestigation(context, input) {
|
|
1318
|
-
if (['prNumber', 'strategy', 'reviewedHeadSha', 'nonClosing'].some((key) => key in input))
|
|
1319
|
-
throw new DeliveryError('Investigation completion refuses PR or merge options.');
|
|
1320
|
-
const root = investigationRoot(context);
|
|
1321
|
-
const preparation = readInvestigationPreparation(root, input.issueNumber);
|
|
1322
|
-
if (!preparation)
|
|
1323
|
-
throw new DeliveryError('No prospective investigation preparation; historical custody cannot be reconstructed.');
|
|
1324
|
-
const resultPath = resolve(input.resultPath);
|
|
1325
|
-
const resultRelative = relative(preparation.row.path, resultPath);
|
|
1326
|
-
const resultOutside = resultRelative === '..' || resultRelative.startsWith(`..${sep}`) || isAbsolute(resultRelative);
|
|
1327
|
-
if (realpathSync(resultPath) !== resultPath || !resultOutside)
|
|
1328
|
-
throw new DeliveryError('Durable investigation result must be canonical and outside the removable worktree.');
|
|
1329
|
-
const result = assertPrivateFile(resultPath, { maxBytes: 512 * 1024 });
|
|
1330
|
-
if (result.length === 0)
|
|
1331
|
-
throw new DeliveryError('Investigation result must contain durable evidence.');
|
|
1332
|
-
const resultDigest = digestBytes(result);
|
|
1333
|
-
const authorityBody = investigationAuthorityBody(preparation, resultDigest);
|
|
1334
|
-
const acceptanceBody = input.authorityCommentId === undefined
|
|
1335
|
-
? undefined
|
|
1336
|
-
: investigationAcceptanceBody(preparation, resultDigest, input.authorityCommentId);
|
|
1337
|
-
const authorize = async () => {
|
|
1338
|
-
await investigationNativeSource(context, input.issueNumber, preparation.head.sha, 'closed');
|
|
1339
|
-
const closure = await readIssueClosure(context, input.issueNumber);
|
|
1340
|
-
if (closure.state !== 'closed' || closure.closeReason !== 'completed' || closure.duplicateOf !== null)
|
|
1341
|
-
throw new DeliveryError('Investigation requires native completed closed-issue authority.');
|
|
1342
|
-
const acknowledgement = readInvestigationAcknowledgement(root, input.issueNumber);
|
|
1343
|
-
const native = (await context.clients.rest.issues.getComment({ ...context.repo, comment_id: acknowledgement.commentId })).data;
|
|
1344
|
-
if (native.id !== acknowledgement.commentId ||
|
|
1345
|
-
native.body !== investigationPreparationBody(preparation) ||
|
|
1346
|
-
native.body !== acknowledgement.body ||
|
|
1347
|
-
native.issue_url.toLowerCase() !==
|
|
1348
|
-
`https://api.github.com/repos/${preparation.repository}/issues/${String(input.issueNumber)}`.toLowerCase() ||
|
|
1349
|
-
native.user?.type !== 'User' ||
|
|
1350
|
-
native.user.login.toLowerCase() !== preparation.operator.actorLogin.toLowerCase() ||
|
|
1351
|
-
`user:${String(native.user.id)}` !== preparation.operator.credentialIdentity)
|
|
1352
|
-
throw new DeliveryError('Native prospective preparation acknowledgement changed.');
|
|
1353
|
-
if (input.authorityCommentId === undefined ||
|
|
1354
|
-
input.acceptanceCommentId === undefined ||
|
|
1355
|
-
acceptanceBody === undefined)
|
|
1356
|
-
throw new DeliveryError('Existing authentic operator and independent App acceptance comments are required.');
|
|
1357
|
-
const authority = await assertNativeWorktreeAcceptance(context, {
|
|
1358
|
-
repository: preparation.repository,
|
|
1359
|
-
subject: input.issueNumber,
|
|
1360
|
-
operator: preparation.operator,
|
|
1361
|
-
reviewerActor: preparation.reviewerActor,
|
|
1362
|
-
authorityCommentId: input.authorityCommentId,
|
|
1363
|
-
acceptanceCommentId: input.acceptanceCommentId,
|
|
1364
|
-
operatorBody: authorityBody,
|
|
1365
|
-
reviewerBody: acceptanceBody,
|
|
1366
|
-
revokedBody: stableJson({
|
|
1367
|
-
schemaVersion: 'ai-delivery.investigation-removal-revocation@1',
|
|
1368
|
-
preparationId: preparation.preparationId,
|
|
1369
|
-
resultDigest,
|
|
1370
|
-
authorityCommentId: input.authorityCommentId,
|
|
1371
|
-
}),
|
|
1372
|
-
});
|
|
1373
|
-
const preparedAt = Date.parse(native.created_at);
|
|
1374
|
-
for (const value of [authority.relinquishment, authority.acceptance]) {
|
|
1375
|
-
const createdAt = Date.parse(value.created_at);
|
|
1376
|
-
if (!Number.isFinite(preparedAt) || !Number.isFinite(createdAt) || createdAt < preparedAt)
|
|
1377
|
-
throw new DeliveryError('Investigation acceptance must follow its prospective preparation.');
|
|
1378
|
-
}
|
|
1379
|
-
return { acknowledgement: native, closure, ...authority };
|
|
1573
|
+
await reconcileCompletedIssueWorktreeDelivery({
|
|
1574
|
+
projectRoot: root,
|
|
1575
|
+
issueNumber,
|
|
1576
|
+
path: row.path,
|
|
1577
|
+
branch: row.branch,
|
|
1578
|
+
prNumber: pr.number,
|
|
1579
|
+
removeSource: (current) => {
|
|
1580
|
+
if (current.identity !== authorIdentity || current.createdAt !== row.createdAt)
|
|
1581
|
+
throw new DeliveryError("Registered source ownership changed; preserve the new owner before cleanup.");
|
|
1582
|
+
removeFinishedIssueSource(current, root, headSha, attestation);
|
|
1583
|
+
}
|
|
1584
|
+
});
|
|
1585
|
+
return { status: "removed" };
|
|
1586
|
+
} catch (error) {
|
|
1587
|
+
return {
|
|
1588
|
+
status: "retained",
|
|
1589
|
+
reason: error instanceof DeliveryError ? error.message : "Cleanup could not prove safe source removal; preserve the worktree and inspect its retention."
|
|
1380
1590
|
};
|
|
1381
|
-
|
|
1382
|
-
assertInvestigationSource(preparation, context.root);
|
|
1383
|
-
await investigationNativeSource(context, input.issueNumber, preparation.head.sha, 'closed');
|
|
1384
|
-
return {
|
|
1385
|
-
completed: false,
|
|
1386
|
-
ready: false,
|
|
1387
|
-
preparationId: preparation.preparationId,
|
|
1388
|
-
resultDigest,
|
|
1389
|
-
authorityBody,
|
|
1390
|
-
...(acceptanceBody === undefined ? {} : { acceptanceBody }),
|
|
1391
|
-
missingEvidence: 'Existing authentic operator and configured-App exact-result acceptance are prerequisites; no submission route is supplied.',
|
|
1392
|
-
};
|
|
1393
|
-
}
|
|
1394
|
-
if (!Number.isSafeInteger(input.authorityCommentId) ||
|
|
1395
|
-
!Number.isSafeInteger(input.acceptanceCommentId) ||
|
|
1396
|
-
input.authorityCommentId <= 0 ||
|
|
1397
|
-
input.acceptanceCommentId <= 0)
|
|
1398
|
-
throw new DeliveryError('Investigation evidence requires positive native comment IDs.');
|
|
1399
|
-
return withInvestigationExclusion(root, preparation.row.path, () => completeInvestigationCustody({
|
|
1400
|
-
preparation,
|
|
1401
|
-
result,
|
|
1402
|
-
authorityCommentId: input.authorityCommentId,
|
|
1403
|
-
acceptanceCommentId: input.acceptanceCommentId,
|
|
1404
|
-
dryRun: input.dryRun === true,
|
|
1405
|
-
authorize,
|
|
1406
|
-
assertSource: (allowAbsent) => assertInvestigationSource(preparation, context.root, allowAbsent),
|
|
1407
|
-
removeSource: () => removeInvestigationSource(preparation, context.root),
|
|
1408
|
-
}));
|
|
1591
|
+
}
|
|
1409
1592
|
}
|
|
1410
|
-
|
|
1593
|
+
export {
|
|
1594
|
+
finishIssue,
|
|
1595
|
+
hasDeliveryMergeTrailer,
|
|
1596
|
+
hasDeliveryPrMarker,
|
|
1597
|
+
listPrs,
|
|
1598
|
+
mergePr,
|
|
1599
|
+
prChecks,
|
|
1600
|
+
prInfo,
|
|
1601
|
+
preflightReviewRoute,
|
|
1602
|
+
publishPr,
|
|
1603
|
+
queueChecks,
|
|
1604
|
+
readPrBoardFacts,
|
|
1605
|
+
startIssueBranch,
|
|
1606
|
+
submitFormalReview
|
|
1607
|
+
};
|
|
1608
|
+
//# sourceMappingURL=pr.js.map
|