@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.
Files changed (301) hide show
  1. package/CONTRIBUTING.md +12 -206
  2. package/README.md +56 -554
  3. package/dist/agent.d.ts +1 -3
  4. package/dist/agent.js +74 -16
  5. package/dist/agent.js.map +7 -1
  6. package/dist/agentReadiness.test.js +73 -67
  7. package/dist/agentReadiness.test.js.map +7 -1
  8. package/dist/boardReconcile.test.js +1651 -1590
  9. package/dist/boardReconcile.test.js.map +7 -1
  10. package/dist/build.test.js +130 -0
  11. package/dist/build.test.js.map +7 -0
  12. package/dist/callerErrors.test.js +91 -0
  13. package/dist/callerErrors.test.js.map +7 -0
  14. package/dist/cli.js +389 -517
  15. package/dist/cli.js.map +7 -1
  16. package/dist/cliResult.d.ts +2 -2
  17. package/dist/cliResult.js +42 -45
  18. package/dist/cliResult.js.map +7 -1
  19. package/dist/cliResult.test.js +424 -369
  20. package/dist/cliResult.test.js.map +7 -1
  21. package/dist/config/deliveryConfig.d.ts +288 -14
  22. package/dist/config/deliveryConfig.js +472 -390
  23. package/dist/config/deliveryConfig.js.map +7 -1
  24. package/dist/config/deliveryConfig.test.js +773 -649
  25. package/dist/config/deliveryConfig.test.js.map +7 -1
  26. package/dist/contributorChecks.test.js +1694 -916
  27. package/dist/contributorChecks.test.js.map +7 -1
  28. package/dist/currentConsumer.test.js +819 -737
  29. package/dist/currentConsumer.test.js.map +7 -1
  30. package/dist/currentTrackingScenario.test.js +499 -479
  31. package/dist/currentTrackingScenario.test.js.map +7 -1
  32. package/dist/delivery/common.js +160 -172
  33. package/dist/delivery/common.js.map +7 -1
  34. package/dist/delivery/delivery.test.js +509 -431
  35. package/dist/delivery/delivery.test.js.map +7 -1
  36. package/dist/delivery/evidence.d.ts +2 -2
  37. package/dist/delivery/evidence.js +133 -120
  38. package/dist/delivery/evidence.js.map +7 -1
  39. package/dist/delivery/index.js +7 -2
  40. package/dist/delivery/index.js.map +7 -1
  41. package/dist/delivery/legacy.js +65 -5
  42. package/dist/delivery/legacy.js.map +7 -1
  43. package/dist/delivery/policy.d.ts +10 -10
  44. package/dist/delivery/policy.js +211 -238
  45. package/dist/delivery/policy.js.map +7 -1
  46. package/dist/delivery/stage.d.ts +18 -18
  47. package/dist/delivery/stage.js +220 -235
  48. package/dist/delivery/stage.js.map +7 -1
  49. package/dist/deliveryBoard.d.ts +74 -0
  50. package/dist/deliveryBoard.js +644 -0
  51. package/dist/deliveryBoard.js.map +7 -0
  52. package/dist/deliveryBoard.test.js +649 -0
  53. package/dist/deliveryBoard.test.js.map +7 -0
  54. package/dist/deliveryHealth.test.js +179 -155
  55. package/dist/deliveryHealth.test.js.map +7 -1
  56. package/dist/dependencyCompatibility.test.js +154 -140
  57. package/dist/dependencyCompatibility.test.js.map +7 -1
  58. package/dist/directoryIndependent.test.js +417 -383
  59. package/dist/directoryIndependent.test.js.map +7 -1
  60. package/dist/dispatch.d.ts +16 -11
  61. package/dist/dispatch.js +316 -354
  62. package/dist/dispatch.js.map +7 -1
  63. package/dist/errors.d.ts +3 -3
  64. package/dist/errors.js +103 -96
  65. package/dist/errors.js.map +7 -1
  66. package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
  67. package/dist/fixtures/deliveryBoardReplay.js +617 -0
  68. package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
  69. package/dist/fixtures/discovery.d.ts +63 -23
  70. package/dist/fixtures/discovery.js +96 -90
  71. package/dist/fixtures/discovery.js.map +7 -1
  72. package/dist/fixtures/inertEntrypointChild.js +57 -56
  73. package/dist/fixtures/inertEntrypointChild.js.map +7 -1
  74. package/dist/fixtures/inertEntrypoints.d.ts +1 -1
  75. package/dist/fixtures/inertEntrypoints.js +321 -276
  76. package/dist/fixtures/inertEntrypoints.js.map +7 -1
  77. package/dist/fixtures/inertTarget.d.ts +78 -7
  78. package/dist/fixtures/inertTarget.js +769 -691
  79. package/dist/fixtures/inertTarget.js.map +7 -1
  80. package/dist/fixtures/issue63.d.ts +4 -3
  81. package/dist/fixtures/issue63.js +260 -274
  82. package/dist/fixtures/issue63.js.map +7 -1
  83. package/dist/fixtures/issueProjectItems.d.ts +20 -0
  84. package/dist/fixtures/issueProjectItems.js +15 -0
  85. package/dist/fixtures/issueProjectItems.js.map +7 -0
  86. package/dist/fixtures/readView.d.ts +120 -0
  87. package/dist/fixtures/readView.js +172 -0
  88. package/dist/fixtures/readView.js.map +7 -0
  89. package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
  90. package/dist/fixtures/recordedGitHubFlows.js +109 -0
  91. package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
  92. package/dist/genericCompatibility.test.js +64 -55
  93. package/dist/genericCompatibility.test.js.map +7 -1
  94. package/dist/git.d.ts +0 -3
  95. package/dist/git.js +59 -76
  96. package/dist/git.js.map +7 -1
  97. package/dist/gitProcess.d.ts +1 -1
  98. package/dist/gitProcess.js +58 -53
  99. package/dist/gitProcess.js.map +7 -1
  100. package/dist/github/client.d.ts +2 -2
  101. package/dist/github/client.js +484 -379
  102. package/dist/github/client.js.map +7 -1
  103. package/dist/github/commandIdentityPolicy.js +42 -52
  104. package/dist/github/commandIdentityPolicy.js.map +7 -1
  105. package/dist/github/discovery.d.ts +1 -0
  106. package/dist/github/discovery.js +197 -215
  107. package/dist/github/discovery.js.map +7 -1
  108. package/dist/github/discovery.test.js +223 -177
  109. package/dist/github/discovery.test.js.map +7 -1
  110. package/dist/github/issueHistory.d.ts +2 -2
  111. package/dist/github/issueHistory.js +117 -125
  112. package/dist/github/issueHistory.js.map +7 -1
  113. package/dist/github/machineAuth.d.ts +1 -1
  114. package/dist/github/machineAuth.js +126 -117
  115. package/dist/github/machineAuth.js.map +7 -1
  116. package/dist/github/machineAuth.test.js +755 -639
  117. package/dist/github/machineAuth.test.js.map +7 -1
  118. package/dist/github/nativeIssueMetadata.js +286 -273
  119. package/dist/github/nativeIssueMetadata.js.map +7 -1
  120. package/dist/github/projectDelivery.d.ts +18 -2
  121. package/dist/github/projectDelivery.js +615 -557
  122. package/dist/github/projectDelivery.js.map +7 -1
  123. package/dist/github/relationships.js +433 -389
  124. package/dist/github/relationships.js.map +7 -1
  125. package/dist/github/repo.d.ts +1 -0
  126. package/dist/github/repo.js +123 -96
  127. package/dist/github/repo.js.map +7 -1
  128. package/dist/index.js +3 -3
  129. package/dist/index.js.map +7 -1
  130. package/dist/issue.d.ts +40 -9
  131. package/dist/issue.js +2102 -1742
  132. package/dist/issue.js.map +7 -1
  133. package/dist/issue63History.test.js +40 -42
  134. package/dist/issue63History.test.js.map +7 -1
  135. package/dist/issue63Routes.test.js +154 -143
  136. package/dist/issue63Routes.test.js.map +7 -1
  137. package/dist/issueBatchUpdate.test.js +989 -885
  138. package/dist/issueBatchUpdate.test.js.map +7 -1
  139. package/dist/issueBlockerGuard.test.js +262 -226
  140. package/dist/issueBlockerGuard.test.js.map +7 -1
  141. package/dist/issueContract.d.ts +23 -4
  142. package/dist/issueContract.js +416 -395
  143. package/dist/issueContract.js.map +7 -1
  144. package/dist/issueContract.test.d.ts +4 -3
  145. package/dist/issueContract.test.js +358 -321
  146. package/dist/issueContract.test.js.map +7 -1
  147. package/dist/issueDates.test.js +235 -233
  148. package/dist/issueDates.test.js.map +7 -1
  149. package/dist/issueInfoReadback.test.js +304 -190
  150. package/dist/issueInfoReadback.test.js.map +7 -1
  151. package/dist/issueIntake.test.js +1938 -1732
  152. package/dist/issueIntake.test.js.map +7 -1
  153. package/dist/issueJournal.d.ts +40 -19
  154. package/dist/issueJournal.js +229 -138
  155. package/dist/issueJournal.js.map +7 -1
  156. package/dist/issueJournal.test.js +605 -422
  157. package/dist/issueJournal.test.js.map +7 -1
  158. package/dist/issueRollup.test.d.ts +1 -0
  159. package/dist/issueRollup.test.js +476 -0
  160. package/dist/issueRollup.test.js.map +7 -0
  161. package/dist/issueTracking.test.js +1059 -989
  162. package/dist/issueTracking.test.js.map +7 -1
  163. package/dist/issueWriteRecovery.test.d.ts +1 -0
  164. package/dist/issueWriteRecovery.test.js +260 -0
  165. package/dist/issueWriteRecovery.test.js.map +7 -0
  166. package/dist/lifecycle.test.js +112 -441
  167. package/dist/lifecycle.test.js.map +7 -1
  168. package/dist/logger.js +80 -74
  169. package/dist/logger.js.map +7 -1
  170. package/dist/mcp/index.js +116 -94
  171. package/dist/mcp/index.js.map +7 -1
  172. package/dist/mcp/tools.d.ts +252 -310
  173. package/dist/mcp/tools.js +235 -342
  174. package/dist/mcp/tools.js.map +7 -1
  175. package/dist/pluginAuthProbe.js +63 -52
  176. package/dist/pluginAuthProbe.js.map +7 -1
  177. package/dist/pluginAuthProbe.test.js +85 -62
  178. package/dist/pluginAuthProbe.test.js.map +7 -1
  179. package/dist/pluginCredentials.test.js +282 -259
  180. package/dist/pluginCredentials.test.js.map +7 -1
  181. package/dist/pluginDoctor.test.js +653 -588
  182. package/dist/pluginDoctor.test.js.map +7 -1
  183. package/dist/pluginInstaller.d.ts +7 -5
  184. package/dist/pluginInstaller.js +1173 -1229
  185. package/dist/pluginInstaller.js.map +7 -1
  186. package/dist/pluginInstaller.test.js +1842 -1423
  187. package/dist/pluginInstaller.test.js.map +7 -1
  188. package/dist/pluginPackaging.test.js +417 -413
  189. package/dist/pluginPackaging.test.js.map +7 -1
  190. package/dist/pr.d.ts +114 -131
  191. package/dist/pr.js +1314 -1327
  192. package/dist/pr.js.map +7 -1
  193. package/dist/pr.test.js +967 -653
  194. package/dist/pr.test.js.map +7 -1
  195. package/dist/prAssociation.test.js +2419 -1788
  196. package/dist/prAssociation.test.js.map +7 -1
  197. package/dist/prDispatch.test.js +123 -89
  198. package/dist/prDispatch.test.js.map +7 -1
  199. package/dist/readView.d.ts +184 -0
  200. package/dist/readView.js +218 -0
  201. package/dist/readView.js.map +7 -0
  202. package/dist/readView.test.d.ts +1 -0
  203. package/dist/readView.test.js +146 -0
  204. package/dist/readView.test.js.map +7 -0
  205. package/dist/releaseReconciliation.test.js +267 -288
  206. package/dist/releaseReconciliation.test.js.map +7 -1
  207. package/dist/releaseWorkflow.test.js +2493 -422
  208. package/dist/releaseWorkflow.test.js.map +7 -1
  209. package/dist/review.d.ts +738 -2
  210. package/dist/review.js +601 -348
  211. package/dist/review.js.map +7 -1
  212. package/dist/review.test.js +1218 -812
  213. package/dist/review.test.js.map +7 -1
  214. package/dist/reviewSubmit.test.d.ts +1 -0
  215. package/dist/reviewSubmit.test.js +747 -0
  216. package/dist/reviewSubmit.test.js.map +7 -0
  217. package/dist/services/agentReadinessService.js +42 -37
  218. package/dist/services/agentReadinessService.js.map +7 -1
  219. package/dist/services/blockerGuardService.js +188 -188
  220. package/dist/services/blockerGuardService.js.map +7 -1
  221. package/dist/services/boardReconcileService.d.ts +125 -125
  222. package/dist/services/boardReconcileService.js +1295 -1421
  223. package/dist/services/boardReconcileService.js.map +7 -1
  224. package/dist/services/deliveryHealthService.js +197 -199
  225. package/dist/services/deliveryHealthService.js.map +7 -1
  226. package/dist/services/legacyIssueMigration.js +263 -277
  227. package/dist/services/legacyIssueMigration.js.map +7 -1
  228. package/dist/stagedChecks.test.js +396 -194
  229. package/dist/stagedChecks.test.js.map +7 -1
  230. package/dist/start.test.js +99 -95
  231. package/dist/start.test.js.map +7 -1
  232. package/dist/stdoutRegression.test.js +321 -358
  233. package/dist/stdoutRegression.test.js.map +7 -1
  234. package/dist/targetPolicyDiscovery.test.js +141 -143
  235. package/dist/targetPolicyDiscovery.test.js.map +7 -1
  236. package/dist/targetPolicyEntrypoints.test.js +308 -269
  237. package/dist/targetPolicyEntrypoints.test.js.map +7 -1
  238. package/dist/targetPolicyLocal.test.js +580 -1051
  239. package/dist/targetPolicyLocal.test.js.map +7 -1
  240. package/dist/targetPolicyRoutes.test.js +274 -281
  241. package/dist/targetPolicyRoutes.test.js.map +7 -1
  242. package/dist/targetRepositoryExecution.test.d.ts +1 -0
  243. package/dist/targetRepositoryExecution.test.js +451 -0
  244. package/dist/targetRepositoryExecution.test.js.map +7 -0
  245. package/dist/terminalMessages.js +41 -35
  246. package/dist/terminalMessages.js.map +7 -1
  247. package/dist/toolOutput.d.ts +2 -0
  248. package/dist/toolOutput.js +36 -0
  249. package/dist/toolOutput.js.map +7 -0
  250. package/dist/toolOutput.test.d.ts +1 -0
  251. package/dist/toolOutput.test.js +240 -0
  252. package/dist/toolOutput.test.js.map +7 -0
  253. package/dist/utils/atomicJson.d.ts +0 -2
  254. package/dist/utils/atomicJson.js +81 -77
  255. package/dist/utils/atomicJson.js.map +7 -1
  256. package/dist/utils/filesystem.d.ts +0 -8
  257. package/dist/utils/filesystem.js +5 -19
  258. package/dist/utils/filesystem.js.map +7 -1
  259. package/dist/utils/lockfile.js +68 -71
  260. package/dist/utils/lockfile.js.map +7 -1
  261. package/dist/verification.d.ts +1 -54
  262. package/dist/verification.js +976 -1941
  263. package/dist/verification.js.map +7 -1
  264. package/dist/verificationGate.test.js +127 -117
  265. package/dist/verificationGate.test.js.map +7 -1
  266. package/dist/version.js +45 -24
  267. package/dist/version.js.map +7 -1
  268. package/package.json +9 -8
  269. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  270. package/plugins/ai-delivery/README.md +47 -156
  271. package/plugins/ai-delivery/plugin.json +1 -1
  272. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
  273. package/plugins/ai-delivery/runtime/dist/cli.js +351 -115
  274. package/plugins/ai-delivery/runtime/package.json +1 -1
  275. package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
  276. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
  277. package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
  278. package/dist/investigationCompletion.test.js +0 -728
  279. package/dist/investigationCompletion.test.js.map +0 -1
  280. package/dist/services/deliveryAdmission.d.ts +0 -49
  281. package/dist/services/deliveryAdmission.js +0 -165
  282. package/dist/services/deliveryAdmission.js.map +0 -1
  283. package/dist/services/worktreeRegistry.d.ts +0 -434
  284. package/dist/services/worktreeRegistry.js +0 -1248
  285. package/dist/services/worktreeRegistry.js.map +0 -1
  286. package/dist/setup.d.ts +0 -60
  287. package/dist/setup.js +0 -585
  288. package/dist/setup.js.map +0 -1
  289. package/dist/setup.test.js +0 -3329
  290. package/dist/setup.test.js.map +0 -1
  291. package/dist/worktree.d.ts +0 -28
  292. package/dist/worktree.js +0 -188
  293. package/dist/worktree.js.map +0 -1
  294. package/dist/worktreeTransition.d.ts +0 -211
  295. package/dist/worktreeTransition.js +0 -1037
  296. package/dist/worktreeTransition.js.map +0 -1
  297. package/dist/worktreeTransition.test.js +0 -1191
  298. package/dist/worktreeTransition.test.js.map +0 -1
  299. /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
  300. /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
  301. /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
