@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/github/client.js
CHANGED
|
@@ -1,420 +1,525 @@
|
|
|
1
|
-
import { createAppAuth } from
|
|
2
|
-
import { graphql } from
|
|
3
|
-
import { Octokit } from
|
|
4
|
-
import { readFileSync } from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import { createAppAuth } from "@octokit/auth-app";
|
|
2
|
+
import { graphql } from "@octokit/graphql";
|
|
3
|
+
import { Octokit } from "@octokit/rest";
|
|
4
|
+
import { closeSync, constants, fstatSync, openSync, readFileSync, readSync } from "node:fs";
|
|
5
|
+
import { createPrivateKey } from "node:crypto";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { types } from "node:util";
|
|
8
|
+
import {
|
|
9
|
+
appCredentialSource,
|
|
10
|
+
privateKeyVariable,
|
|
11
|
+
resolveDeliveryRoleCredentials
|
|
12
|
+
} from "../config/deliveryConfig.js";
|
|
13
|
+
import { runStageCommand } from "../verification.js";
|
|
14
|
+
import {
|
|
15
|
+
DeliveryError,
|
|
16
|
+
setMachineRequestDiagnostics,
|
|
17
|
+
getRateLimitDiagnostics
|
|
18
|
+
} from "../errors.js";
|
|
19
|
+
import {
|
|
20
|
+
assertSupportedAuthorHost,
|
|
21
|
+
machineAuthorEligible,
|
|
22
|
+
withMachineAuthorCredential,
|
|
23
|
+
MACHINE_AUTH_ENV_NAMES
|
|
24
|
+
} from "./machineAuth.js";
|
|
25
|
+
const authorGitTokens = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
const machineClients = /* @__PURE__ */ new WeakSet();
|
|
27
|
+
const machineProtectionAbsence = /* @__PURE__ */ new WeakMap();
|
|
28
|
+
const machineAuthorSelections = /* @__PURE__ */ new WeakMap();
|
|
29
|
+
const resolvedMachineAuthors = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
function retainMachineAuthorForConfiguration(config, clients, signal) {
|
|
31
|
+
const selection = machineAuthorSelections.get(clients);
|
|
32
|
+
if (selection !== void 0) {
|
|
33
|
+
if (selection.signal !== signal)
|
|
34
|
+
throw new DeliveryError("Machine GitHub session command context changed; resolve the command again.");
|
|
35
|
+
resolvedMachineAuthors.set(config.roles, { clients, ...selection });
|
|
36
|
+
}
|
|
22
37
|
}
|
|
23
38
|
function sessionSelectors(env) {
|
|
24
|
-
|
|
39
|
+
return JSON.stringify(MACHINE_AUTH_ENV_NAMES.map((name) => [name, env[name]]));
|
|
25
40
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
throw new DeliveryError('Git push requires the selected author credential token.');
|
|
31
|
-
return callback(token);
|
|
41
|
+
async function withAuthorGitToken(clients, callback) {
|
|
42
|
+
const token = clients.role === "author" ? authorGitTokens.get(clients) : void 0;
|
|
43
|
+
if (!token) throw new DeliveryError("Git push requires the selected author credential token.");
|
|
44
|
+
return callback(token);
|
|
32
45
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (actual !== 'admin' && actual !== 'write' && (level === 'write' || actual !== 'read')) {
|
|
44
|
-
throw new DeliveryError(`GitHub App ${input.role} role lacks required ${name}:${level} permission.`);
|
|
45
|
-
}
|
|
46
|
+
function assertDeliveryRolePermissions(input) {
|
|
47
|
+
if (typeof input.permissions !== "object" || input.permissions === null || Array.isArray(input.permissions)) {
|
|
48
|
+
throw new DeliveryError(`GitHub App ${input.role} role did not return installation permissions.`);
|
|
49
|
+
}
|
|
50
|
+
const permissions = input.permissions;
|
|
51
|
+
const required = input.role === "author" ? { contents: "write", issues: "write", organization_projects: "write", pull_requests: "write" } : { contents: "read", pull_requests: "write" };
|
|
52
|
+
for (const [name, level] of [...Object.entries(required), ...Object.entries(input.additional ?? {})]) {
|
|
53
|
+
const actual = permissions[name];
|
|
54
|
+
if (actual !== "admin" && actual !== "write" && (level === "write" || actual !== "read")) {
|
|
55
|
+
throw new DeliveryError(`GitHub App ${input.role} role lacks required ${name}:${level} permission.`);
|
|
46
56
|
}
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (retained !==
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
assertSupportedAuthorHost(env);
|
|
65
|
-
return retained.clients;
|
|
59
|
+
async function createDeliveryGitHubClients(input) {
|
|
60
|
+
input.signal?.throwIfAborted();
|
|
61
|
+
const env = input.env ?? process.env;
|
|
62
|
+
const selected = input.config.roles[input.role];
|
|
63
|
+
const retained = input.role === "author" ? resolvedMachineAuthors.get(input.config.roles) : void 0;
|
|
64
|
+
if (retained !== void 0) {
|
|
65
|
+
if (selected.authSource !== "personal" || input.identity.trim().toLowerCase() !== selected.identity.toLowerCase() || !machineAuthorEligible(selected.credentialEnv.token, env) || retained.env !== env || retained.signal !== input.signal || retained.selectors !== sessionSelectors(env))
|
|
66
|
+
throw new DeliveryError(
|
|
67
|
+
"Machine GitHub session environment changed after repository selection; resolve the command again."
|
|
68
|
+
);
|
|
69
|
+
assertSupportedAuthorHost(env);
|
|
70
|
+
return retained.clients;
|
|
71
|
+
}
|
|
72
|
+
if (selected.authSource === "personal") {
|
|
73
|
+
if (input.role !== "author" || input.identity.trim().toLowerCase() !== selected.identity.toLowerCase()) {
|
|
74
|
+
throw new DeliveryError("Personal author operation requires the configured author identity.");
|
|
66
75
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
await clients.authenticatedAuthor(input.signal);
|
|
77
|
-
machineAuthorSelections.set(clients, selection);
|
|
78
|
-
return clients;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
const token = env[selected.credentialEnv.token]?.trim();
|
|
82
|
-
if (!token) {
|
|
83
|
-
throw new DeliveryError(`Missing personal author token in ${selected.credentialEnv.token}.`);
|
|
84
|
-
}
|
|
85
|
-
return personalClients(token, `env:${selected.credentialEnv.token}`, input.signal);
|
|
76
|
+
assertSupportedAuthorHost(env);
|
|
77
|
+
if (machineAuthorEligible(selected.credentialEnv.token, env)) {
|
|
78
|
+
const selection = { env, signal: input.signal, selectors: sessionSelectors(env) };
|
|
79
|
+
return withMachineAuthorCredential(env, input.signal, async (token2, session) => {
|
|
80
|
+
const clients = personalClients(token2, `gh:github.com:${session.executable}`, input.signal, session.login);
|
|
81
|
+
await clients.authenticatedAuthor(input.signal);
|
|
82
|
+
machineAuthorSelections.set(clients, selection);
|
|
83
|
+
return clients;
|
|
84
|
+
});
|
|
86
85
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
input.identity.trim().toLowerCase() !== 'personal') {
|
|
91
|
-
throw new DeliveryError('Personal-token auth requires the explicit personal author identity.');
|
|
92
|
-
}
|
|
93
|
-
assertSupportedAuthorHost(env);
|
|
94
|
-
const token = (input.personalAuth.token ?? env.GH_TOKEN ?? env.GITHUB_TOKEN)?.trim();
|
|
95
|
-
if (!token)
|
|
96
|
-
throw new DeliveryError('Explicit personal-token auth requested but no token was supplied.');
|
|
97
|
-
const source = input.personalAuth.token !== undefined
|
|
98
|
-
? 'explicit-personal-token'
|
|
99
|
-
: env.GH_TOKEN !== undefined
|
|
100
|
-
? 'env:GH_TOKEN'
|
|
101
|
-
: 'env:GITHUB_TOKEN';
|
|
102
|
-
return personalClients(token, source, input.signal);
|
|
86
|
+
const token = env[selected.credentialEnv.token]?.trim();
|
|
87
|
+
if (!token) {
|
|
88
|
+
throw new DeliveryError(`Missing personal author token in ${selected.credentialEnv.token}.`);
|
|
103
89
|
}
|
|
104
|
-
|
|
105
|
-
|
|
90
|
+
return personalClients(token, `env:${selected.credentialEnv.token}`, input.signal);
|
|
91
|
+
}
|
|
92
|
+
if (input.personalAuth !== void 0) {
|
|
93
|
+
if (input.personalAuth.enabled !== true || input.role !== "author" || input.identity.trim().toLowerCase() !== "personal") {
|
|
94
|
+
throw new DeliveryError("Personal-token auth requires the explicit personal author identity.");
|
|
106
95
|
}
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
96
|
+
assertSupportedAuthorHost(env);
|
|
97
|
+
const token = (input.personalAuth.token ?? env.GH_TOKEN ?? env.GITHUB_TOKEN)?.trim();
|
|
98
|
+
if (!token) throw new DeliveryError("Explicit personal-token auth requested but no token was supplied.");
|
|
99
|
+
const source = input.personalAuth.token !== void 0 ? "explicit-personal-token" : env.GH_TOKEN !== void 0 ? "env:GH_TOKEN" : "env:GITHUB_TOKEN";
|
|
100
|
+
return personalClients(token, source, input.signal);
|
|
101
|
+
}
|
|
102
|
+
if (input.identity.trim().toLowerCase() !== selected.identity.toLowerCase()) {
|
|
103
|
+
throw new DeliveryError(`GitHub ${input.role} operation requires the configured ${input.role} identity.`);
|
|
104
|
+
}
|
|
105
|
+
const credentials = resolveDeliveryRoleCredentials({ config: input.config, env, role: input.role });
|
|
106
|
+
const otherRole = input.role === "author" ? "reviewer" : "author";
|
|
107
|
+
const personalAuthorSelected = input.role === "reviewer" && input.selectedAuthor?.role === "author" && input.selectedAuthor.authSource === "personal";
|
|
108
|
+
if (!personalAuthorSelected && input.config.roles[otherRole].authSource !== "personal") {
|
|
109
|
+
const otherRoleConfig = input.config.roles[otherRole];
|
|
110
|
+
const other = credentials.profile === void 0 ? resolveDeliveryRoleCredentials({ config: input.config, env, role: otherRole }) : "appId" in otherRoleConfig ? {
|
|
111
|
+
appId: String(otherRoleConfig.appId),
|
|
112
|
+
installationId: otherRoleConfig.installationId,
|
|
113
|
+
privateKeyPath: void 0
|
|
114
|
+
} : {
|
|
115
|
+
appId: env[otherRoleConfig.credentialEnv.appId]?.trim(),
|
|
116
|
+
installationId: Number(env[otherRoleConfig.credentialEnv.installationId]),
|
|
117
|
+
privateKeyPath: void 0
|
|
118
|
+
};
|
|
119
|
+
if (credentials.appId === other.appId || credentials.installationId === other.installationId || credentials.privateKeyPath !== void 0 && credentials.privateKeyPath === other.privateKeyPath) {
|
|
120
|
+
throw new DeliveryError("Author and reviewer must use distinct GitHub App credentials.");
|
|
119
121
|
}
|
|
120
|
-
|
|
122
|
+
}
|
|
123
|
+
let privateKey;
|
|
124
|
+
if (credentials.profile !== void 0) {
|
|
125
|
+
privateKey = await selectedPrivateKey(credentials.profile, env, input.config, input.signal);
|
|
126
|
+
} else {
|
|
121
127
|
try {
|
|
122
|
-
|
|
128
|
+
privateKey = readFileSync(credentials.privateKeyPath, "utf8");
|
|
129
|
+
} catch {
|
|
130
|
+
throw new DeliveryError(`GitHub App private key for ${input.role} role is unavailable.`);
|
|
123
131
|
}
|
|
124
|
-
|
|
125
|
-
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const auth = createAppAuth({
|
|
135
|
+
appId: credentials.appId,
|
|
136
|
+
privateKey,
|
|
137
|
+
...input.signal === void 0 ? {} : { request: new Octokit({ request: { signal: input.signal } }).request }
|
|
138
|
+
});
|
|
139
|
+
const result = await auth({ installationId: credentials.installationId, type: "installation" });
|
|
140
|
+
if (typeof result.token !== "string" || !result.token.startsWith("ghs_")) {
|
|
141
|
+
throw new DeliveryError(`GitHub ${input.role} role did not receive an App installation token.`);
|
|
126
142
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
143
|
+
assertDeliveryRolePermissions({
|
|
144
|
+
...input.additionalPermissions === void 0 ? {} : { additional: input.additionalPermissions },
|
|
145
|
+
permissions: result.permissions,
|
|
146
|
+
role: input.role
|
|
147
|
+
});
|
|
148
|
+
const appActorLogin = input.role === "reviewer" ? async (signal) => {
|
|
149
|
+
const requestSignal = signal ?? input.signal;
|
|
150
|
+
try {
|
|
151
|
+
const app = await new Octokit({
|
|
152
|
+
auth: (await auth({ type: "app" })).token,
|
|
153
|
+
...requestSignal === void 0 ? {} : { request: { signal: requestSignal } }
|
|
154
|
+
}).rest.apps.getAuthenticated();
|
|
155
|
+
if (!app.data || app.data.id !== Number(credentials.appId) || !app.data.slug) {
|
|
156
|
+
throw new DeliveryError("Reviewer GitHub App identity did not match its configured App ID.");
|
|
136
157
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
158
|
+
const actor = `${app.data.slug}[bot]`;
|
|
159
|
+
if (credentials.profile !== void 0 && actor !== credentials.profile.actorLogin)
|
|
160
|
+
throw new DeliveryError("Reviewer GitHub App actor did not match its configured actorLogin.");
|
|
161
|
+
return actor;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error instanceof DeliveryError) throw error;
|
|
164
|
+
throw new DeliveryError("Reviewer GitHub App actor lookup failed.");
|
|
165
|
+
}
|
|
166
|
+
} : void 0;
|
|
167
|
+
const authenticatedAuthor = input.role === "author" ? async (signal) => {
|
|
168
|
+
const requestSignal = signal ?? input.signal;
|
|
169
|
+
try {
|
|
170
|
+
const app = await new Octokit({
|
|
171
|
+
auth: (await auth({ type: "app" })).token,
|
|
172
|
+
...requestSignal === void 0 ? {} : { request: { signal: requestSignal } }
|
|
173
|
+
}).rest.apps.getAuthenticated();
|
|
174
|
+
if (!app.data || app.data.id !== Number(credentials.appId) || !app.data.slug) {
|
|
175
|
+
throw new DeliveryError("Author GitHub App identity did not match its configured App ID.");
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
actorLogin: `${app.data.slug}[bot]`,
|
|
179
|
+
credentialIdentity: `app:${String(app.data.id)}:installation:${credentials.installationId}`
|
|
180
|
+
};
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (error instanceof DeliveryError) throw error;
|
|
183
|
+
throw new DeliveryError("Author GitHub App actor lookup failed.");
|
|
184
|
+
}
|
|
185
|
+
} : void 0;
|
|
186
|
+
return buildClients(
|
|
187
|
+
result.token,
|
|
188
|
+
"app",
|
|
189
|
+
input.role,
|
|
190
|
+
`app:${credentials.appId}:installation:${credentials.installationId}`,
|
|
191
|
+
appActorLogin,
|
|
192
|
+
authenticatedAuthor,
|
|
193
|
+
result.permissions.contents,
|
|
194
|
+
input.signal
|
|
195
|
+
);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
input.signal?.throwIfAborted();
|
|
198
|
+
if (error instanceof DeliveryError) throw error;
|
|
199
|
+
throw new DeliveryError(`GitHub App authentication failed for ${input.role} role.`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async function selectedPrivateKey(profile, env, config, signal) {
|
|
203
|
+
const source = appCredentialSource(profile);
|
|
204
|
+
const failure = (reason) => new DeliveryError(`Reviewer ${profile.identity} credential source ${source.type}: ${reason}`);
|
|
205
|
+
let bytes;
|
|
206
|
+
try {
|
|
207
|
+
signal?.throwIfAborted();
|
|
208
|
+
if (source.type === "env") {
|
|
209
|
+
const value = env[privateKeyVariable(profile)];
|
|
210
|
+
if (!value) throw failure("selected variable is missing or empty; configure this identity.");
|
|
211
|
+
if (Buffer.byteLength(value) > 64 * 1024) throw failure("response exceeds 64 KiB.");
|
|
212
|
+
bytes = Buffer.from(value);
|
|
213
|
+
} else if (source.type === "file") {
|
|
214
|
+
const fd = openSync(source.path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
215
|
+
try {
|
|
216
|
+
const stat = fstatSync(fd);
|
|
217
|
+
if (!stat.isFile() || (stat.mode & 4095) !== 384 || stat.nlink !== 1 || process.getuid !== void 0 && stat.uid !== process.getuid())
|
|
218
|
+
throw failure("key file must be a regular, owned, single-link file with mode 0600.");
|
|
219
|
+
const buffer = Buffer.alloc(64 * 1024 + 1);
|
|
220
|
+
let size = 0;
|
|
221
|
+
for (; ; ) {
|
|
222
|
+
const read = readSync(fd, buffer, size, buffer.length - size, null);
|
|
223
|
+
if (read === 0) break;
|
|
224
|
+
size += read;
|
|
225
|
+
if (size === buffer.length) throw failure("response exceeds 64 KiB.");
|
|
226
|
+
}
|
|
227
|
+
bytes = buffer.subarray(0, size);
|
|
228
|
+
} finally {
|
|
229
|
+
closeSync(fd);
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
if (process.platform === "win32")
|
|
233
|
+
throw failure("command sources currently require a POSIX process supervisor; use env on Windows.");
|
|
234
|
+
const commandEnv = {};
|
|
235
|
+
const forbidden = /* @__PURE__ */ new Set([
|
|
236
|
+
...config.credentialKeyReferences ?? [],
|
|
237
|
+
...Object.values(config.roles).flatMap(
|
|
238
|
+
(role) => "credentialEnv" in role ? Object.values(role.credentialEnv) : appCredentialSource(role).type === "env" ? [privateKeyVariable(role)] : []
|
|
239
|
+
)
|
|
240
|
+
]);
|
|
241
|
+
for (const name of [
|
|
242
|
+
"HOME",
|
|
243
|
+
"USER",
|
|
244
|
+
"LOGNAME",
|
|
245
|
+
"PATH",
|
|
246
|
+
"LANG",
|
|
247
|
+
"LC_ALL",
|
|
248
|
+
"TMPDIR",
|
|
249
|
+
"TEMP",
|
|
250
|
+
"TMP",
|
|
251
|
+
"SystemRoot",
|
|
252
|
+
"USERPROFILE",
|
|
253
|
+
"APPDATA",
|
|
254
|
+
"LOCALAPPDATA"
|
|
255
|
+
]) {
|
|
256
|
+
if (forbidden.has(name)) throw failure("credential reference conflicts with an implicit OS selector.");
|
|
257
|
+
if (env[name] !== void 0) commandEnv[name] = env[name];
|
|
258
|
+
}
|
|
259
|
+
for (const name of source.env ?? []) {
|
|
260
|
+
if (forbidden.has(name) || /^(?:NODE_|NPM_|DYLD_|LD_|BASH_|GIT_|GH_PRIVATE_KEY)/u.test(name) || ["ENV", "SHELLOPTS", "CDPATH"].includes(name))
|
|
261
|
+
throw failure("helper environment reference conflicts with author/key or execution selectors.");
|
|
262
|
+
if (env[name] === void 0) throw failure("a configured helper environment reference is missing.");
|
|
263
|
+
commandEnv[name] = env[name];
|
|
264
|
+
}
|
|
265
|
+
const timeout = new AbortController();
|
|
266
|
+
const timer = setTimeout(() => timeout.abort(), 3e4);
|
|
267
|
+
let cleanupFailed = false;
|
|
268
|
+
try {
|
|
269
|
+
bytes = await runStageCommand(
|
|
270
|
+
env.HOME ?? homedir(),
|
|
271
|
+
source.argv,
|
|
272
|
+
signal === void 0 ? timeout.signal : AbortSignal.any([signal, timeout.signal]),
|
|
273
|
+
void 0,
|
|
274
|
+
void 0,
|
|
275
|
+
void 0,
|
|
276
|
+
void 0,
|
|
277
|
+
void 0,
|
|
278
|
+
{
|
|
279
|
+
environment: commandEnv,
|
|
280
|
+
cwd: env.HOME ?? homedir(),
|
|
281
|
+
maxCapturedOutputBytes: 64 * 1024,
|
|
282
|
+
stdoutOnly: true,
|
|
283
|
+
failedOutput: () => "",
|
|
284
|
+
onCleanupFailure: () => {
|
|
285
|
+
cleanupFailed = true;
|
|
183
286
|
}
|
|
184
|
-
|
|
185
|
-
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
} catch {
|
|
290
|
+
throw failure(
|
|
291
|
+
cleanupFailed ? "helper failed and owned process cleanup is unverified; reconcile before retrying." : timeout.signal.aborted ? "helper response timed out; verify the selected command." : signal?.aborted ? "helper request cancelled." : "helper failed; verify its executable, access and bounded output."
|
|
292
|
+
);
|
|
293
|
+
} finally {
|
|
294
|
+
clearTimeout(timer);
|
|
295
|
+
}
|
|
186
296
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
297
|
+
if (bytes.length === 0 || bytes.length > 64 * 1024) throw failure("response is empty or exceeds 64 KiB.");
|
|
298
|
+
let pem = bytes.toString("utf8");
|
|
299
|
+
if (!Buffer.from(pem).equals(bytes)) throw failure("response must be valid UTF-8.");
|
|
300
|
+
if (source.type !== "file" && source.encoding === "base64") {
|
|
301
|
+
const encoded = pem.trim();
|
|
302
|
+
if (!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u.test(encoded))
|
|
303
|
+
throw failure("response must be canonical base64.");
|
|
304
|
+
const decoded = Buffer.from(encoded, "base64");
|
|
305
|
+
if (decoded.toString("base64") !== encoded) throw failure("response must be canonical base64.");
|
|
306
|
+
pem = decoded.toString("utf8");
|
|
307
|
+
if (!Buffer.from(pem).equals(decoded)) throw failure("decoded response must be UTF-8 PEM.");
|
|
191
308
|
}
|
|
309
|
+
if (!/^-----BEGIN (?:RSA )?PRIVATE KEY-----\r?\n[\s\S]+\r?\n-----END (?:RSA )?PRIVATE KEY-----\s*$/u.test(pem) || createPrivateKey(pem).asymmetricKeyType !== "rsa")
|
|
310
|
+
throw failure("response must be an unencrypted RSA private key in PEM format.");
|
|
311
|
+
signal?.throwIfAborted();
|
|
312
|
+
return pem;
|
|
313
|
+
} catch (error) {
|
|
314
|
+
if (error instanceof DeliveryError) throw error;
|
|
315
|
+
throw failure("selected key is unavailable or malformed; verify this source.");
|
|
316
|
+
}
|
|
192
317
|
}
|
|
193
318
|
function personalClients(token, credentialSource, signal, machineLogin) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
319
|
+
if (!/^[A-Za-z0-9_-]{1,4096}$/u.test(token))
|
|
320
|
+
throw new DeliveryError("Selected personal author token is malformed; verify the explicit credential.");
|
|
321
|
+
if (machineLogin !== void 0 && (credentialSource.includes(token) || machineLogin.includes(token)))
|
|
322
|
+
throw new DeliveryError("Machine GitHub session readback is unsafe.");
|
|
323
|
+
return buildClients(
|
|
324
|
+
token,
|
|
325
|
+
"personal",
|
|
326
|
+
"author",
|
|
327
|
+
credentialSource,
|
|
328
|
+
void 0,
|
|
329
|
+
async (requestSignal) => {
|
|
330
|
+
const selectedSignal = requestSignal ?? signal;
|
|
331
|
+
try {
|
|
332
|
+
const user = (await new Octokit({
|
|
333
|
+
auth: token,
|
|
334
|
+
...machineLogin === void 0 ? {} : { log: { debug() {
|
|
335
|
+
}, info() {
|
|
336
|
+
}, warn() {
|
|
337
|
+
}, error() {
|
|
338
|
+
} } },
|
|
339
|
+
...selectedSignal === void 0 ? {} : { request: { signal: selectedSignal } }
|
|
340
|
+
}).rest.users.getAuthenticated()).data;
|
|
341
|
+
if (!Number.isSafeInteger(user.id) || user.id <= 0 || !user.login) {
|
|
342
|
+
throw new DeliveryError("Personal author identity readback is incomplete.");
|
|
216
343
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
344
|
+
if (machineLogin !== void 0 && (user.type !== "User" || user.login.toLowerCase() !== machineLogin.toLowerCase() || !/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/u.test(user.login) || user.login.includes(token)))
|
|
345
|
+
throw new DeliveryError("Machine GitHub session identity does not match the selected active account.");
|
|
346
|
+
return { actorLogin: user.login, credentialIdentity: `user:${String(user.id)}` };
|
|
347
|
+
} catch (error) {
|
|
348
|
+
if (error instanceof DeliveryError) throw error;
|
|
349
|
+
if (error.status === 401) {
|
|
350
|
+
throw new DeliveryError(
|
|
351
|
+
machineLogin === void 0 ? "Configured personal author token is invalid or expired; refresh the selected token." : "Machine GitHub session is invalid or expired; verify the selected github.com account."
|
|
352
|
+
);
|
|
226
353
|
}
|
|
227
|
-
|
|
354
|
+
throw new DeliveryError("Personal author identity readback failed.");
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
void 0,
|
|
358
|
+
signal,
|
|
359
|
+
machineLogin !== void 0
|
|
360
|
+
);
|
|
228
361
|
}
|
|
229
362
|
function buildClients(token, authSource, role, credentialSource, appActorLogin, authenticatedAuthor, effectiveContentsPermission, signal, machineSession = false) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
363
|
+
const rest = new Octokit({
|
|
364
|
+
auth: token,
|
|
365
|
+
...machineSession ? { log: { debug() {
|
|
366
|
+
}, info() {
|
|
367
|
+
}, warn() {
|
|
368
|
+
}, error() {
|
|
369
|
+
} } } : {},
|
|
370
|
+
...signal === void 0 ? {} : { request: { signal } }
|
|
371
|
+
});
|
|
372
|
+
const rawGraphql = graphql.defaults({
|
|
373
|
+
headers: { authorization: `token ${token}` },
|
|
374
|
+
...signal === void 0 ? {} : { request: { signal } }
|
|
375
|
+
});
|
|
376
|
+
let observedRateLimit;
|
|
377
|
+
const observeRateLimit = (error, graphqlFailure = false) => {
|
|
378
|
+
observedRateLimit = getRateLimitDiagnostics(error, graphqlFailure) ?? observedRateLimit;
|
|
379
|
+
};
|
|
380
|
+
rest.hook.error("request", (error) => {
|
|
381
|
+
observeRateLimit(error);
|
|
382
|
+
throw error;
|
|
383
|
+
});
|
|
384
|
+
if (machineSession)
|
|
385
|
+
rest.hook.error("request", (error, options) => {
|
|
386
|
+
const safe = safeMachineRequestError(error, "rest.request", restMachineEndpoint(options));
|
|
387
|
+
const target = branchProtectionTarget(options);
|
|
388
|
+
const responseTarget = branchProtectionTarget({ method: "GET", url: ownData(ownData(error, "response"), "url") });
|
|
389
|
+
if (target && responseTarget && target.owner.toLowerCase() === responseTarget.owner.toLowerCase() && target.repo.toLowerCase() === responseTarget.repo.toLowerCase() && target.branch === responseTarget.branch && exactBranchProtectionAbsence(error))
|
|
390
|
+
machineProtectionAbsence.set(safe, { clients, ...target });
|
|
391
|
+
throw safe;
|
|
246
392
|
});
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
throw safe;
|
|
393
|
+
const clients = {
|
|
394
|
+
authSource,
|
|
395
|
+
credentialSource,
|
|
396
|
+
...effectiveContentsPermission ? { effectiveContentsPermission } : {},
|
|
397
|
+
role,
|
|
398
|
+
...appActorLogin ? { appActorLogin } : {},
|
|
399
|
+
...authenticatedAuthor ? { authenticatedAuthor } : {},
|
|
400
|
+
graphql: new Proxy(rawGraphql, {
|
|
401
|
+
apply(target, receiver, args) {
|
|
402
|
+
return Reflect.apply(target, receiver, args).catch((error) => {
|
|
403
|
+
observeRateLimit(error, true);
|
|
404
|
+
throw machineSession ? safeMachineRequestError(error, "graphql.request", "graphql") : error;
|
|
260
405
|
});
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
apply(target, receiver, args) {
|
|
270
|
-
return Reflect.apply(target, receiver, args).catch((error) => {
|
|
271
|
-
observeRateLimit(error, true);
|
|
272
|
-
throw machineSession ? safeMachineRequestError(error, 'graphql.request', 'graphql') : error;
|
|
273
|
-
});
|
|
274
|
-
},
|
|
275
|
-
}),
|
|
276
|
-
rest,
|
|
277
|
-
rateLimitObservation: () => observedRateLimit,
|
|
278
|
-
};
|
|
279
|
-
if (machineSession)
|
|
280
|
-
machineClients.add(clients);
|
|
281
|
-
if (role === 'author')
|
|
282
|
-
authorGitTokens.set(clients, token);
|
|
283
|
-
return clients;
|
|
406
|
+
}
|
|
407
|
+
}),
|
|
408
|
+
rest,
|
|
409
|
+
rateLimitObservation: () => observedRateLimit
|
|
410
|
+
};
|
|
411
|
+
if (machineSession) machineClients.add(clients);
|
|
412
|
+
if (role === "author") authorGitTokens.set(clients, token);
|
|
413
|
+
return clients;
|
|
284
414
|
}
|
|
285
415
|
function ownData(value, name) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return descriptor && 'value' in descriptor ? descriptor.value : undefined;
|
|
416
|
+
if (typeof value !== "object" || value === null || types.isProxy(value) || Array.isArray(value)) return void 0;
|
|
417
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
418
|
+
return descriptor && "value" in descriptor ? descriptor.value : void 0;
|
|
290
419
|
}
|
|
291
420
|
function exactBranchProtectionAbsence(error) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
ownData(response, 'status') === 404 &&
|
|
295
|
-
ownData(ownData(response, 'data'), 'message') === 'Branch not protected');
|
|
421
|
+
const response = ownData(error, "response");
|
|
422
|
+
return ownData(error, "status") === 404 && ownData(response, "status") === 404 && ownData(ownData(response, "data"), "message") === "Branch not protected";
|
|
296
423
|
}
|
|
297
424
|
function branchProtectionTarget(options) {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
parsed.search ||
|
|
314
|
-
parsed.hash)
|
|
315
|
-
return undefined;
|
|
316
|
-
path = parsed.pathname;
|
|
317
|
-
}
|
|
318
|
-
catch {
|
|
319
|
-
return undefined;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
let owner, repo, branch;
|
|
323
|
-
if (path === '/repos/{owner}/{repo}/branches/{branch}/protection') {
|
|
324
|
-
owner = ownData(options, 'owner');
|
|
325
|
-
repo = ownData(options, 'repo');
|
|
326
|
-
branch = ownData(options, 'branch');
|
|
425
|
+
const url = ownData(options, "url");
|
|
426
|
+
if (ownData(options, "method") !== "GET" || typeof url !== "string" || url.length > 1024 || /[^\x21-\x7e]/u.test(url))
|
|
427
|
+
return void 0;
|
|
428
|
+
let path;
|
|
429
|
+
if (url.startsWith("/")) {
|
|
430
|
+
if (ownData(options, "baseUrl") !== "https://api.github.com" || /[?#]/u.test(url)) return void 0;
|
|
431
|
+
path = url;
|
|
432
|
+
} else {
|
|
433
|
+
try {
|
|
434
|
+
const parsed = new URL(url);
|
|
435
|
+
if (parsed.origin !== "https://api.github.com" || parsed.username || parsed.password || parsed.search || parsed.hash)
|
|
436
|
+
return void 0;
|
|
437
|
+
path = parsed.pathname;
|
|
438
|
+
} catch {
|
|
439
|
+
return void 0;
|
|
327
440
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
441
|
+
}
|
|
442
|
+
let owner, repo, branch;
|
|
443
|
+
if (path === "/repos/{owner}/{repo}/branches/{branch}/protection") {
|
|
444
|
+
owner = ownData(options, "owner");
|
|
445
|
+
repo = ownData(options, "repo");
|
|
446
|
+
branch = ownData(options, "branch");
|
|
447
|
+
} else {
|
|
448
|
+
const match = /^\/repos\/([^/]+)\/([^/]+)\/branches\/(.+)\/protection$/u.exec(path);
|
|
449
|
+
if (!match) return void 0;
|
|
450
|
+
try {
|
|
451
|
+
[owner, repo, branch] = match.slice(1).map((part) => decodeURIComponent(part));
|
|
452
|
+
} catch {
|
|
453
|
+
return void 0;
|
|
338
454
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
typeof branch !== 'string' ||
|
|
344
|
-
!branch.length ||
|
|
345
|
-
branch.length > 1024 ||
|
|
346
|
-
/[^\x21-\x7e]/u.test(branch))
|
|
347
|
-
return undefined;
|
|
348
|
-
return { owner, repo, branch };
|
|
455
|
+
}
|
|
456
|
+
if (typeof owner !== "string" || !/^[A-Za-z0-9_-]{1,100}$/u.test(owner) || typeof repo !== "string" || !/^[A-Za-z0-9_.-]{1,100}$/u.test(repo) || typeof branch !== "string" || !branch.length || branch.length > 1024 || /[^\x21-\x7e]/u.test(branch))
|
|
457
|
+
return void 0;
|
|
458
|
+
return { owner, repo, branch };
|
|
349
459
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
return false;
|
|
356
|
-
const target = machineProtectionAbsence.get(error);
|
|
357
|
-
return (target?.clients === clients &&
|
|
358
|
-
target.owner.toLowerCase() === repository.owner.toLowerCase() &&
|
|
359
|
-
target.repo.toLowerCase() === repository.repo.toLowerCase() &&
|
|
360
|
-
target.branch === branch);
|
|
460
|
+
function hasBranchProtectionAbsence(error, clients, repository, branch) {
|
|
461
|
+
if (!machineClients.has(clients)) return exactBranchProtectionAbsence(error);
|
|
462
|
+
if (typeof error !== "object" || error === null || types.isProxy(error)) return false;
|
|
463
|
+
const target = machineProtectionAbsence.get(error);
|
|
464
|
+
return target?.clients === clients && target.owner.toLowerCase() === repository.owner.toLowerCase() && target.repo.toLowerCase() === repository.repo.toLowerCase() && target.branch === branch;
|
|
361
465
|
}
|
|
362
466
|
function restMachineEndpoint(options) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
path = parsed.pathname;
|
|
379
|
-
}
|
|
380
|
-
catch {
|
|
381
|
-
return 'UNKNOWN';
|
|
382
|
-
}
|
|
467
|
+
const method = ownData(options, "method"), url = ownData(options, "url");
|
|
468
|
+
if (typeof method !== "string" || typeof url !== "string" || url.length > 1024 || /[^\x21-\x7e]/u.test(url))
|
|
469
|
+
return "UNKNOWN";
|
|
470
|
+
let path;
|
|
471
|
+
if (url.startsWith("/")) {
|
|
472
|
+
const base = ownData(options, "baseUrl");
|
|
473
|
+
if (base !== "https://api.github.com") return "UNKNOWN";
|
|
474
|
+
path = url.split(/[?#]/u)[0];
|
|
475
|
+
} else {
|
|
476
|
+
try {
|
|
477
|
+
const parsed = new URL(url);
|
|
478
|
+
if (parsed.origin !== "https://api.github.com" || parsed.username || parsed.password) return "UNKNOWN";
|
|
479
|
+
path = parsed.pathname;
|
|
480
|
+
} catch {
|
|
481
|
+
return "UNKNOWN";
|
|
383
482
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
]
|
|
396
|
-
|
|
483
|
+
}
|
|
484
|
+
const prefix = "/repos/[^/]{1,100}/[^/]{1,100}";
|
|
485
|
+
const number = "(?:[0-9]{1,20}|\\{pull_number\\})";
|
|
486
|
+
const routes = [
|
|
487
|
+
["PUT", new RegExp(`^${prefix}/pulls/${number}/merge$`, "u"), "pulls.merge"],
|
|
488
|
+
["GET", new RegExp(`^${prefix}/pulls/${number}$`, "u"), "pulls.get"],
|
|
489
|
+
["GET", new RegExp(`^${prefix}/pulls/${number}/reviews$`, "u"), "pulls.listReviews"],
|
|
490
|
+
["GET", new RegExp(`^${prefix}/pulls/${number}/reviews/(?:[0-9]{1,20}|\\{review_id\\})$`, "u"), "pulls.getReview"],
|
|
491
|
+
["GET", new RegExp(`^${prefix}/git/commits/[^/]{1,100}$`, "u"), "git.getCommit"],
|
|
492
|
+
["GET", new RegExp(`^${prefix}/git/ref/.{1,300}$`, "u"), "git.getRef"],
|
|
493
|
+
["GET", new RegExp(`^${prefix}/issues/(?:[0-9]{1,20}|\\{issue_number\\})$`, "u"), "issues.get"],
|
|
494
|
+
["PATCH", new RegExp(`^${prefix}/issues/(?:[0-9]{1,20}|\\{issue_number\\})$`, "u"), "issues.update"]
|
|
495
|
+
];
|
|
496
|
+
return routes.find(([verb, pattern]) => verb === method && pattern.test(path))?.[2] ?? "UNKNOWN";
|
|
397
497
|
}
|
|
398
498
|
function safeMachineRequestError(error, phase, endpoint) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
});
|
|
418
|
-
return safe;
|
|
499
|
+
const status = ownData(error, "status");
|
|
500
|
+
const safe = new DeliveryError(
|
|
501
|
+
status === 401 ? "Machine GitHub session is invalid or expired; verify the selected github.com account." : status === 403 || status === 404 ? "Machine GitHub session cannot access the selected repository or operation; verify its existing permissions." : "Machine GitHub request failed; verify the selected account and repository access."
|
|
502
|
+
);
|
|
503
|
+
if (typeof status === "number" && Number.isSafeInteger(status) && status >= 400 && status <= 599)
|
|
504
|
+
Object.assign(safe, { status });
|
|
505
|
+
const headers = ownData(error, "headers") ?? ownData(ownData(error, "response"), "headers");
|
|
506
|
+
setMachineRequestDiagnostics(safe, {
|
|
507
|
+
phase,
|
|
508
|
+
endpoint,
|
|
509
|
+
status,
|
|
510
|
+
code: ownData(error, "code"),
|
|
511
|
+
requestId: ownData(headers, "x-github-request-id"),
|
|
512
|
+
retryAfter: ownData(headers, "retry-after"),
|
|
513
|
+
resetAt: ownData(headers, "x-ratelimit-reset"),
|
|
514
|
+
remaining: ownData(headers, "x-ratelimit-remaining")
|
|
515
|
+
});
|
|
516
|
+
return safe;
|
|
419
517
|
}
|
|
420
|
-
|
|
518
|
+
export {
|
|
519
|
+
assertDeliveryRolePermissions,
|
|
520
|
+
createDeliveryGitHubClients,
|
|
521
|
+
hasBranchProtectionAbsence,
|
|
522
|
+
retainMachineAuthorForConfiguration,
|
|
523
|
+
withAuthorGitToken
|
|
524
|
+
};
|
|
525
|
+
//# sourceMappingURL=client.js.map
|