@aviaratech/ai-delivery 0.3.35 → 0.3.37
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 +56 -554
- package/dist/agent.d.ts +1 -3
- package/dist/agent.js +74 -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 +1651 -1590
- package/dist/boardReconcile.test.js.map +7 -1
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +91 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +389 -517
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -45
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +424 -369
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +288 -14
- package/dist/config/deliveryConfig.js +472 -390
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +773 -649
- 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 -479
- 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.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 +16 -11
- package/dist/dispatch.js +316 -354
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +103 -96
- 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 +63 -23
- 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.d.ts +0 -3
- package/dist/git.js +59 -76
- 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 +42 -52
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +1 -0
- package/dist/github/discovery.js +197 -215
- 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 +18 -2
- package/dist/github/projectDelivery.js +615 -557
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.js +433 -389
- 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 +40 -9
- package/dist/issue.js +2102 -1742
- 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 +989 -885
- 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 +1938 -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 +1059 -989
- 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 -94
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +252 -310
- package/dist/mcp/tools.js +235 -342
- 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 -1229
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1842 -1423
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +417 -413
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +114 -131
- package/dist/pr.js +1314 -1327
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +967 -653
- 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 +123 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +184 -0
- package/dist/readView.js +218 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +146 -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 +125 -125
- package/dist/services/boardReconcileService.js +1295 -1421
- package/dist/services/boardReconcileService.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/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 +321 -358
- 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 +274 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +451 -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.d.ts +0 -2
- package/dist/utils/atomicJson.js +81 -77
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.d.ts +0 -8
- package/dist/utils/filesystem.js +5 -19
- 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 -54
- package/dist/verification.js +976 -1941
- 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.js +45 -24
- package/dist/version.js.map +7 -1
- package/package.json +9 -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 +238 -44
- package/plugins/ai-delivery/runtime/dist/cli.js +351 -115
- 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/services/deliveryAdmission.d.ts +0 -49
- package/dist/services/deliveryAdmission.js +0 -165
- package/dist/services/deliveryAdmission.js.map +0 -1
- package/dist/services/worktreeRegistry.d.ts +0 -434
- package/dist/services/worktreeRegistry.js +0 -1248
- package/dist/services/worktreeRegistry.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 -3329
- package/dist/setup.test.js.map +0 -1
- package/dist/worktree.d.ts +0 -28
- package/dist/worktree.js +0 -188
- package/dist/worktree.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 → build.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
|
@@ -1,92 +1,94 @@
|
|
|
1
|
-
import { CollectionLimitError, DeliveryError } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const response = await input.graphql(`
|
|
1
|
+
import { CollectionLimitError, DeliveryError } from "../errors.js";
|
|
2
|
+
const PROJECT_DELIVERY_STATUSES = ["Todo", "In Progress", "Blocked", "Done"];
|
|
3
|
+
const PROJECT_REVIEW_STATUS = "In Review";
|
|
4
|
+
async function archiveIssueProjectItem(input) {
|
|
5
|
+
const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
|
|
6
|
+
...input,
|
|
7
|
+
settings: requireProjectSettings(input.settings),
|
|
8
|
+
requireWritable: true
|
|
9
|
+
});
|
|
10
|
+
assertWritableConfiguration(configuration);
|
|
11
|
+
const item = await findIssueProjectItem({ ...input, configuration });
|
|
12
|
+
if (item === null) return null;
|
|
13
|
+
if (item.archived) return { archived: true, itemId: item.id };
|
|
14
|
+
const response = await input.graphql(
|
|
15
|
+
`
|
|
17
16
|
mutation ArchiveProjectDeliveryItem($projectId: ID!, $itemId: ID!) {
|
|
18
17
|
archiveProjectV2Item(input: { projectId: $projectId, itemId: $itemId }) {
|
|
19
18
|
item { id isArchived }
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
|
-
`,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
`,
|
|
22
|
+
{ itemId: item.id, projectId: configuration.projectId }
|
|
23
|
+
);
|
|
24
|
+
const record = requireRecord(response, "GitHub returned invalid Project archive evidence.");
|
|
25
|
+
const payload = requireRecord(record.archiveProjectV2Item, "GitHub omitted Project archive payload.");
|
|
26
|
+
const archivedItem = requireRecord(payload.item, "GitHub omitted the archived Project item.");
|
|
27
|
+
if (archivedItem.id !== item.id || archivedItem.isArchived !== true) {
|
|
28
|
+
throw new DeliveryError("Project archive mutation did not return the exact archived item.");
|
|
29
|
+
}
|
|
30
|
+
await readBackProjectArchiveState({
|
|
31
|
+
archived: true,
|
|
32
|
+
configuration,
|
|
33
|
+
graphql: input.graphql,
|
|
34
|
+
issueNodeId: input.issueNodeId,
|
|
35
|
+
itemId: item.id
|
|
36
|
+
});
|
|
37
|
+
return { archived: true, itemId: item.id };
|
|
38
|
+
}
|
|
39
|
+
async function getIssueProjectStatus(input) {
|
|
40
|
+
const configuration = input.configuration ?? await getProjectDeliveryConfiguration({ ...input, settings: requireProjectSettings(input.settings) });
|
|
41
|
+
let item = await findIssueProjectItem({ ...input, configuration });
|
|
42
|
+
if (item === null || item.archived) return null;
|
|
43
|
+
if (item.status === null && item.statusOptionId === null) {
|
|
44
|
+
item = await readProjectItem({
|
|
45
|
+
configuration,
|
|
46
|
+
graphql: input.graphql,
|
|
47
|
+
issueNodeId: input.issueNodeId,
|
|
48
|
+
itemId: item.id,
|
|
49
|
+
...input.capacityRead ? { capacityRead: true } : {}
|
|
35
50
|
});
|
|
36
|
-
|
|
51
|
+
}
|
|
52
|
+
if (item.archived) return null;
|
|
53
|
+
if (item.status === null && item.statusOptionId === null) return null;
|
|
54
|
+
const status = requireItemStatus(item, configuration);
|
|
55
|
+
return { itemId: item.id, status, ...item.review ? { review: true } : {} };
|
|
37
56
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return null;
|
|
44
|
-
// The list projection may omit a status already verified by a direct item read.
|
|
45
|
-
// Resolve that exact item without inferring a status or accepting a missing item.
|
|
46
|
-
if (item.status === null && item.statusOptionId === null) {
|
|
47
|
-
item = await readProjectItem({
|
|
48
|
-
configuration,
|
|
49
|
-
graphql: input.graphql,
|
|
50
|
-
issueNodeId: input.issueNodeId,
|
|
51
|
-
itemId: item.id,
|
|
52
|
-
...(input.capacityRead ? { capacityRead: true } : {}),
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
if (item.archived)
|
|
56
|
-
return null;
|
|
57
|
-
if (item.status === null && item.statusOptionId === null)
|
|
58
|
-
return null;
|
|
59
|
-
const status = requireItemStatus(item, configuration);
|
|
60
|
-
return { itemId: item.id, status };
|
|
57
|
+
async function getArchivedIssueProjectStatus(input) {
|
|
58
|
+
const configuration = input.configuration ?? await getProjectDeliveryConfiguration({ ...input, settings: requireProjectSettings(input.settings) });
|
|
59
|
+
const item = await findIssueProjectItem({ ...input, configuration });
|
|
60
|
+
if (item === null || !item.archived || item.status === null && item.statusOptionId === null) return null;
|
|
61
|
+
return requireItemStatus(item, configuration);
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
async function getProjectDeliveryConfiguration(input) {
|
|
64
|
+
const settings = requireProjectSettings(input.settings);
|
|
65
|
+
const project = await readProjectDeliveryDefinition({
|
|
66
|
+
graphql: input.graphql,
|
|
67
|
+
org: input.org,
|
|
68
|
+
number: settings.number,
|
|
69
|
+
...input.maxPages === void 0 ? {} : { maxPages: input.maxPages }
|
|
70
|
+
});
|
|
71
|
+
return resolveProjectDeliveryConfiguration(project, { requireWritable: input.requireWritable === true, settings });
|
|
71
72
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
73
|
+
async function readProjectDeliveryDefinition(input) {
|
|
74
|
+
const nodes = [];
|
|
75
|
+
let cursor = null;
|
|
76
|
+
let hasNextPage = true;
|
|
77
|
+
const seenCursors = /* @__PURE__ */ new Set();
|
|
78
|
+
const fieldIds = /* @__PURE__ */ new Set();
|
|
79
|
+
let project = null;
|
|
80
|
+
let pages = 0;
|
|
81
|
+
while (hasNextPage) {
|
|
82
|
+
if (input.maxPages !== void 0 && pages >= input.maxPages)
|
|
83
|
+
throw new CollectionLimitError({
|
|
84
|
+
collection: "project-fields",
|
|
85
|
+
pagesRequested: pages,
|
|
86
|
+
rowsObserved: nodes.length,
|
|
87
|
+
limit: input.maxPages
|
|
88
|
+
});
|
|
89
|
+
pages++;
|
|
90
|
+
const response = await input.graphql(
|
|
91
|
+
`
|
|
90
92
|
query ProjectDeliveryConfiguration($org: String!, $number: Int!, $cursor: String) {
|
|
91
93
|
organization(login: $org) {
|
|
92
94
|
projectV2(number: $number) {
|
|
@@ -132,238 +134,247 @@ export async function readProjectDeliveryDefinition(input) {
|
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
|
-
`,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const fieldId = requireString(field.id, 'GitHub omitted a delivery Project field ID.');
|
|
153
|
-
if (fieldIds.has(fieldId))
|
|
154
|
-
throw new DeliveryError('GitHub repeated a delivery Project field.');
|
|
155
|
-
fieldIds.add(fieldId);
|
|
156
|
-
requireString(field.name, 'GitHub omitted a delivery Project field name.');
|
|
157
|
-
requireString(field.__typename, 'GitHub omitted a delivery Project field type.');
|
|
158
|
-
if (field.__typename === 'ProjectV2SingleSelectField') {
|
|
159
|
-
if (typeof field.isIssueField !== 'boolean')
|
|
160
|
-
throw new DeliveryError('GitHub omitted the Project field binding kind.');
|
|
161
|
-
readOptions(field.options, 'Project field');
|
|
162
|
-
if (field.isIssueField) {
|
|
163
|
-
const issueField = requireRecord(field.issueField, 'GitHub omitted the bound organization field.');
|
|
164
|
-
requireString(issueField.__typename, 'GitHub omitted the bound organization field type.');
|
|
165
|
-
if (issueField.__typename === 'IssueFieldSingleSelect') {
|
|
166
|
-
requireString(issueField.id, 'GitHub omitted the bound organization field ID.');
|
|
167
|
-
requireString(issueField.name, 'GitHub omitted the bound organization field name.');
|
|
168
|
-
if (!/^[1-9]\d*$/u.test(String(issueField.fullDatabaseId)))
|
|
169
|
-
throw new DeliveryError('GitHub omitted the bound organization field database ID.');
|
|
170
|
-
readOptions(issueField.options, 'organization field');
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
nodes.push(node);
|
|
175
|
-
}
|
|
176
|
-
project = { ...pageProject, fields: { nodes } };
|
|
177
|
-
const pageInfo = requireRecord(fields.pageInfo, 'GitHub omitted delivery Project field pagination.');
|
|
178
|
-
if (typeof pageInfo.hasNextPage !== 'boolean')
|
|
179
|
-
throw new DeliveryError('GitHub omitted delivery Project pagination state.');
|
|
180
|
-
hasNextPage = pageInfo.hasNextPage === true;
|
|
181
|
-
const nextCursor = typeof pageInfo.endCursor === 'string' ? pageInfo.endCursor : null;
|
|
182
|
-
assertAdvancingCursor({ cursor, hasNextPage, nextCursor, seenCursors, surface: 'field' });
|
|
183
|
-
if (nextCursor !== null)
|
|
184
|
-
seenCursors.add(nextCursor);
|
|
185
|
-
cursor = nextCursor;
|
|
186
|
-
}
|
|
187
|
-
if (project === null) {
|
|
188
|
-
throw new DeliveryError(`Expected organization Project #${String(input.number)}.`);
|
|
189
|
-
}
|
|
190
|
-
return project;
|
|
191
|
-
}
|
|
192
|
-
export function projectSettingsFromDeliveryConfig(config) {
|
|
193
|
-
const project = config.native.project;
|
|
194
|
-
return {
|
|
195
|
-
number: project.number,
|
|
196
|
-
points: config.native.points,
|
|
197
|
-
priority: config.native.priority,
|
|
198
|
-
statuses: {
|
|
199
|
-
Blocked: project.statuses.blocked,
|
|
200
|
-
Done: project.statuses.done,
|
|
201
|
-
'In Progress': project.statuses.inProgress,
|
|
202
|
-
Todo: project.statuses.todo,
|
|
203
|
-
},
|
|
204
|
-
statusField: project.statusField,
|
|
205
|
-
title: project.title,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
export function resolveProjectDeliveryConfiguration(raw, options) {
|
|
209
|
-
const settings = requireProjectSettings(options.settings);
|
|
210
|
-
const project = requireRecord(raw, 'GitHub returned invalid delivery Project configuration.');
|
|
211
|
-
if (project.number !== settings.number || project.title !== settings.title) {
|
|
212
|
-
throw new DeliveryError(`Expected organization Project #${String(settings.number)} titled ${settings.title}.`);
|
|
213
|
-
}
|
|
214
|
-
if (options.requireWritable === true && project.viewerCanUpdate !== true) {
|
|
215
|
-
throw new DeliveryError(`Organization Project #${String(settings.number)} is not writable by this identity.`);
|
|
137
|
+
`,
|
|
138
|
+
{ cursor, number: input.number, org: input.org }
|
|
139
|
+
);
|
|
140
|
+
const responseRecord = requireRecord(response, "GitHub returned invalid delivery Project configuration.");
|
|
141
|
+
if ("errors" in responseRecord) throw new DeliveryError("GitHub returned partial delivery Project evidence.");
|
|
142
|
+
const organization = requireRecord(
|
|
143
|
+
responseRecord.organization,
|
|
144
|
+
`Organization ${input.org} is unavailable to the selected GitHub identity.`
|
|
145
|
+
);
|
|
146
|
+
const pageProject = requireRecord(
|
|
147
|
+
organization.projectV2,
|
|
148
|
+
`Expected organization Project #${String(input.number)}.`
|
|
149
|
+
);
|
|
150
|
+
const fields = requireRecord(pageProject.fields, "GitHub omitted delivery Project fields.");
|
|
151
|
+
const previousProject = project;
|
|
152
|
+
if (previousProject !== null && ["id", "number", "title", "closed", "viewerCanUpdate"].some((key) => previousProject[key] !== pageProject[key])) {
|
|
153
|
+
throw new DeliveryError("Delivery Project identity changed while reading its field pages.");
|
|
216
154
|
}
|
|
217
|
-
const projectId = requireString(project.id, 'GitHub omitted the delivery Project node id.');
|
|
218
|
-
const fields = requireRecord(project.fields, 'GitHub omitted delivery Project fields.');
|
|
219
155
|
if (!Array.isArray(fields.nodes)) {
|
|
220
|
-
|
|
156
|
+
throw new DeliveryError("GitHub returned invalid delivery Project field nodes.");
|
|
221
157
|
}
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
158
|
+
for (const node of fields.nodes) {
|
|
159
|
+
const field = requireRecord(node, "GitHub returned an incomplete delivery Project field.");
|
|
160
|
+
const fieldId = requireString(field.id, "GitHub omitted a delivery Project field ID.");
|
|
161
|
+
if (fieldIds.has(fieldId)) throw new DeliveryError("GitHub repeated a delivery Project field.");
|
|
162
|
+
fieldIds.add(fieldId);
|
|
163
|
+
requireString(field.name, "GitHub omitted a delivery Project field name.");
|
|
164
|
+
requireString(field.__typename, "GitHub omitted a delivery Project field type.");
|
|
165
|
+
if (field.__typename === "ProjectV2SingleSelectField") {
|
|
166
|
+
if (typeof field.isIssueField !== "boolean")
|
|
167
|
+
throw new DeliveryError("GitHub omitted the Project field binding kind.");
|
|
168
|
+
readOptions(field.options, "Project field");
|
|
169
|
+
if (field.isIssueField) {
|
|
170
|
+
const issueField = requireRecord(field.issueField, "GitHub omitted the bound organization field.");
|
|
171
|
+
requireString(issueField.__typename, "GitHub omitted the bound organization field type.");
|
|
172
|
+
if (issueField.__typename === "IssueFieldSingleSelect") {
|
|
173
|
+
requireString(issueField.id, "GitHub omitted the bound organization field ID.");
|
|
174
|
+
requireString(issueField.name, "GitHub omitted the bound organization field name.");
|
|
175
|
+
if (!/^[1-9]\d*$/u.test(String(issueField.fullDatabaseId)))
|
|
176
|
+
throw new DeliveryError("GitHub omitted the bound organization field database ID.");
|
|
177
|
+
readOptions(issueField.options, "organization field");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
nodes.push(node);
|
|
237
182
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
183
|
+
project = { ...pageProject, fields: { nodes } };
|
|
184
|
+
const pageInfo = requireRecord(fields.pageInfo, "GitHub omitted delivery Project field pagination.");
|
|
185
|
+
if (typeof pageInfo.hasNextPage !== "boolean")
|
|
186
|
+
throw new DeliveryError("GitHub omitted delivery Project pagination state.");
|
|
187
|
+
hasNextPage = pageInfo.hasNextPage === true;
|
|
188
|
+
const nextCursor = typeof pageInfo.endCursor === "string" ? pageInfo.endCursor : null;
|
|
189
|
+
assertAdvancingCursor({ cursor, hasNextPage, nextCursor, seenCursors, surface: "field" });
|
|
190
|
+
if (nextCursor !== null) seenCursors.add(nextCursor);
|
|
191
|
+
cursor = nextCursor;
|
|
192
|
+
}
|
|
193
|
+
if (project === null) {
|
|
194
|
+
throw new DeliveryError(`Expected organization Project #${String(input.number)}.`);
|
|
195
|
+
}
|
|
196
|
+
return project;
|
|
197
|
+
}
|
|
198
|
+
function projectSettingsFromDeliveryConfig(config) {
|
|
199
|
+
const project = config.native.project;
|
|
200
|
+
return {
|
|
201
|
+
number: project.number,
|
|
202
|
+
points: config.native.points,
|
|
203
|
+
priority: config.native.priority,
|
|
204
|
+
statuses: {
|
|
205
|
+
Blocked: project.statuses.blocked,
|
|
206
|
+
Done: project.statuses.done,
|
|
207
|
+
"In Progress": project.statuses.inProgress,
|
|
208
|
+
Todo: project.statuses.todo
|
|
209
|
+
},
|
|
210
|
+
statusField: project.statusField,
|
|
211
|
+
title: project.title
|
|
212
|
+
};
|
|
259
213
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
214
|
+
function resolveProjectDeliveryConfiguration(raw, options) {
|
|
215
|
+
const settings = requireProjectSettings(options.settings);
|
|
216
|
+
const project = requireRecord(raw, "GitHub returned invalid delivery Project configuration.");
|
|
217
|
+
if (project.number !== settings.number || project.title !== settings.title) {
|
|
218
|
+
throw new DeliveryError(`Expected organization Project #${String(settings.number)} titled ${settings.title}.`);
|
|
219
|
+
}
|
|
220
|
+
if (options.requireWritable === true && project.viewerCanUpdate !== true) {
|
|
221
|
+
throw new DeliveryError(`Organization Project #${String(settings.number)} is not writable by this identity.`);
|
|
222
|
+
}
|
|
223
|
+
const projectId = requireString(project.id, "GitHub omitted the delivery Project node id.");
|
|
224
|
+
const fields = requireRecord(project.fields, "GitHub omitted delivery Project fields.");
|
|
225
|
+
if (!Array.isArray(fields.nodes)) {
|
|
226
|
+
throw new DeliveryError("GitHub returned invalid delivery Project field nodes.");
|
|
227
|
+
}
|
|
228
|
+
const statusField = requireExactlyOneField(fields.nodes, settings.statusField);
|
|
229
|
+
const pointsField = requireBoundIssueField({
|
|
230
|
+
expectedDatabaseId: settings.points.databaseId,
|
|
231
|
+
expectedOptions: settings.points.values,
|
|
232
|
+
fields: fields.nodes,
|
|
233
|
+
name: settings.points.name
|
|
234
|
+
});
|
|
235
|
+
const priorityField = requireBoundIssueField({
|
|
236
|
+
expectedDatabaseId: settings.priority.databaseId,
|
|
237
|
+
expectedOptions: settings.priority.values,
|
|
238
|
+
fields: fields.nodes,
|
|
239
|
+
name: settings.priority.name
|
|
240
|
+
});
|
|
241
|
+
if (statusField.__typename !== "ProjectV2SingleSelectField" || statusField.isIssueField !== false) {
|
|
242
|
+
throw new DeliveryError("Project Status must be the sole Project-owned single-select workflow field.");
|
|
243
|
+
}
|
|
244
|
+
if (PROJECT_DELIVERY_STATUSES.some((status) => settings.statuses[status] === PROJECT_REVIEW_STATUS))
|
|
245
|
+
throw new DeliveryError(`Rename the configured Status that uses ${PROJECT_REVIEW_STATUS}; that name is reserved.`);
|
|
246
|
+
const allStatusOptions = readOptions(statusField.options, `Project ${settings.statusField}`);
|
|
247
|
+
const reviewOptions = allStatusOptions.filter((option) => option.name === PROJECT_REVIEW_STATUS);
|
|
248
|
+
const statusOptions = allStatusOptions.filter((option) => option.name !== PROJECT_REVIEW_STATUS);
|
|
249
|
+
if (reviewOptions.length > 1)
|
|
250
|
+
throw new DeliveryError(`Project ${settings.statusField} repeats ${PROJECT_REVIEW_STATUS}.`);
|
|
251
|
+
assertExactOptionSet({
|
|
252
|
+
expected: PROJECT_DELIVERY_STATUSES.map((status) => settings.statuses[status]),
|
|
253
|
+
fieldName: `Project ${settings.statusField}`,
|
|
254
|
+
options: statusOptions
|
|
255
|
+
});
|
|
256
|
+
const statusOptionIds = Object.fromEntries(
|
|
257
|
+
PROJECT_DELIVERY_STATUSES.map((status) => [
|
|
258
|
+
status,
|
|
259
|
+
statusOptions.find((option) => option.name === settings.statuses[status])?.id
|
|
260
|
+
])
|
|
261
|
+
);
|
|
262
|
+
return {
|
|
263
|
+
pointsFieldId: requireString(pointsField.id, "GitHub omitted the Project Points field id."),
|
|
264
|
+
priorityFieldId: requireString(priorityField.id, "GitHub omitted the Project Priority field id."),
|
|
265
|
+
projectId,
|
|
266
|
+
projectNumber: settings.number,
|
|
267
|
+
settings,
|
|
268
|
+
statusFieldId: requireString(statusField.id, "GitHub omitted the Project Status field id."),
|
|
269
|
+
statusOptionIds,
|
|
270
|
+
...reviewOptions[0] ? { reviewOptionId: reviewOptions[0].id } : {},
|
|
271
|
+
title: settings.title,
|
|
272
|
+
writable: project.viewerCanUpdate === true
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
async function restoreIssueProjectItem(input) {
|
|
276
|
+
const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
|
|
277
|
+
...input,
|
|
278
|
+
settings: requireProjectSettings(input.settings),
|
|
279
|
+
requireWritable: true
|
|
280
|
+
});
|
|
281
|
+
assertWritableConfiguration(configuration);
|
|
282
|
+
const item = await findIssueProjectItem({ ...input, configuration });
|
|
283
|
+
if (item === null) return null;
|
|
284
|
+
if (!item.archived) return { archived: false, itemId: item.id };
|
|
285
|
+
const response = await input.graphql(
|
|
286
|
+
`
|
|
274
287
|
mutation RestoreProjectDeliveryItem($projectId: ID!, $itemId: ID!) {
|
|
275
288
|
unarchiveProjectV2Item(input: { projectId: $projectId, itemId: $itemId }) {
|
|
276
289
|
item { id isArchived }
|
|
277
290
|
}
|
|
278
291
|
}
|
|
279
|
-
`,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
`,
|
|
293
|
+
{ itemId: item.id, projectId: configuration.projectId }
|
|
294
|
+
);
|
|
295
|
+
const record = requireRecord(response, "GitHub returned invalid Project restore evidence.");
|
|
296
|
+
const payload = requireRecord(record.unarchiveProjectV2Item, "GitHub omitted Project restore payload.");
|
|
297
|
+
const restoredItem = requireRecord(payload.item, "GitHub omitted the restored Project item.");
|
|
298
|
+
if (restoredItem.id !== item.id || restoredItem.isArchived !== false) {
|
|
299
|
+
throw new DeliveryError("Project restore mutation did not return the exact active item.");
|
|
300
|
+
}
|
|
301
|
+
await readBackProjectArchiveState({
|
|
302
|
+
archived: false,
|
|
303
|
+
configuration,
|
|
304
|
+
graphql: input.graphql,
|
|
305
|
+
issueNodeId: input.issueNodeId,
|
|
306
|
+
itemId: item.id
|
|
307
|
+
});
|
|
308
|
+
return { archived: false, itemId: item.id };
|
|
294
309
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
310
|
+
async function assertIssueProjectWritable(input) {
|
|
311
|
+
const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
|
|
312
|
+
...input,
|
|
313
|
+
settings: requireProjectSettings(input.settings),
|
|
314
|
+
requireWritable: true
|
|
315
|
+
});
|
|
316
|
+
assertWritableConfiguration(configuration);
|
|
317
|
+
const item = await findIssueProjectItem({ ...input, configuration });
|
|
318
|
+
if (item?.archived === true) {
|
|
319
|
+
if (input.preserveArchived) return item.id;
|
|
320
|
+
throw new DeliveryError("The issue delivery Project item is archived and cannot be updated.");
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
307
323
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
await input.beforeAdd?.();
|
|
323
|
-
const response = await input.graphql(`
|
|
324
|
+
async function ensureIssueProjectMembership(input) {
|
|
325
|
+
const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
|
|
326
|
+
...input,
|
|
327
|
+
settings: requireProjectSettings(input.settings),
|
|
328
|
+
requireWritable: true
|
|
329
|
+
});
|
|
330
|
+
assertWritableConfiguration(configuration);
|
|
331
|
+
const existing = await findIssueProjectItem({ ...input, configuration });
|
|
332
|
+
if (existing?.archived) throw new DeliveryError("The issue delivery Project item is archived and cannot be updated.");
|
|
333
|
+
let itemId = existing?.id;
|
|
334
|
+
if (itemId === void 0) {
|
|
335
|
+
await input.beforeAdd?.();
|
|
336
|
+
const response = await input.graphql(
|
|
337
|
+
`
|
|
324
338
|
mutation AddProjectDeliveryItem($projectId: ID!, $contentId: ID!) {
|
|
325
339
|
addProjectV2ItemById(input: { projectId: $projectId, contentId: $contentId }) {
|
|
326
340
|
item { id }
|
|
327
341
|
}
|
|
328
342
|
}
|
|
329
|
-
`,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
343
|
+
`,
|
|
344
|
+
{ contentId: input.issueNodeId, projectId: configuration.projectId }
|
|
345
|
+
);
|
|
346
|
+
const added = requireRecord(response, "GitHub returned invalid Project item creation evidence.");
|
|
347
|
+
const payload = requireRecord(added.addProjectV2ItemById, "GitHub omitted Project item creation payload.");
|
|
348
|
+
const created = requireRecord(payload.item, "GitHub omitted the created Project item.");
|
|
349
|
+
itemId = requireString(created.id, "GitHub omitted the created Project item id.");
|
|
350
|
+
}
|
|
351
|
+
input.onItemKnown?.(itemId);
|
|
352
|
+
const item = await readProjectItem({ configuration, graphql: input.graphql, issueNodeId: input.issueNodeId, itemId });
|
|
353
|
+
if (item.archived) throw new DeliveryError("Project membership readback is archived.");
|
|
354
|
+
return { itemId, archived: false };
|
|
341
355
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const optionId = configuration.statusOptionIds[input.status];
|
|
365
|
-
await input.beforeAdvance?.();
|
|
366
|
-
const updateResponse = await input.graphql(`
|
|
356
|
+
async function syncIssueProjectStatus(input) {
|
|
357
|
+
const configuration = input.configuration ?? await getProjectDeliveryConfiguration({
|
|
358
|
+
...input,
|
|
359
|
+
settings: requireProjectSettings(input.settings),
|
|
360
|
+
requireWritable: true
|
|
361
|
+
});
|
|
362
|
+
assertWritableConfiguration(configuration);
|
|
363
|
+
let item = await findIssueProjectItem({ ...input, configuration });
|
|
364
|
+
if (item?.archived === true) {
|
|
365
|
+
throw new DeliveryError("The issue delivery Project item is archived and cannot be updated.");
|
|
366
|
+
}
|
|
367
|
+
if (item !== null && item.status !== null && item.statusOptionId !== null && requireItemStatus(item, configuration) === input.status) {
|
|
368
|
+
return { itemId: item.id, status: input.status };
|
|
369
|
+
}
|
|
370
|
+
if (item === null) {
|
|
371
|
+
const membership = await ensureIssueProjectMembership({ ...input, configuration });
|
|
372
|
+
item = { archived: false, contentId: input.issueNodeId, id: membership.itemId, status: null, statusOptionId: null };
|
|
373
|
+
}
|
|
374
|
+
const optionId = configuration.statusOptionIds[input.status];
|
|
375
|
+
await input.beforeAdvance?.();
|
|
376
|
+
const updateResponse = await input.graphql(
|
|
377
|
+
`
|
|
367
378
|
mutation UpdateProjectDeliveryStatus($projectId: ID!, $itemId: ID!, $fieldId: ID!, $optionId: String!) {
|
|
368
379
|
updateProjectV2ItemFieldValue(
|
|
369
380
|
input: {
|
|
@@ -376,69 +387,75 @@ export async function syncIssueProjectStatus(input) {
|
|
|
376
387
|
projectV2Item { id }
|
|
377
388
|
}
|
|
378
389
|
}
|
|
379
|
-
`,
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
const update = requireRecord(updateResponse, 'GitHub returned invalid Project Status mutation evidence.');
|
|
386
|
-
const updatePayload = requireRecord(update.updateProjectV2ItemFieldValue, 'GitHub omitted Project Status mutation payload.');
|
|
387
|
-
const updatedItem = requireRecord(updatePayload.projectV2Item, 'GitHub omitted the updated Project item.');
|
|
388
|
-
if (updatedItem.id !== item.id) {
|
|
389
|
-
throw new DeliveryError('Project Status mutation returned a different item identity.');
|
|
390
|
+
`,
|
|
391
|
+
{
|
|
392
|
+
fieldId: configuration.statusFieldId,
|
|
393
|
+
itemId: item.id,
|
|
394
|
+
optionId,
|
|
395
|
+
projectId: configuration.projectId
|
|
390
396
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
397
|
+
);
|
|
398
|
+
const update = requireRecord(updateResponse, "GitHub returned invalid Project Status mutation evidence.");
|
|
399
|
+
const updatePayload = requireRecord(
|
|
400
|
+
update.updateProjectV2ItemFieldValue,
|
|
401
|
+
"GitHub omitted Project Status mutation payload."
|
|
402
|
+
);
|
|
403
|
+
const updatedItem = requireRecord(updatePayload.projectV2Item, "GitHub omitted the updated Project item.");
|
|
404
|
+
if (updatedItem.id !== item.id) {
|
|
405
|
+
throw new DeliveryError("Project Status mutation returned a different item identity.");
|
|
406
|
+
}
|
|
407
|
+
return await readBackProjectItem({
|
|
408
|
+
configuration,
|
|
409
|
+
graphql: input.graphql,
|
|
410
|
+
issueNodeId: input.issueNodeId,
|
|
411
|
+
itemId: item.id,
|
|
412
|
+
status: input.status
|
|
413
|
+
});
|
|
398
414
|
}
|
|
399
415
|
function assertAdvancingCursor(input) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
throw new DeliveryError(`Delivery Project ${input.surface} pagination repeated a non-advancing cursor.`);
|
|
407
|
-
}
|
|
416
|
+
if (input.hasNextPage && input.nextCursor === null) {
|
|
417
|
+
throw new DeliveryError(`Delivery Project ${input.surface} pagination omitted its next cursor.`);
|
|
418
|
+
}
|
|
419
|
+
if (input.hasNextPage && input.nextCursor !== null && (input.nextCursor === input.cursor || input.seenCursors.has(input.nextCursor))) {
|
|
420
|
+
throw new DeliveryError(`Delivery Project ${input.surface} pagination repeated a non-advancing cursor.`);
|
|
421
|
+
}
|
|
408
422
|
}
|
|
409
423
|
function assertExactOptionSet(input) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
424
|
+
const observed = input.options.map((option) => option.name);
|
|
425
|
+
const observedSet = new Set(observed);
|
|
426
|
+
const expectedSet = new Set(input.expected);
|
|
427
|
+
if (observedSet.size !== observed.length || observedSet.size !== expectedSet.size || observed.some((option) => !expectedSet.has(option))) {
|
|
428
|
+
throw new DeliveryError(
|
|
429
|
+
`${input.fieldName} options must be exactly ${input.expected.join(", ")} (order is provider-owned).`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
418
432
|
}
|
|
419
433
|
function assertWritableConfiguration(configuration) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
434
|
+
if (!configuration.writable) {
|
|
435
|
+
throw new DeliveryError(
|
|
436
|
+
`Organization Project #${String(configuration.projectNumber)} is not writable by this identity.`
|
|
437
|
+
);
|
|
438
|
+
}
|
|
423
439
|
}
|
|
424
440
|
async function fetchProjectDeliveryItemNodes(input) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
441
|
+
const nodes = [];
|
|
442
|
+
let cursor = null;
|
|
443
|
+
let hasNextPage = true;
|
|
444
|
+
const seenCursors = /* @__PURE__ */ new Set();
|
|
445
|
+
let pages = 0;
|
|
446
|
+
if (input.maxPages !== void 0 && (!Number.isSafeInteger(input.maxPages) || input.maxPages <= 0))
|
|
447
|
+
throw new DeliveryError("Project item page budget must be positive.");
|
|
448
|
+
while (hasNextPage) {
|
|
449
|
+
if (input.maxPages !== void 0 && pages >= input.maxPages)
|
|
450
|
+
throw new CollectionLimitError({
|
|
451
|
+
collection: "project-items",
|
|
452
|
+
pagesRequested: pages,
|
|
453
|
+
rowsObserved: nodes.length,
|
|
454
|
+
limit: input.maxPages
|
|
455
|
+
});
|
|
456
|
+
pages++;
|
|
457
|
+
const response = await input.graphql(
|
|
458
|
+
`
|
|
442
459
|
query ProjectDeliveryItems($org: String!, $number: Int!, $cursor: String, $statusField: String!) {
|
|
443
460
|
organization(login: $org) {
|
|
444
461
|
projectV2(number: $number) {
|
|
@@ -458,140 +475,174 @@ async function fetchProjectDeliveryItemNodes(input) {
|
|
|
458
475
|
}
|
|
459
476
|
}
|
|
460
477
|
}
|
|
461
|
-
`,
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
nodes.push(...items.nodes);
|
|
480
|
-
const pageInfo = requireRecord(items.pageInfo, 'GitHub omitted delivery Project item pagination.');
|
|
481
|
-
if ((input.capacityRead || input.strictProjection) && typeof pageInfo.hasNextPage !== 'boolean')
|
|
482
|
-
throw new DeliveryError('WIP capacity Project pagination is incomplete.');
|
|
483
|
-
hasNextPage = pageInfo.hasNextPage === true;
|
|
484
|
-
const nextCursor = typeof pageInfo.endCursor === 'string' ? pageInfo.endCursor : null;
|
|
485
|
-
assertAdvancingCursor({ cursor, hasNextPage, nextCursor, seenCursors, surface: 'item' });
|
|
486
|
-
if (nextCursor !== null)
|
|
487
|
-
seenCursors.add(nextCursor);
|
|
488
|
-
cursor = nextCursor;
|
|
478
|
+
`,
|
|
479
|
+
{
|
|
480
|
+
cursor,
|
|
481
|
+
number: input.configuration.projectNumber,
|
|
482
|
+
org: input.org,
|
|
483
|
+
statusField: input.configuration.settings.statusField
|
|
484
|
+
}
|
|
485
|
+
);
|
|
486
|
+
const record = requireRecord(response, "GitHub returned invalid delivery Project item evidence.");
|
|
487
|
+
if (input.strictProjection && "errors" in record)
|
|
488
|
+
throw new DeliveryError("GitHub returned partial Project item evidence.");
|
|
489
|
+
const organization = requireRecord(record.organization, "GitHub omitted the delivery Project organization.");
|
|
490
|
+
const project = requireRecord(organization.projectV2, "GitHub omitted the delivery Project.");
|
|
491
|
+
if ((input.capacityRead || input.strictProjection) && (project.id !== input.configuration.projectId || project.number !== input.configuration.projectNumber))
|
|
492
|
+
throw new DeliveryError("WIP capacity Project identity disagrees with the configured Project.");
|
|
493
|
+
const items = requireRecord(project.items, "GitHub omitted delivery Project items.");
|
|
494
|
+
if (!Array.isArray(items.nodes)) {
|
|
495
|
+
throw new DeliveryError("GitHub returned invalid delivery Project items.");
|
|
489
496
|
}
|
|
490
|
-
|
|
497
|
+
nodes.push(...items.nodes);
|
|
498
|
+
const pageInfo = requireRecord(items.pageInfo, "GitHub omitted delivery Project item pagination.");
|
|
499
|
+
if ((input.capacityRead || input.strictProjection) && typeof pageInfo.hasNextPage !== "boolean" || input.capacityRead && pageInfo.endCursor !== null && typeof pageInfo.endCursor !== "string")
|
|
500
|
+
throw new DeliveryError("WIP capacity Project pagination is incomplete.");
|
|
501
|
+
hasNextPage = pageInfo.hasNextPage === true;
|
|
502
|
+
const nextCursor = typeof pageInfo.endCursor === "string" ? pageInfo.endCursor : null;
|
|
503
|
+
assertAdvancingCursor({ cursor, hasNextPage, nextCursor, seenCursors, surface: "item" });
|
|
504
|
+
if (nextCursor !== null) seenCursors.add(nextCursor);
|
|
505
|
+
cursor = nextCursor;
|
|
506
|
+
}
|
|
507
|
+
return nodes;
|
|
491
508
|
}
|
|
492
509
|
async function findIssueProjectItem(input) {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
const record = requireRecord(raw, 'GitHub returned invalid Project membership.');
|
|
511
|
-
if (typeof record.isArchived !== 'boolean')
|
|
512
|
-
throw new DeliveryError('Project archive projection is incomplete.');
|
|
513
|
-
const content = requireRecord(record.content, 'Project content is unreadable; absence cannot be proved.');
|
|
514
|
-
const kind = content.__typename;
|
|
515
|
-
if (kind !== 'Issue' && kind !== 'DraftIssue' && kind !== 'PullRequest')
|
|
516
|
-
throw new DeliveryError('Project content type is unreadable.');
|
|
517
|
-
// Membership identity is independent of whether this item's Status is usable.
|
|
518
|
-
let item = parseProjectItem({ ...record, fieldValueByName: null }, input.configuration);
|
|
519
|
-
if (!item || ids.has(item.id))
|
|
520
|
-
throw new DeliveryError('Project item identity is missing or repeated.');
|
|
521
|
-
let statusRead = record.fieldValueByName === null ? 'unset' : 'unreadable';
|
|
522
|
-
const rawStatus = isRecord(record.fieldValueByName) ? record.fieldValueByName : null;
|
|
523
|
-
const safeText = (value) => typeof value === 'string' && value.length > 0 && value.length <= 512 ? value : null;
|
|
524
|
-
const statusName = safeText(rawStatus?.name);
|
|
525
|
-
if (record.fieldValueByName !== undefined && record.fieldValueByName !== null) {
|
|
526
|
-
try {
|
|
527
|
-
item = parseProjectItem(record, input.configuration);
|
|
528
|
-
statusRead = 'verified';
|
|
529
|
-
}
|
|
530
|
-
catch {
|
|
531
|
-
item.statusOptionId = safeText(rawStatus?.optionId);
|
|
510
|
+
const response = await input.graphql(
|
|
511
|
+
`
|
|
512
|
+
query ProjectDeliveryIssueItems($issueNodeId: ID!, $statusField: String!) {
|
|
513
|
+
node(id: $issueNodeId) {
|
|
514
|
+
... on Issue {
|
|
515
|
+
id
|
|
516
|
+
projectItems(first: 50, includeArchived: true) {
|
|
517
|
+
nodes {
|
|
518
|
+
id
|
|
519
|
+
isArchived
|
|
520
|
+
project { id number }
|
|
521
|
+
content { ... on Issue { id } }
|
|
522
|
+
fieldValueByName(name: $statusField) {
|
|
523
|
+
... on ProjectV2ItemFieldSingleSelectValue { name optionId }
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
pageInfo { hasNextPage }
|
|
532
527
|
}
|
|
528
|
+
}
|
|
533
529
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
530
|
+
}
|
|
531
|
+
`,
|
|
532
|
+
{ issueNodeId: input.issueNodeId, statusField: input.configuration.settings.statusField }
|
|
533
|
+
);
|
|
534
|
+
const record = requireRecord(response, "GitHub returned invalid issue Project evidence.");
|
|
535
|
+
const node = requireRecord(record.node, "GitHub omitted the issue.");
|
|
536
|
+
const items = requireRecord(node.projectItems, "GitHub omitted the issue Project items.");
|
|
537
|
+
if (node.id !== input.issueNodeId || !Array.isArray(items.nodes))
|
|
538
|
+
throw new DeliveryError("GitHub returned Project items for a different issue.");
|
|
539
|
+
if (requireRecord(items.pageInfo, "GitHub omitted issue Project pagination.").hasNextPage !== false)
|
|
540
|
+
throw new DeliveryError("Issue belongs to more than 50 Projects; Project membership cannot be proved.");
|
|
541
|
+
const matches = [];
|
|
542
|
+
for (const raw of items.nodes) {
|
|
543
|
+
const project = requireRecord(
|
|
544
|
+
requireRecord(raw, "GitHub returned an invalid Project item.").project,
|
|
545
|
+
"GitHub omitted the Project item identity."
|
|
546
|
+
);
|
|
547
|
+
if (project.id !== input.configuration.projectId) continue;
|
|
548
|
+
const item = parseProjectItem(raw, input.configuration, input.capacityRead);
|
|
549
|
+
if (item?.contentId !== input.issueNodeId)
|
|
550
|
+
throw new DeliveryError("Project membership is unreadable; absence cannot be proved.");
|
|
551
|
+
matches.push(item);
|
|
552
|
+
}
|
|
553
|
+
if (matches.length > 1)
|
|
554
|
+
throw new DeliveryError(
|
|
555
|
+
`Issue has ${String(matches.length)} duplicate Project items in ${input.configuration.title}.`
|
|
556
|
+
);
|
|
557
|
+
return matches[0] ?? null;
|
|
558
|
+
}
|
|
559
|
+
async function readProjectDeliveryItems(input) {
|
|
560
|
+
const observations = [];
|
|
561
|
+
const ids = /* @__PURE__ */ new Set();
|
|
562
|
+
for (const raw of await fetchProjectDeliveryItemNodes({ ...input, strictProjection: true })) {
|
|
563
|
+
const record = requireRecord(raw, "GitHub returned invalid Project membership.");
|
|
564
|
+
if (typeof record.isArchived !== "boolean") throw new DeliveryError("Project archive projection is incomplete.");
|
|
565
|
+
const content = requireRecord(record.content, "Project content is unreadable; absence cannot be proved.");
|
|
566
|
+
const kind = content.__typename;
|
|
567
|
+
if (kind !== "Issue" && kind !== "DraftIssue" && kind !== "PullRequest")
|
|
568
|
+
throw new DeliveryError("Project content type is unreadable.");
|
|
569
|
+
let item = parseProjectItem({ ...record, fieldValueByName: null }, input.configuration);
|
|
570
|
+
if (!item || ids.has(item.id)) throw new DeliveryError("Project item identity is missing or repeated.");
|
|
571
|
+
let statusRead = record.fieldValueByName === null ? "unset" : "unreadable";
|
|
572
|
+
const rawStatus = isRecord(record.fieldValueByName) ? record.fieldValueByName : null;
|
|
573
|
+
const safeText = (value) => typeof value === "string" && value.length > 0 && value.length <= 512 ? value : null;
|
|
574
|
+
const statusName = safeText(rawStatus?.name);
|
|
575
|
+
if (record.fieldValueByName !== void 0 && record.fieldValueByName !== null) {
|
|
576
|
+
try {
|
|
577
|
+
item = parseProjectItem(record, input.configuration);
|
|
578
|
+
statusRead = "verified";
|
|
579
|
+
} catch {
|
|
580
|
+
item.statusOptionId = safeText(rawStatus?.optionId);
|
|
581
|
+
}
|
|
552
582
|
}
|
|
553
|
-
|
|
583
|
+
ids.add(item.id);
|
|
584
|
+
const identity = {
|
|
585
|
+
...item,
|
|
586
|
+
projectId: input.configuration.projectId,
|
|
587
|
+
projectNumber: input.configuration.projectNumber,
|
|
588
|
+
statusRead,
|
|
589
|
+
statusName
|
|
590
|
+
};
|
|
591
|
+
if (kind === "Issue") {
|
|
592
|
+
const repository = requireString(
|
|
593
|
+
requireRecord(content.repository, "Project issue repository is unreadable.").nameWithOwner,
|
|
594
|
+
"Project issue repository is missing."
|
|
595
|
+
);
|
|
596
|
+
if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(repository) || !Number.isSafeInteger(content.number) || Number(content.number) <= 0)
|
|
597
|
+
throw new DeliveryError("Project issue identity is invalid.");
|
|
598
|
+
observations.push({ ...identity, contentKind: "issue", repository, issueNumber: Number(content.number) });
|
|
599
|
+
} else observations.push({ ...identity, contentKind: kind === "DraftIssue" ? "draft" : "pull-request" });
|
|
600
|
+
}
|
|
601
|
+
return observations;
|
|
554
602
|
}
|
|
555
603
|
function isRecord(value) {
|
|
556
|
-
|
|
604
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
557
605
|
}
|
|
558
606
|
function parseProjectItem(raw, configuration, capacityRead = false) {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
status = canonicalStatus;
|
|
582
|
-
statusOptionId = optionId;
|
|
607
|
+
const item = requireRecord(raw, "GitHub returned an invalid delivery Project item.");
|
|
608
|
+
if (capacityRead && (typeof item.isArchived !== "boolean" || item.fieldValueByName === void 0))
|
|
609
|
+
throw new DeliveryError("WIP capacity Project status or archive evidence is missing.");
|
|
610
|
+
const content = item.content;
|
|
611
|
+
if (capacityRead && !item.isArchived && (content === null || content === void 0))
|
|
612
|
+
throw new DeliveryError("WIP capacity Project item content is unreadable.");
|
|
613
|
+
if (content === null || content === void 0) return null;
|
|
614
|
+
const contentRecord = requireRecord(content, "GitHub returned an invalid delivery Project item content node.");
|
|
615
|
+
const contentId = requireString(contentRecord.id, "GitHub omitted a delivery Project item content id.");
|
|
616
|
+
const fieldValue = item.fieldValueByName;
|
|
617
|
+
let status = null;
|
|
618
|
+
let statusOptionId = null;
|
|
619
|
+
let review = false;
|
|
620
|
+
if (fieldValue !== null && fieldValue !== void 0) {
|
|
621
|
+
const statusRecord = requireRecord(fieldValue, "GitHub returned invalid Project Status readback.");
|
|
622
|
+
const name = requireString(statusRecord.name, "GitHub omitted Project Status name.");
|
|
623
|
+
const optionId = requireString(statusRecord.optionId, "GitHub omitted Project Status option id.");
|
|
624
|
+
const statuses = configuration.settings.statuses;
|
|
625
|
+
review = name === PROJECT_REVIEW_STATUS && optionId === configuration.reviewOptionId;
|
|
626
|
+
const canonicalStatus = review ? "In Progress" : PROJECT_DELIVERY_STATUSES.find((candidate) => statuses[candidate] === name);
|
|
627
|
+
if (canonicalStatus === void 0 || !review && configuration.statusOptionIds[canonicalStatus] !== optionId) {
|
|
628
|
+
throw new DeliveryError(`GitHub returned unsupported Project Status ${name}.`);
|
|
583
629
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
630
|
+
status = canonicalStatus;
|
|
631
|
+
statusOptionId = review ? configuration.statusOptionIds["In Progress"] : optionId;
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
archived: item.isArchived === true,
|
|
635
|
+
contentId,
|
|
636
|
+
id: requireString(item.id, "GitHub omitted the delivery Project item id."),
|
|
637
|
+
status,
|
|
638
|
+
statusOptionId,
|
|
639
|
+
...review ? { review: true } : {}
|
|
640
|
+
};
|
|
591
641
|
}
|
|
592
642
|
async function readBackProjectArchiveState(input) {
|
|
593
|
-
|
|
594
|
-
|
|
643
|
+
const response = await input.graphql(
|
|
644
|
+
`
|
|
645
|
+
query ${input.archived ? "Archived" : "Restored"}ProjectDeliveryItemReadback($itemId: ID!) {
|
|
595
646
|
node(id: $itemId) {
|
|
596
647
|
... on ProjectV2Item {
|
|
597
648
|
id
|
|
@@ -601,31 +652,28 @@ async function readBackProjectArchiveState(input) {
|
|
|
601
652
|
}
|
|
602
653
|
}
|
|
603
654
|
}
|
|
604
|
-
`,
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
throw new DeliveryError(`Project ${state} readback did not report the exact issue item.`);
|
|
616
|
-
}
|
|
655
|
+
`,
|
|
656
|
+
{ itemId: input.itemId }
|
|
657
|
+
);
|
|
658
|
+
const state = input.archived ? "archived" : "restored";
|
|
659
|
+
const record = requireRecord(response, `GitHub returned invalid ${state} Project item readback.`);
|
|
660
|
+
const node = requireRecord(record.node, `GitHub omitted ${state} Project item readback.`);
|
|
661
|
+
const project = requireRecord(node.project, `GitHub omitted ${state} Project identity readback.`);
|
|
662
|
+
const content = requireRecord(node.content, `GitHub omitted ${state} Project item content readback.`);
|
|
663
|
+
if (node.id !== input.itemId || node.isArchived !== input.archived || project.id !== input.configuration.projectId || project.number !== input.configuration.projectNumber || content.id !== input.issueNodeId) {
|
|
664
|
+
throw new DeliveryError(`Project ${state} readback did not report the exact issue item.`);
|
|
665
|
+
}
|
|
617
666
|
}
|
|
618
667
|
async function readBackProjectItem(input) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
625
|
-
return { itemId: input.itemId, status: input.status };
|
|
668
|
+
const item = await readProjectItem(input);
|
|
669
|
+
if (item.archived || item.status !== input.status || item.statusOptionId !== input.configuration.statusOptionIds[input.status]) {
|
|
670
|
+
throw new DeliveryError(`Project Status readback did not report ${input.status} for the exact issue item.`);
|
|
671
|
+
}
|
|
672
|
+
return { itemId: input.itemId, status: input.status };
|
|
626
673
|
}
|
|
627
674
|
async function readProjectItem(input) {
|
|
628
|
-
|
|
675
|
+
const response = await input.graphql(
|
|
676
|
+
`
|
|
629
677
|
query ProjectDeliveryItemReadback($itemId: ID!, $statusField: String!) {
|
|
630
678
|
node(id: $itemId) {
|
|
631
679
|
... on ProjectV2Item {
|
|
@@ -639,85 +687,95 @@ async function readProjectItem(input) {
|
|
|
639
687
|
}
|
|
640
688
|
}
|
|
641
689
|
}
|
|
642
|
-
`,
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
if (item === null)
|
|
656
|
-
throw new DeliveryError('GitHub omitted Project item content readback.');
|
|
657
|
-
return item;
|
|
690
|
+
`,
|
|
691
|
+
{ itemId: input.itemId, statusField: input.configuration.settings.statusField }
|
|
692
|
+
);
|
|
693
|
+
const record = requireRecord(response, "GitHub returned invalid Project item readback.");
|
|
694
|
+
const node = requireRecord(record.node, "GitHub omitted Project item readback.");
|
|
695
|
+
const project = requireRecord(node.project, "GitHub omitted Project identity readback.");
|
|
696
|
+
const content = requireRecord(node.content, "GitHub omitted Project item content readback.");
|
|
697
|
+
if (node.id !== input.itemId || typeof node.isArchived !== "boolean" || project.id !== input.configuration.projectId || project.number !== input.configuration.projectNumber || content.id !== input.issueNodeId) {
|
|
698
|
+
throw new DeliveryError("Project Status readback did not report the exact issue item.");
|
|
699
|
+
}
|
|
700
|
+
const item = parseProjectItem(node, input.configuration, input.capacityRead);
|
|
701
|
+
if (item === null) throw new DeliveryError("GitHub omitted Project item content readback.");
|
|
702
|
+
return item;
|
|
658
703
|
}
|
|
659
704
|
function readOptions(raw, fieldName) {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
705
|
+
if (!Array.isArray(raw)) {
|
|
706
|
+
throw new DeliveryError(`${fieldName} options are malformed.`);
|
|
707
|
+
}
|
|
708
|
+
return raw.map((option) => {
|
|
709
|
+
const record = requireRecord(option, `${fieldName} option is malformed.`);
|
|
710
|
+
return {
|
|
711
|
+
id: requireString(record.id, `${fieldName} option id is missing.`),
|
|
712
|
+
name: requireString(record.name, `${fieldName} option name is missing.`)
|
|
713
|
+
};
|
|
714
|
+
});
|
|
670
715
|
}
|
|
671
716
|
function requireBoundIssueField(input) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
})
|
|
691
|
-
|
|
717
|
+
const field = requireExactlyOneField(input.fields, input.name);
|
|
718
|
+
if (field.__typename !== "ProjectV2SingleSelectField" || field.isIssueField !== true) {
|
|
719
|
+
throw new DeliveryError(`Project ${input.name} must bind the organization issue field.`);
|
|
720
|
+
}
|
|
721
|
+
if (Array.isArray(field.options) && field.options.length !== 0) {
|
|
722
|
+
throw new DeliveryError(`Project ${input.name} must not define Project-owned duplicate options.`);
|
|
723
|
+
}
|
|
724
|
+
const issueField = requireRecord(
|
|
725
|
+
field.issueField,
|
|
726
|
+
`Project ${input.name} omitted its bound organization issue field.`
|
|
727
|
+
);
|
|
728
|
+
const databaseId = typeof issueField.fullDatabaseId === "string" ? issueField.fullDatabaseId : String(issueField.fullDatabaseId);
|
|
729
|
+
if (issueField.__typename !== "IssueFieldSingleSelect" || issueField.name !== input.name || databaseId !== input.expectedDatabaseId) {
|
|
730
|
+
throw new DeliveryError(`Project ${input.name} must bind organization issue field ${input.expectedDatabaseId}.`);
|
|
731
|
+
}
|
|
732
|
+
assertExactOptionSet({
|
|
733
|
+
expected: input.expectedOptions,
|
|
734
|
+
fieldName: input.name,
|
|
735
|
+
options: readOptions(issueField.options, `organization ${input.name}`)
|
|
736
|
+
});
|
|
737
|
+
return field;
|
|
692
738
|
}
|
|
693
739
|
function requireExactlyOneField(fields, name) {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
740
|
+
const matches = fields.filter((field) => isRecord(field) && field.name === name);
|
|
741
|
+
if (matches.length !== 1) {
|
|
742
|
+
throw new DeliveryError(`Expected exactly one Project ${name} field, found ${String(matches.length)}.`);
|
|
743
|
+
}
|
|
744
|
+
return matches[0];
|
|
699
745
|
}
|
|
700
746
|
function requireItemStatus(item, configuration) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
}
|
|
706
|
-
return item.status;
|
|
747
|
+
if (item.status === null || item.statusOptionId === null || configuration.statusOptionIds[item.status] !== item.statusOptionId) {
|
|
748
|
+
throw new DeliveryError("The issue delivery Project item has no canonical Project Status.");
|
|
749
|
+
}
|
|
750
|
+
return item.status;
|
|
707
751
|
}
|
|
708
752
|
function requireRecord(value, message) {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
return value;
|
|
753
|
+
if (!isRecord(value)) throw new DeliveryError(message);
|
|
754
|
+
return value;
|
|
712
755
|
}
|
|
713
756
|
function requireString(value, message) {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
return value;
|
|
757
|
+
if (typeof value !== "string" || value.length === 0) throw new DeliveryError(message);
|
|
758
|
+
return value;
|
|
717
759
|
}
|
|
718
760
|
function requireProjectSettings(settings) {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
return settings;
|
|
761
|
+
if (settings === void 0) throw new DeliveryError("Project delivery settings are required.");
|
|
762
|
+
return settings;
|
|
722
763
|
}
|
|
723
|
-
|
|
764
|
+
export {
|
|
765
|
+
PROJECT_DELIVERY_STATUSES,
|
|
766
|
+
PROJECT_REVIEW_STATUS,
|
|
767
|
+
archiveIssueProjectItem,
|
|
768
|
+
assertIssueProjectWritable,
|
|
769
|
+
ensureIssueProjectMembership,
|
|
770
|
+
getArchivedIssueProjectStatus,
|
|
771
|
+
getIssueProjectStatus,
|
|
772
|
+
getProjectDeliveryConfiguration,
|
|
773
|
+
projectSettingsFromDeliveryConfig,
|
|
774
|
+
readBackProjectItem,
|
|
775
|
+
readProjectDeliveryDefinition,
|
|
776
|
+
readProjectDeliveryItems,
|
|
777
|
+
resolveProjectDeliveryConfiguration,
|
|
778
|
+
restoreIssueProjectItem,
|
|
779
|
+
syncIssueProjectStatus
|
|
780
|
+
};
|
|
781
|
+
//# sourceMappingURL=projectDelivery.js.map
|