@@ -1,92 +1,94 @@
1
- import { CollectionLimitError, DeliveryError } from '../errors.js';
2
- export const PROJECT_DELIVERY_STATUSES = ['Todo', 'In Progress', 'Blocked', 'Done'];
3
- export async function archiveIssueProjectItem(input) {
4
- const configuration = input.configuration ??
5
- (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)
13
- return null;
14
- if (item.archived)
15
- return { archived: true, itemId: item.id };
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
- `, { itemId: item.id, projectId: configuration.projectId });
23
- const record = requireRecord(response, 'GitHub returned invalid Project archive evidence.');
24
- const payload = requireRecord(record.archiveProjectV2Item, 'GitHub omitted Project archive payload.');
25
- const archivedItem = requireRecord(payload.item, 'GitHub omitted the archived Project item.');
26
- if (archivedItem.id !== item.id || archivedItem.isArchived !== true) {
27
- throw new DeliveryError('Project archive mutation did not return the exact archived item.');
28
- }
29
- await readBackProjectArchiveState({
30
- archived: true,
31
- configuration,
32
- graphql: input.graphql,
33
- issueNodeId: input.issueNodeId,
34
- itemId: item.id,
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
- return { archived: true, itemId: item.id };
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
- export async function getIssueProjectStatus(input) {
39
- const configuration = input.configuration ??
40
- (await getProjectDeliveryConfiguration({ ...input, settings: requireProjectSettings(input.settings) }));
41
- let item = await findIssueProjectItem({ ...input, configuration });
42
- if (item === null || item.archived)
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
- export async function getProjectDeliveryConfiguration(input) {
63
- const settings = requireProjectSettings(input.settings);
64
- const project = await readProjectDeliveryDefinition({
65
- graphql: input.graphql,
66
- org: input.org,
67
- number: settings.number,
68
- ...(input.maxPages === undefined ? {} : { maxPages: input.maxPages }),
69
- });
70
- return resolveProjectDeliveryConfiguration(project, { requireWritable: input.requireWritable === true, settings });
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
- export async function readProjectDeliveryDefinition(input) {
73
- const nodes = [];
74
- let cursor = null;
75
- let hasNextPage = true;
76
- const seenCursors = new Set();
77
- const fieldIds = new Set();
78
- let project = null;
79
- let pages = 0;
80
- while (hasNextPage) {
81
- if (input.maxPages !== undefined && pages >= input.maxPages)
82
- throw new CollectionLimitError({
83
- collection: 'project-fields',
84
- pagesRequested: pages,
85
- rowsObserved: nodes.length,
86
- limit: input.maxPages,
87
- });
88
- pages++;
89
- const response = await input.graphql(`
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
- `, { cursor, number: input.number, org: input.org });
136
- const responseRecord = requireRecord(response, 'GitHub returned invalid delivery Project configuration.');
137
- if ('errors' in responseRecord)
138
- throw new DeliveryError('GitHub returned partial delivery Project evidence.');
139
- const organization = requireRecord(responseRecord.organization, `Organization ${input.org} is unavailable to the selected GitHub identity.`);
140
- const pageProject = requireRecord(organization.projectV2, `Expected organization Project #${String(input.number)}.`);
141
- const fields = requireRecord(pageProject.fields, 'GitHub omitted delivery Project fields.');
142
- const previousProject = project;
143
- if (previousProject !== null &&
144
- ['id', 'number', 'title', 'closed', 'viewerCanUpdate'].some((key) => previousProject[key] !== pageProject[key])) {
145
- throw new DeliveryError('Delivery Project identity changed while reading its field pages.');
146
- }
147
- if (!Array.isArray(fields.nodes)) {
148
- throw new DeliveryError('GitHub returned invalid delivery Project field nodes.');
149
- }
150
- for (const node of fields.nodes) {
151
- const field = requireRecord(node, 'GitHub returned an incomplete delivery Project field.');
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
- throw new DeliveryError('GitHub returned invalid delivery Project field nodes.');
156
+ throw new DeliveryError("GitHub returned invalid delivery Project field nodes.");
221
157
  }
222
- const statusField = requireExactlyOneField(fields.nodes, settings.statusField);
223
- const pointsField = requireBoundIssueField({
224
- expectedDatabaseId: settings.points.databaseId,
225
- expectedOptions: settings.points.values,
226
- fields: fields.nodes,
227
- name: settings.points.name,
228
- });
229
- const priorityField = requireBoundIssueField({
230
- expectedDatabaseId: settings.priority.databaseId,
231
- expectedOptions: settings.priority.values,
232
- fields: fields.nodes,
233
- name: settings.priority.name,
234
- });
235
- if (statusField.__typename !== 'ProjectV2SingleSelectField' || statusField.isIssueField !== false) {
236
- throw new DeliveryError('Project Status must be the sole Project-owned single-select workflow field.');
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
- const statusOptions = readOptions(statusField.options, `Project ${settings.statusField}`);
239
- assertExactOptionSet({
240
- expected: PROJECT_DELIVERY_STATUSES.map((status) => settings.statuses[status]),
241
- fieldName: `Project ${settings.statusField}`,
242
- options: statusOptions,
243
- });
244
- const statusOptionIds = Object.fromEntries(PROJECT_DELIVERY_STATUSES.map((status) => [
245
- status,
246
- statusOptions.find((option) => option.name === settings.statuses[status])?.id,
247
- ]));
248
- return {
249
- pointsFieldId: requireString(pointsField.id, 'GitHub omitted the Project Points field id.'),
250
- priorityFieldId: requireString(priorityField.id, 'GitHub omitted the Project Priority field id.'),
251
- projectId,
252
- projectNumber: settings.number,
253
- settings,
254
- statusFieldId: requireString(statusField.id, 'GitHub omitted the Project Status field id.'),
255
- statusOptionIds,
256
- title: settings.title,
257
- writable: project.viewerCanUpdate === true,
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
- export async function restoreIssueProjectItem(input) {
261
- const configuration = input.configuration ??
262
- (await getProjectDeliveryConfiguration({
263
- ...input,
264
- settings: requireProjectSettings(input.settings),
265
- requireWritable: true,
266
- }));
267
- assertWritableConfiguration(configuration);
268
- const item = await findIssueProjectItem({ ...input, configuration });
269
- if (item === null)
270
- return null;
271
- if (!item.archived)
272
- return { archived: false, itemId: item.id };
273
- const response = await input.graphql(`
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
- `, { itemId: item.id, projectId: configuration.projectId });
280
- const record = requireRecord(response, 'GitHub returned invalid Project restore evidence.');
281
- const payload = requireRecord(record.unarchiveProjectV2Item, 'GitHub omitted Project restore payload.');
282
- const restoredItem = requireRecord(payload.item, 'GitHub omitted the restored Project item.');
283
- if (restoredItem.id !== item.id || restoredItem.isArchived !== false) {
284
- throw new DeliveryError('Project restore mutation did not return the exact active item.');
285
- }
286
- await readBackProjectArchiveState({
287
- archived: false,
288
- configuration,
289
- graphql: input.graphql,
290
- issueNodeId: input.issueNodeId,
291
- itemId: item.id,
292
- });
293
- return { archived: false, itemId: item.id };
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
- /** Read-only preflight; the later synchronization still checks for archive races. */
296
- export async function assertIssueProjectWritable(input) {
297
- const configuration = input.configuration ??
298
- (await getProjectDeliveryConfiguration({
299
- ...input,
300
- settings: requireProjectSettings(input.settings),
301
- requireWritable: true,
302
- }));
303
- assertWritableConfiguration(configuration);
304
- const item = await findIssueProjectItem({ ...input, configuration });
305
- if (item?.archived === true)
306
- throw new DeliveryError('The issue delivery Project item is archived and cannot be updated.');
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
- /** Add only membership and verify the exact unarchived item; Status is never written here. */
309
- export async function ensureIssueProjectMembership(input) {
310
- const configuration = input.configuration ??
311
- (await getProjectDeliveryConfiguration({
312
- ...input,
313
- settings: requireProjectSettings(input.settings),
314
- requireWritable: true,
315
- }));
316
- assertWritableConfiguration(configuration);
317
- const existing = await findIssueProjectItem({ ...input, configuration, refuseUnreadable: true });
318
- if (existing?.archived)
319
- throw new DeliveryError('The issue delivery Project item is archived and cannot be updated.');
320
- let itemId = existing?.id;
321
- if (itemId === undefined) {
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
- `, { contentId: input.issueNodeId, projectId: configuration.projectId });
330
- const added = requireRecord(response, 'GitHub returned invalid Project item creation evidence.');
331
- const payload = requireRecord(added.addProjectV2ItemById, 'GitHub omitted Project item creation payload.');
332
- const created = requireRecord(payload.item, 'GitHub omitted the created Project item.');
333
- itemId = requireString(created.id, 'GitHub omitted the created Project item id.');
334
- }
335
- // Retain mutation identity even if the exact readback is subsequently unavailable.
336
- input.onItemKnown?.(itemId);
337
- const item = await readProjectItem({ configuration, graphql: input.graphql, issueNodeId: input.issueNodeId, itemId });
338
- if (item.archived)
339
- throw new DeliveryError('Project membership readback is archived.');
340
- return { itemId, archived: false };
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
- export async function syncIssueProjectStatus(input) {
343
- const configuration = input.configuration ??
344
- (await getProjectDeliveryConfiguration({
345
- ...input,
346
- settings: requireProjectSettings(input.settings),
347
- requireWritable: true,
348
- }));
349
- assertWritableConfiguration(configuration);
350
- let item = await findIssueProjectItem({ ...input, configuration });
351
- if (item?.archived === true) {
352
- throw new DeliveryError('The issue delivery Project item is archived and cannot be updated.');
353
- }
354
- if (item !== null &&
355
- item.status !== null &&
356
- item.statusOptionId !== null &&
357
- requireItemStatus(item, configuration) === input.status) {
358
- return { itemId: item.id, status: input.status };
359
- }
360
- if (item === null) {
361
- const membership = await ensureIssueProjectMembership({ ...input, configuration });
362
- item = { archived: false, contentId: input.issueNodeId, id: membership.itemId, status: null, statusOptionId: null };
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
- fieldId: configuration.statusFieldId,
381
- itemId: item.id,
382
- optionId,
383
- projectId: configuration.projectId,
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
- return await readBackProjectItem({
392
- configuration,
393
- graphql: input.graphql,
394
- issueNodeId: input.issueNodeId,
395
- itemId: item.id,
396
- status: input.status,
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
- if (input.hasNextPage && input.nextCursor === null) {
401
- throw new DeliveryError(`Delivery Project ${input.surface} pagination omitted its next cursor.`);
402
- }
403
- if (input.hasNextPage &&
404
- input.nextCursor !== null &&
405
- (input.nextCursor === input.cursor || input.seenCursors.has(input.nextCursor))) {
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
- const observed = input.options.map((option) => option.name);
411
- const observedSet = new Set(observed);
412
- const expectedSet = new Set(input.expected);
413
- if (observedSet.size !== observed.length ||
414
- observedSet.size !== expectedSet.size ||
415
- observed.some((option) => !expectedSet.has(option))) {
416
- throw new DeliveryError(`${input.fieldName} options must be exactly ${input.expected.join(', ')} (order is provider-owned).`);
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
- if (!configuration.writable) {
421
- throw new DeliveryError(`Organization Project #${String(configuration.projectNumber)} is not writable by this identity.`);
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
- const nodes = [];
426
- let cursor = null;
427
- let hasNextPage = true;
428
- const seenCursors = new Set();
429
- let pages = 0;
430
- if (input.maxPages !== undefined && (!Number.isSafeInteger(input.maxPages) || input.maxPages <= 0))
431
- throw new DeliveryError('Project item page budget must be positive.');
432
- while (hasNextPage) {
433
- if (input.maxPages !== undefined && pages >= input.maxPages)
434
- throw new CollectionLimitError({
435
- collection: 'project-items',
436
- pagesRequested: pages,
437
- rowsObserved: nodes.length,
438
- limit: input.maxPages,
439
- });
440
- pages++;
441
- const response = await input.graphql(`
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
- cursor,
463
- number: input.configuration.projectNumber,
464
- org: input.org,
465
- statusField: input.configuration.settings.statusField,
466
- });
467
- const record = requireRecord(response, 'GitHub returned invalid delivery Project item evidence.');
468
- if (input.strictProjection && 'errors' in record)
469
- throw new DeliveryError('GitHub returned partial Project item evidence.');
470
- const organization = requireRecord(record.organization, 'GitHub omitted the delivery Project organization.');
471
- const project = requireRecord(organization.projectV2, 'GitHub omitted the delivery Project.');
472
- if ((input.capacityRead || input.strictProjection) &&
473
- (project.id !== input.configuration.projectId || project.number !== input.configuration.projectNumber))
474
- throw new DeliveryError('WIP capacity Project identity disagrees with the configured Project.');
475
- const items = requireRecord(project.items, 'GitHub omitted delivery Project items.');
476
- if (!Array.isArray(items.nodes)) {
477
- throw new DeliveryError('GitHub returned invalid delivery Project items.');
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
- return nodes;
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
- const matches = [];
494
- for (const raw of await fetchProjectDeliveryItemNodes(input)) {
495
- if (input.refuseUnreadable && (!isRecord(raw) || raw.content === null || raw.content === undefined))
496
- throw new DeliveryError('Project membership is unreadable; absence cannot be proved.');
497
- const item = parseProjectItem(raw, input.configuration, input.capacityRead);
498
- if (item?.contentId === input.issueNodeId)
499
- matches.push(item);
500
- }
501
- if (matches.length > 1)
502
- throw new DeliveryError(`Issue has ${String(matches.length)} duplicate Project items in ${input.configuration.title}.`);
503
- return matches[0] ?? null;
504
- }
505
- /** Complete, strict reconciliation projection over the same Project pagination owner. */
506
- export async function readProjectDeliveryItems(input) {
507
- const observations = [];
508
- const ids = new Set();
509
- for (const raw of await fetchProjectDeliveryItemNodes({ ...input, strictProjection: true })) {
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
- ids.add(item.id);
535
- const identity = {
536
- ...item,
537
- projectId: input.configuration.projectId,
538
- projectNumber: input.configuration.projectNumber,
539
- statusRead,
540
- statusName,
541
- };
542
- if (kind === 'Issue') {
543
- const repository = requireString(requireRecord(content.repository, 'Project issue repository is unreadable.').nameWithOwner, 'Project issue repository is missing.');
544
- if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(repository) ||
545
- !Number.isSafeInteger(content.number) ||
546
- Number(content.number) <= 0)
547
- throw new DeliveryError('Project issue identity is invalid.');
548
- observations.push({ ...identity, contentKind: 'issue', repository, issueNumber: Number(content.number) });
549
- }
550
- else
551
- observations.push({ ...identity, contentKind: kind === 'DraftIssue' ? 'draft' : 'pull-request' });
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
- return observations;
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
- return typeof value === 'object' && value !== null && !Array.isArray(value);
604
+ return typeof value === "object" && value !== null && !Array.isArray(value);
557
605
  }
558
606
  function parseProjectItem(raw, configuration, capacityRead = false) {
559
- const item = requireRecord(raw, 'GitHub returned an invalid delivery Project item.');
560
- if (capacityRead && (typeof item.isArchived !== 'boolean' || item.fieldValueByName === undefined))
561
- throw new DeliveryError('WIP capacity Project status or archive evidence is missing.');
562
- const content = item.content;
563
- if (capacityRead && !item.isArchived && (content === null || content === undefined))
564
- throw new DeliveryError('WIP capacity Project item content is unreadable.');
565
- if (content === null || content === undefined)
566
- return null;
567
- const contentRecord = requireRecord(content, 'GitHub returned an invalid delivery Project item content node.');
568
- const contentId = requireString(contentRecord.id, 'GitHub omitted a delivery Project item content id.');
569
- const fieldValue = item.fieldValueByName;
570
- let status = null;
571
- let statusOptionId = null;
572
- if (fieldValue !== null && fieldValue !== undefined) {
573
- const statusRecord = requireRecord(fieldValue, 'GitHub returned invalid Project Status readback.');
574
- const name = requireString(statusRecord.name, 'GitHub omitted Project Status name.');
575
- const optionId = requireString(statusRecord.optionId, 'GitHub omitted Project Status option id.');
576
- const statuses = configuration.settings.statuses;
577
- const canonicalStatus = PROJECT_DELIVERY_STATUSES.find((candidate) => statuses[candidate] === name);
578
- if (canonicalStatus === undefined || configuration.statusOptionIds[canonicalStatus] !== optionId) {
579
- throw new DeliveryError(`GitHub returned unsupported Project Status ${name}.`);
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
- return {
585
- archived: item.isArchived === true,
586
- contentId,
587
- id: requireString(item.id, 'GitHub omitted the delivery Project item id.'),
588
- status,
589
- statusOptionId,
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
- const response = await input.graphql(`
594
- query ${input.archived ? 'Archived' : 'Restored'}ProjectDeliveryItemReadback($itemId: ID!) {
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
- `, { itemId: input.itemId });
605
- const state = input.archived ? 'archived' : 'restored';
606
- const record = requireRecord(response, `GitHub returned invalid ${state} Project item readback.`);
607
- const node = requireRecord(record.node, `GitHub omitted ${state} Project item readback.`);
608
- const project = requireRecord(node.project, `GitHub omitted ${state} Project identity readback.`);
609
- const content = requireRecord(node.content, `GitHub omitted ${state} Project item content readback.`);
610
- if (node.id !== input.itemId ||
611
- node.isArchived !== input.archived ||
612
- project.id !== input.configuration.projectId ||
613
- project.number !== input.configuration.projectNumber ||
614
- content.id !== input.issueNodeId) {
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
- const item = await readProjectItem(input);
620
- if (item.archived ||
621
- item.status !== input.status ||
622
- item.statusOptionId !== input.configuration.statusOptionIds[input.status]) {
623
- throw new DeliveryError(`Project Status readback did not report ${input.status} for the exact issue item.`);
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
- const response = await input.graphql(`
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
- `, { itemId: input.itemId, statusField: input.configuration.settings.statusField });
643
- const record = requireRecord(response, 'GitHub returned invalid Project item readback.');
644
- const node = requireRecord(record.node, 'GitHub omitted Project item readback.');
645
- const project = requireRecord(node.project, 'GitHub omitted Project identity readback.');
646
- const content = requireRecord(node.content, 'GitHub omitted Project item content readback.');
647
- if (node.id !== input.itemId ||
648
- typeof node.isArchived !== 'boolean' ||
649
- project.id !== input.configuration.projectId ||
650
- project.number !== input.configuration.projectNumber ||
651
- content.id !== input.issueNodeId) {
652
- throw new DeliveryError('Project Status readback did not report the exact issue item.');
653
- }
654
- const item = parseProjectItem(node, input.configuration, input.capacityRead);
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
- if (!Array.isArray(raw)) {
661
- throw new DeliveryError(`${fieldName} options are malformed.`);
662
- }
663
- return raw.map((option) => {
664
- const record = requireRecord(option, `${fieldName} option is malformed.`);
665
- return {
666
- id: requireString(record.id, `${fieldName} option id is missing.`),
667
- name: requireString(record.name, `${fieldName} option name is missing.`),
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
- const field = requireExactlyOneField(input.fields, input.name);
673
- if (field.__typename !== 'ProjectV2SingleSelectField' || field.isIssueField !== true) {
674
- throw new DeliveryError(`Project ${input.name} must bind the organization issue field.`);
675
- }
676
- if (Array.isArray(field.options) && field.options.length !== 0) {
677
- throw new DeliveryError(`Project ${input.name} must not define Project-owned duplicate options.`);
678
- }
679
- const issueField = requireRecord(field.issueField, `Project ${input.name} omitted its bound organization issue field.`);
680
- const databaseId = typeof issueField.fullDatabaseId === 'string' ? issueField.fullDatabaseId : String(issueField.fullDatabaseId);
681
- if (issueField.__typename !== 'IssueFieldSingleSelect' ||
682
- issueField.name !== input.name ||
683
- databaseId !== input.expectedDatabaseId) {
684
- throw new DeliveryError(`Project ${input.name} must bind organization issue field ${input.expectedDatabaseId}.`);
685
- }
686
- assertExactOptionSet({
687
- expected: input.expectedOptions,
688
- fieldName: input.name,
689
- options: readOptions(issueField.options, `organization ${input.name}`),
690
- });
691
- return field;
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
- const matches = fields.filter((field) => isRecord(field) && field.name === name);
695
- if (matches.length !== 1) {
696
- throw new DeliveryError(`Expected exactly one Project ${name} field, found ${String(matches.length)}.`);
697
- }
698
- return matches[0];
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
- if (item.status === null ||
702
- item.statusOptionId === null ||
703
- configuration.statusOptionIds[item.status] !== item.statusOptionId) {
704
- throw new DeliveryError('The issue delivery Project item has no canonical Project Status.');
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
- if (!isRecord(value))
710
- throw new DeliveryError(message);
711
- return value;
753
+ if (!isRecord(value)) throw new DeliveryError(message);
754
+ return value;
712
755
  }
713
756
  function requireString(value, message) {
714
- if (typeof value !== 'string' || value.length === 0)
715
- throw new DeliveryError(message);
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
- if (settings === undefined)
720
- throw new DeliveryError('Project delivery settings are required.');
721
- return settings;
761
+ if (settings === void 0) throw new DeliveryError("Project delivery settings are required.");
762
+ return settings;
722
763
  }
723
- //# sourceMappingURL=projectDelivery.js.map
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