@ghx-dev/core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/dist/agent.d.ts +32 -7
- package/dist/agent.js +29 -12
- package/dist/agent.js.map +1 -1
- package/dist/{chunk-JH6GM6XU.js → chunk-OL4ARD3R.js} +116 -7
- package/dist/chunk-OL4ARD3R.js.map +1 -0
- package/dist/chunk-PJ2JKKQE.js +4148 -0
- package/dist/chunk-PJ2JKKQE.js.map +1 -0
- package/dist/{chunk-4PLVKNCF.js → chunk-SCIJMW5P.js} +14 -4
- package/dist/chunk-SCIJMW5P.js.map +1 -0
- package/dist/cli/assets/skills/ghx/SKILL.md +57 -0
- package/dist/cli/index.js +373 -41
- package/dist/cli/index.js.map +1 -1
- package/dist/{core/contracts/envelope.d.ts → envelope-BpF6MNCv.d.ts} +15 -3
- package/dist/index.d.ts +470 -22
- package/dist/index.js +6 -30
- package/package.json +11 -9
- package/dist/agent-interface/prompt/main-skill.d.ts +0 -3
- package/dist/agent-interface/prompt/main-skill.js +0 -7
- package/dist/agent-interface/prompt/main-skill.js.map +0 -1
- package/dist/agent-interface/tools/execute-tool.d.ts +0 -16
- package/dist/agent-interface/tools/execute-tool.js +0 -7
- package/dist/agent-interface/tools/execute-tool.js.map +0 -1
- package/dist/agent-interface/tools/explain-tool.d.ts +0 -11
- package/dist/agent-interface/tools/explain-tool.js +0 -9
- package/dist/agent-interface/tools/explain-tool.js.map +0 -1
- package/dist/agent-interface/tools/list-capabilities-tool.d.ts +0 -7
- package/dist/agent-interface/tools/list-capabilities-tool.js +0 -9
- package/dist/agent-interface/tools/list-capabilities-tool.js.map +0 -1
- package/dist/chunk-22WWCK6A.js +0 -92
- package/dist/chunk-22WWCK6A.js.map +0 -1
- package/dist/chunk-2W4L5YCC.js +0 -116
- package/dist/chunk-2W4L5YCC.js.map +0 -1
- package/dist/chunk-3MRJX72M.js +0 -209
- package/dist/chunk-3MRJX72M.js.map +0 -1
- package/dist/chunk-4PLVKNCF.js.map +0 -1
- package/dist/chunk-573MDG3I.js +0 -18
- package/dist/chunk-573MDG3I.js.map +0 -1
- package/dist/chunk-5JRLVOF2.js +0 -50
- package/dist/chunk-5JRLVOF2.js.map +0 -1
- package/dist/chunk-B6RLMKS4.js +0 -41
- package/dist/chunk-B6RLMKS4.js.map +0 -1
- package/dist/chunk-D746VR3B.js +0 -38
- package/dist/chunk-D746VR3B.js.map +0 -1
- package/dist/chunk-DJIEG6K7.js +0 -20
- package/dist/chunk-DJIEG6K7.js.map +0 -1
- package/dist/chunk-DLKIQBK6.js +0 -106
- package/dist/chunk-DLKIQBK6.js.map +0 -1
- package/dist/chunk-EBRDO4Y6.js +0 -31
- package/dist/chunk-EBRDO4Y6.js.map +0 -1
- package/dist/chunk-FXN6IIT5.js +0 -14
- package/dist/chunk-FXN6IIT5.js.map +0 -1
- package/dist/chunk-GMTG7X2L.js +0 -16
- package/dist/chunk-GMTG7X2L.js.map +0 -1
- package/dist/chunk-HQ2VRCH7.js +0 -42
- package/dist/chunk-HQ2VRCH7.js.map +0 -1
- package/dist/chunk-JH6GM6XU.js.map +0 -1
- package/dist/chunk-JLDU462R.js +0 -1352
- package/dist/chunk-JLDU462R.js.map +0 -1
- package/dist/chunk-MGNGSGMF.js +0 -203
- package/dist/chunk-MGNGSGMF.js.map +0 -1
- package/dist/chunk-NFF5VF4U.js +0 -28
- package/dist/chunk-NFF5VF4U.js.map +0 -1
- package/dist/chunk-QEAMC4IJ.js +0 -34
- package/dist/chunk-QEAMC4IJ.js.map +0 -1
- package/dist/chunk-QZZC53HF.js +0 -38
- package/dist/chunk-QZZC53HF.js.map +0 -1
- package/dist/chunk-RUQXGZ35.js +0 -34
- package/dist/chunk-RUQXGZ35.js.map +0 -1
- package/dist/chunk-SA2D4A5U.js +0 -1496
- package/dist/chunk-SA2D4A5U.js.map +0 -1
- package/dist/chunk-SD7U4BNA.js +0 -174
- package/dist/chunk-SD7U4BNA.js.map +0 -1
- package/dist/chunk-SJR2SACI.js +0 -30
- package/dist/chunk-SJR2SACI.js.map +0 -1
- package/dist/chunk-TCLMLVUQ.js +0 -38
- package/dist/chunk-TCLMLVUQ.js.map +0 -1
- package/dist/chunk-TDTKOJKN.js +0 -52
- package/dist/chunk-TDTKOJKN.js.map +0 -1
- package/dist/chunk-UGWIZ3RI.js +0 -7
- package/dist/chunk-UGWIZ3RI.js.map +0 -1
- package/dist/chunk-UOJWOHRM.js +0 -16
- package/dist/chunk-UOJWOHRM.js.map +0 -1
- package/dist/chunk-VD5NXQP7.js +0 -42
- package/dist/chunk-VD5NXQP7.js.map +0 -1
- package/dist/chunk-W2TKG2UL.js +0 -37
- package/dist/chunk-W2TKG2UL.js.map +0 -1
- package/dist/chunk-W6ROKCY5.js +0 -28
- package/dist/chunk-W6ROKCY5.js.map +0 -1
- package/dist/chunk-XNMM64WU.js +0 -221
- package/dist/chunk-XNMM64WU.js.map +0 -1
- package/dist/cli/commands/capabilities-explain.d.ts +0 -3
- package/dist/cli/commands/capabilities-explain.js +0 -10
- package/dist/cli/commands/capabilities-explain.js.map +0 -1
- package/dist/cli/commands/capabilities-list.d.ts +0 -3
- package/dist/cli/commands/capabilities-list.js +0 -10
- package/dist/cli/commands/capabilities-list.js.map +0 -1
- package/dist/cli/commands/doctor.d.ts +0 -3
- package/dist/cli/commands/doctor.js +0 -7
- package/dist/cli/commands/doctor.js.map +0 -1
- package/dist/cli/commands/routes.d.ts +0 -3
- package/dist/cli/commands/routes.js +0 -7
- package/dist/cli/commands/routes.js.map +0 -1
- package/dist/cli/commands/run.d.ts +0 -3
- package/dist/cli/commands/run.js +0 -31
- package/dist/cli/commands/run.js.map +0 -1
- package/dist/cli/commands/setup.d.ts +0 -3
- package/dist/cli/commands/setup.js +0 -7
- package/dist/cli/commands/setup.js.map +0 -1
- package/dist/cli/formatters/json.d.ts +0 -3
- package/dist/cli/formatters/json.js +0 -8
- package/dist/cli/formatters/json.js.map +0 -1
- package/dist/cli/formatters/table.d.ts +0 -3
- package/dist/cli/formatters/table.js +0 -8
- package/dist/cli/formatters/table.js.map +0 -1
- package/dist/core/contracts/envelope.js +0 -1
- package/dist/core/contracts/envelope.js.map +0 -1
- package/dist/core/contracts/task.d.ts +0 -7
- package/dist/core/contracts/task.js +0 -1
- package/dist/core/contracts/task.js.map +0 -1
- package/dist/core/contracts/tasks/check_run.annotations.list.d.ts +0 -5
- package/dist/core/contracts/tasks/check_run.annotations.list.js +0 -8
- package/dist/core/contracts/tasks/check_run.annotations.list.js.map +0 -1
- package/dist/core/contracts/tasks/issue.assignees.update.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.assignees.update.js +0 -8
- package/dist/core/contracts/tasks/issue.assignees.update.js.map +0 -1
- package/dist/core/contracts/tasks/issue.blocked_by.add.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.blocked_by.add.js +0 -8
- package/dist/core/contracts/tasks/issue.blocked_by.add.js.map +0 -1
- package/dist/core/contracts/tasks/issue.blocked_by.remove.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.blocked_by.remove.js +0 -8
- package/dist/core/contracts/tasks/issue.blocked_by.remove.js.map +0 -1
- package/dist/core/contracts/tasks/issue.close.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.close.js +0 -8
- package/dist/core/contracts/tasks/issue.close.js.map +0 -1
- package/dist/core/contracts/tasks/issue.comments.create.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.comments.create.js +0 -8
- package/dist/core/contracts/tasks/issue.comments.create.js.map +0 -1
- package/dist/core/contracts/tasks/issue.comments.list.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.comments.list.js +0 -8
- package/dist/core/contracts/tasks/issue.comments.list.js.map +0 -1
- package/dist/core/contracts/tasks/issue.create.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.create.js +0 -8
- package/dist/core/contracts/tasks/issue.create.js.map +0 -1
- package/dist/core/contracts/tasks/issue.delete.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.delete.js +0 -8
- package/dist/core/contracts/tasks/issue.delete.js.map +0 -1
- package/dist/core/contracts/tasks/issue.labels.update.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.labels.update.js +0 -8
- package/dist/core/contracts/tasks/issue.labels.update.js.map +0 -1
- package/dist/core/contracts/tasks/issue.linked_prs.list.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.linked_prs.list.js +0 -8
- package/dist/core/contracts/tasks/issue.linked_prs.list.js.map +0 -1
- package/dist/core/contracts/tasks/issue.list.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.list.js +0 -8
- package/dist/core/contracts/tasks/issue.list.js.map +0 -1
- package/dist/core/contracts/tasks/issue.milestone.set.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.milestone.set.js +0 -8
- package/dist/core/contracts/tasks/issue.milestone.set.js.map +0 -1
- package/dist/core/contracts/tasks/issue.parent.remove.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.parent.remove.js +0 -8
- package/dist/core/contracts/tasks/issue.parent.remove.js.map +0 -1
- package/dist/core/contracts/tasks/issue.parent.set.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.parent.set.js +0 -8
- package/dist/core/contracts/tasks/issue.parent.set.js.map +0 -1
- package/dist/core/contracts/tasks/issue.relations.get.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.relations.get.js +0 -8
- package/dist/core/contracts/tasks/issue.relations.get.js.map +0 -1
- package/dist/core/contracts/tasks/issue.reopen.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.reopen.js +0 -8
- package/dist/core/contracts/tasks/issue.reopen.js.map +0 -1
- package/dist/core/contracts/tasks/issue.update.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.update.js +0 -8
- package/dist/core/contracts/tasks/issue.update.js.map +0 -1
- package/dist/core/contracts/tasks/issue.view.d.ts +0 -5
- package/dist/core/contracts/tasks/issue.view.js +0 -8
- package/dist/core/contracts/tasks/issue.view.js.map +0 -1
- package/dist/core/contracts/tasks/pr.assignees.update.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.assignees.update.js +0 -8
- package/dist/core/contracts/tasks/pr.assignees.update.js.map +0 -1
- package/dist/core/contracts/tasks/pr.branch.update.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.branch.update.js +0 -8
- package/dist/core/contracts/tasks/pr.branch.update.js.map +0 -1
- package/dist/core/contracts/tasks/pr.checks.get_failed.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.checks.get_failed.js +0 -8
- package/dist/core/contracts/tasks/pr.checks.get_failed.js.map +0 -1
- package/dist/core/contracts/tasks/pr.checks.rerun_all.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.checks.rerun_all.js +0 -8
- package/dist/core/contracts/tasks/pr.checks.rerun_all.js.map +0 -1
- package/dist/core/contracts/tasks/pr.checks.rerun_failed.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.checks.rerun_failed.js +0 -8
- package/dist/core/contracts/tasks/pr.checks.rerun_failed.js.map +0 -1
- package/dist/core/contracts/tasks/pr.comment.reply.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.comment.reply.js +0 -8
- package/dist/core/contracts/tasks/pr.comment.reply.js.map +0 -1
- package/dist/core/contracts/tasks/pr.comment.resolve.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.comment.resolve.js +0 -8
- package/dist/core/contracts/tasks/pr.comment.resolve.js.map +0 -1
- package/dist/core/contracts/tasks/pr.comment.unresolve.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.comment.unresolve.js +0 -8
- package/dist/core/contracts/tasks/pr.comment.unresolve.js.map +0 -1
- package/dist/core/contracts/tasks/pr.comments.list.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.comments.list.js +0 -8
- package/dist/core/contracts/tasks/pr.comments.list.js.map +0 -1
- package/dist/core/contracts/tasks/pr.diff.list_files.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.diff.list_files.js +0 -8
- package/dist/core/contracts/tasks/pr.diff.list_files.js.map +0 -1
- package/dist/core/contracts/tasks/pr.list.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.list.js +0 -8
- package/dist/core/contracts/tasks/pr.list.js.map +0 -1
- package/dist/core/contracts/tasks/pr.merge.execute.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.merge.execute.js +0 -8
- package/dist/core/contracts/tasks/pr.merge.execute.js.map +0 -1
- package/dist/core/contracts/tasks/pr.mergeability.view.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.mergeability.view.js +0 -8
- package/dist/core/contracts/tasks/pr.mergeability.view.js.map +0 -1
- package/dist/core/contracts/tasks/pr.ready_for_review.set.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.ready_for_review.set.js +0 -8
- package/dist/core/contracts/tasks/pr.ready_for_review.set.js.map +0 -1
- package/dist/core/contracts/tasks/pr.review.submit_approve.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.review.submit_approve.js +0 -8
- package/dist/core/contracts/tasks/pr.review.submit_approve.js.map +0 -1
- package/dist/core/contracts/tasks/pr.review.submit_comment.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.review.submit_comment.js +0 -8
- package/dist/core/contracts/tasks/pr.review.submit_comment.js.map +0 -1
- package/dist/core/contracts/tasks/pr.review.submit_request_changes.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.review.submit_request_changes.js +0 -8
- package/dist/core/contracts/tasks/pr.review.submit_request_changes.js.map +0 -1
- package/dist/core/contracts/tasks/pr.reviewers.request.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.reviewers.request.js +0 -8
- package/dist/core/contracts/tasks/pr.reviewers.request.js.map +0 -1
- package/dist/core/contracts/tasks/pr.reviews.list.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.reviews.list.js +0 -8
- package/dist/core/contracts/tasks/pr.reviews.list.js.map +0 -1
- package/dist/core/contracts/tasks/pr.status.checks.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.status.checks.js +0 -8
- package/dist/core/contracts/tasks/pr.status.checks.js.map +0 -1
- package/dist/core/contracts/tasks/pr.view.d.ts +0 -5
- package/dist/core/contracts/tasks/pr.view.js +0 -8
- package/dist/core/contracts/tasks/pr.view.js.map +0 -1
- package/dist/core/contracts/tasks/project_v2.fields.list.d.ts +0 -5
- package/dist/core/contracts/tasks/project_v2.fields.list.js +0 -8
- package/dist/core/contracts/tasks/project_v2.fields.list.js.map +0 -1
- package/dist/core/contracts/tasks/project_v2.item.add_issue.d.ts +0 -5
- package/dist/core/contracts/tasks/project_v2.item.add_issue.js +0 -8
- package/dist/core/contracts/tasks/project_v2.item.add_issue.js.map +0 -1
- package/dist/core/contracts/tasks/project_v2.item.field.update.d.ts +0 -5
- package/dist/core/contracts/tasks/project_v2.item.field.update.js +0 -8
- package/dist/core/contracts/tasks/project_v2.item.field.update.js.map +0 -1
- package/dist/core/contracts/tasks/project_v2.items.list.d.ts +0 -5
- package/dist/core/contracts/tasks/project_v2.items.list.js +0 -8
- package/dist/core/contracts/tasks/project_v2.items.list.js.map +0 -1
- package/dist/core/contracts/tasks/project_v2.org.get.d.ts +0 -5
- package/dist/core/contracts/tasks/project_v2.org.get.js +0 -8
- package/dist/core/contracts/tasks/project_v2.org.get.js.map +0 -1
- package/dist/core/contracts/tasks/project_v2.user.get.d.ts +0 -5
- package/dist/core/contracts/tasks/project_v2.user.get.js +0 -8
- package/dist/core/contracts/tasks/project_v2.user.get.js.map +0 -1
- package/dist/core/contracts/tasks/release.create_draft.d.ts +0 -5
- package/dist/core/contracts/tasks/release.create_draft.js +0 -8
- package/dist/core/contracts/tasks/release.create_draft.js.map +0 -1
- package/dist/core/contracts/tasks/release.get.d.ts +0 -5
- package/dist/core/contracts/tasks/release.get.js +0 -8
- package/dist/core/contracts/tasks/release.get.js.map +0 -1
- package/dist/core/contracts/tasks/release.list.d.ts +0 -5
- package/dist/core/contracts/tasks/release.list.js +0 -8
- package/dist/core/contracts/tasks/release.list.js.map +0 -1
- package/dist/core/contracts/tasks/release.publish_draft.d.ts +0 -5
- package/dist/core/contracts/tasks/release.publish_draft.js +0 -8
- package/dist/core/contracts/tasks/release.publish_draft.js.map +0 -1
- package/dist/core/contracts/tasks/release.update.d.ts +0 -5
- package/dist/core/contracts/tasks/release.update.js +0 -8
- package/dist/core/contracts/tasks/release.update.js.map +0 -1
- package/dist/core/contracts/tasks/repo.issue_types.list.d.ts +0 -5
- package/dist/core/contracts/tasks/repo.issue_types.list.js +0 -8
- package/dist/core/contracts/tasks/repo.issue_types.list.js.map +0 -1
- package/dist/core/contracts/tasks/repo.labels.list.d.ts +0 -5
- package/dist/core/contracts/tasks/repo.labels.list.js +0 -8
- package/dist/core/contracts/tasks/repo.labels.list.js.map +0 -1
- package/dist/core/contracts/tasks/repo.view.d.ts +0 -5
- package/dist/core/contracts/tasks/repo.view.js +0 -8
- package/dist/core/contracts/tasks/repo.view.js.map +0 -1
- package/dist/core/contracts/tasks/workflow.get.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow.get.js +0 -8
- package/dist/core/contracts/tasks/workflow.get.js.map +0 -1
- package/dist/core/contracts/tasks/workflow.list.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow.list.js +0 -8
- package/dist/core/contracts/tasks/workflow.list.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_dispatch.run.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_dispatch.run.js +0 -8
- package/dist/core/contracts/tasks/workflow_dispatch.run.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_job.logs.analyze.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_job.logs.analyze.js +0 -8
- package/dist/core/contracts/tasks/workflow_job.logs.analyze.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_job.logs.get.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_job.logs.get.js +0 -8
- package/dist/core/contracts/tasks/workflow_job.logs.get.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_run.artifacts.list.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_run.artifacts.list.js +0 -8
- package/dist/core/contracts/tasks/workflow_run.artifacts.list.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_run.cancel.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_run.cancel.js +0 -8
- package/dist/core/contracts/tasks/workflow_run.cancel.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_run.get.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_run.get.js +0 -8
- package/dist/core/contracts/tasks/workflow_run.get.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_run.jobs.list.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_run.jobs.list.js +0 -8
- package/dist/core/contracts/tasks/workflow_run.jobs.list.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_run.rerun_all.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_run.rerun_all.js +0 -8
- package/dist/core/contracts/tasks/workflow_run.rerun_all.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_run.rerun_failed.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_run.rerun_failed.js +0 -8
- package/dist/core/contracts/tasks/workflow_run.rerun_failed.js.map +0 -1
- package/dist/core/contracts/tasks/workflow_runs.list.d.ts +0 -5
- package/dist/core/contracts/tasks/workflow_runs.list.js +0 -8
- package/dist/core/contracts/tasks/workflow_runs.list.js.map +0 -1
- package/dist/core/errors/codes.d.ts +0 -13
- package/dist/core/errors/codes.js +0 -7
- package/dist/core/errors/codes.js.map +0 -1
- package/dist/core/errors/map-error.d.ts +0 -5
- package/dist/core/errors/map-error.js +0 -8
- package/dist/core/errors/map-error.js.map +0 -1
- package/dist/core/errors/retryability.d.ts +0 -3
- package/dist/core/errors/retryability.js +0 -8
- package/dist/core/errors/retryability.js.map +0 -1
- package/dist/core/execute/execute.d.ts +0 -28
- package/dist/core/execute/execute.js +0 -11
- package/dist/core/execute/execute.js.map +0 -1
- package/dist/core/execution/adapters/cli-adapter.d.ts +0 -22
- package/dist/core/execution/adapters/cli-adapter.js +0 -69
- package/dist/core/execution/adapters/cli-adapter.js.map +0 -1
- package/dist/core/execution/adapters/cli-capability-adapter.d.ts +0 -16
- package/dist/core/execution/adapters/cli-capability-adapter.js +0 -11
- package/dist/core/execution/adapters/cli-capability-adapter.js.map +0 -1
- package/dist/core/execution/adapters/graphql-adapter.d.ts +0 -25
- package/dist/core/execution/adapters/graphql-adapter.js +0 -44
- package/dist/core/execution/adapters/graphql-adapter.js.map +0 -1
- package/dist/core/execution/adapters/graphql-capability-adapter.d.ts +0 -20
- package/dist/core/execution/adapters/graphql-capability-adapter.js +0 -11
- package/dist/core/execution/adapters/graphql-capability-adapter.js.map +0 -1
- package/dist/core/execution/adapters/rest-adapter.d.ts +0 -3
- package/dist/core/execution/adapters/rest-adapter.js +0 -8
- package/dist/core/execution/adapters/rest-adapter.js.map +0 -1
- package/dist/core/execution/cli/safe-runner.d.ts +0 -12
- package/dist/core/execution/cli/safe-runner.js +0 -7
- package/dist/core/execution/cli/safe-runner.js.map +0 -1
- package/dist/core/execution/normalizer.d.ts +0 -13
- package/dist/core/execution/normalizer.js +0 -9
- package/dist/core/execution/normalizer.js.map +0 -1
- package/dist/core/execution/preflight.d.ts +0 -24
- package/dist/core/execution/preflight.js +0 -8
- package/dist/core/execution/preflight.js.map +0 -1
- package/dist/core/registry/index.d.ts +0 -15
- package/dist/core/registry/index.js +0 -12
- package/dist/core/registry/index.js.map +0 -1
- package/dist/core/registry/operation-card-schema.d.ts +0 -167
- package/dist/core/registry/operation-card-schema.js +0 -7
- package/dist/core/registry/operation-card-schema.js.map +0 -1
- package/dist/core/registry/schema-validator.d.ts +0 -16
- package/dist/core/registry/schema-validator.js +0 -9
- package/dist/core/registry/schema-validator.js.map +0 -1
- package/dist/core/registry/types.d.ts +0 -51
- package/dist/core/registry/types.js +0 -1
- package/dist/core/registry/types.js.map +0 -1
- package/dist/core/routing/capability-registry.d.ts +0 -8
- package/dist/core/routing/capability-registry.js +0 -15
- package/dist/core/routing/capability-registry.js.map +0 -1
- package/dist/core/routing/engine.d.ts +0 -32
- package/dist/core/routing/engine.js +0 -23
- package/dist/core/routing/engine.js.map +0 -1
- package/dist/core/routing/policy.d.ts +0 -3
- package/dist/core/routing/policy.js +0 -7
- package/dist/core/routing/policy.js.map +0 -1
- package/dist/core/routing/reason-codes.d.ts +0 -4
- package/dist/core/routing/reason-codes.js +0 -15
- package/dist/core/routing/reason-codes.js.map +0 -1
- package/dist/core/telemetry/logger.d.ts +0 -8
- package/dist/core/telemetry/logger.js +0 -9
- package/dist/core/telemetry/logger.js.map +0 -1
- package/dist/core/telemetry/metrics.d.ts +0 -7
- package/dist/core/telemetry/metrics.js +0 -1
- package/dist/core/telemetry/metrics.js.map +0 -1
- package/dist/gql/client.d.ts +0 -314
- package/dist/gql/client.js +0 -19
- package/dist/gql/client.js.map +0 -1
- package/dist/gql/generated/common-types.d.ts +0 -36
- package/dist/gql/generated/common-types.js +0 -1
- package/dist/gql/generated/common-types.js.map +0 -1
- package/dist/gql/operations/issue-assignees-update.generated.d.ts +0 -33
- package/dist/gql/operations/issue-assignees-update.generated.js +0 -28
- package/dist/gql/operations/issue-assignees-update.generated.js.map +0 -1
- package/dist/gql/operations/issue-blocked-by-add.generated.d.ts +0 -30
- package/dist/gql/operations/issue-blocked-by-add.generated.js +0 -26
- package/dist/gql/operations/issue-blocked-by-add.generated.js.map +0 -1
- package/dist/gql/operations/issue-blocked-by-remove.generated.d.ts +0 -30
- package/dist/gql/operations/issue-blocked-by-remove.generated.js +0 -26
- package/dist/gql/operations/issue-blocked-by-remove.generated.js.map +0 -1
- package/dist/gql/operations/issue-close.generated.d.ts +0 -27
- package/dist/gql/operations/issue-close.generated.js +0 -25
- package/dist/gql/operations/issue-close.generated.js.map +0 -1
- package/dist/gql/operations/issue-comment-create.generated.d.ts +0 -31
- package/dist/gql/operations/issue-comment-create.generated.js +0 -27
- package/dist/gql/operations/issue-comment-create.generated.js.map +0 -1
- package/dist/gql/operations/issue-comments-list.generated.d.ts +0 -59
- package/dist/gql/operations/issue-comments-list.generated.js +0 -9
- package/dist/gql/operations/issue-comments-list.generated.js.map +0 -1
- package/dist/gql/operations/issue-create.generated.d.ts +0 -31
- package/dist/gql/operations/issue-create.generated.js +0 -27
- package/dist/gql/operations/issue-create.generated.js.map +0 -1
- package/dist/gql/operations/issue-delete.generated.d.ts +0 -22
- package/dist/gql/operations/issue-delete.generated.js +0 -21
- package/dist/gql/operations/issue-delete.generated.js.map +0 -1
- package/dist/gql/operations/issue-labels-update.generated.d.ts +0 -33
- package/dist/gql/operations/issue-labels-update.generated.js +0 -28
- package/dist/gql/operations/issue-labels-update.generated.js.map +0 -1
- package/dist/gql/operations/issue-linked-prs-list.generated.d.ts +0 -132
- package/dist/gql/operations/issue-linked-prs-list.generated.js +0 -39
- package/dist/gql/operations/issue-linked-prs-list.generated.js.map +0 -1
- package/dist/gql/operations/issue-list.generated.d.ts +0 -40
- package/dist/gql/operations/issue-list.generated.js +0 -9
- package/dist/gql/operations/issue-list.generated.js.map +0 -1
- package/dist/gql/operations/issue-milestone-set.generated.d.ts +0 -30
- package/dist/gql/operations/issue-milestone-set.generated.js +0 -26
- package/dist/gql/operations/issue-milestone-set.generated.js.map +0 -1
- package/dist/gql/operations/issue-parent-remove.generated.d.ts +0 -30
- package/dist/gql/operations/issue-parent-remove.generated.js +0 -26
- package/dist/gql/operations/issue-parent-remove.generated.js.map +0 -1
- package/dist/gql/operations/issue-parent-set.generated.d.ts +0 -30
- package/dist/gql/operations/issue-parent-set.generated.js +0 -26
- package/dist/gql/operations/issue-parent-set.generated.js.map +0 -1
- package/dist/gql/operations/issue-relations-get.generated.d.ts +0 -49
- package/dist/gql/operations/issue-relations-get.generated.js +0 -40
- package/dist/gql/operations/issue-relations-get.generated.js.map +0 -1
- package/dist/gql/operations/issue-reopen.generated.d.ts +0 -27
- package/dist/gql/operations/issue-reopen.generated.js +0 -25
- package/dist/gql/operations/issue-reopen.generated.js.map +0 -1
- package/dist/gql/operations/issue-update.generated.d.ts +0 -31
- package/dist/gql/operations/issue-update.generated.js +0 -27
- package/dist/gql/operations/issue-update.generated.js.map +0 -1
- package/dist/gql/operations/issue-view.generated.d.ts +0 -31
- package/dist/gql/operations/issue-view.generated.js +0 -9
- package/dist/gql/operations/issue-view.generated.js.map +0 -1
- package/dist/gql/operations/pr-comment-reply.generated.d.ts +0 -26
- package/dist/gql/operations/pr-comment-reply.generated.js +0 -25
- package/dist/gql/operations/pr-comment-reply.generated.js.map +0 -1
- package/dist/gql/operations/pr-comment-resolve.generated.d.ts +0 -26
- package/dist/gql/operations/pr-comment-resolve.generated.js +0 -24
- package/dist/gql/operations/pr-comment-resolve.generated.js.map +0 -1
- package/dist/gql/operations/pr-comment-unresolve.generated.d.ts +0 -26
- package/dist/gql/operations/pr-comment-unresolve.generated.js +0 -24
- package/dist/gql/operations/pr-comment-unresolve.generated.js.map +0 -1
- package/dist/gql/operations/pr-comments-list.generated.d.ts +0 -84
- package/dist/gql/operations/pr-comments-list.generated.js +0 -58
- package/dist/gql/operations/pr-comments-list.generated.js.map +0 -1
- package/dist/gql/operations/pr-diff-list-files.generated.d.ts +0 -42
- package/dist/gql/operations/pr-diff-list-files.generated.js +0 -9
- package/dist/gql/operations/pr-diff-list-files.generated.js.map +0 -1
- package/dist/gql/operations/pr-list.generated.d.ts +0 -40
- package/dist/gql/operations/pr-list.generated.js +0 -9
- package/dist/gql/operations/pr-list.generated.js.map +0 -1
- package/dist/gql/operations/pr-reviews-list.generated.d.ts +0 -64
- package/dist/gql/operations/pr-reviews-list.generated.js +0 -9
- package/dist/gql/operations/pr-reviews-list.generated.js.map +0 -1
- package/dist/gql/operations/pr-view.generated.d.ts +0 -31
- package/dist/gql/operations/pr-view.generated.js +0 -9
- package/dist/gql/operations/pr-view.generated.js.map +0 -1
- package/dist/gql/operations/repo-view.generated.d.ts +0 -33
- package/dist/gql/operations/repo-view.generated.js +0 -9
- package/dist/gql/operations/repo-view.generated.js.map +0 -1
- package/dist/shared/constants.d.ts +0 -3
- package/dist/shared/constants.js +0 -6
- package/dist/shared/constants.js.map +0 -1
- package/dist/shared/types.d.ts +0 -3
- package/dist/shared/types.js +0 -1
- package/dist/shared/types.js.map +0 -1
- package/dist/shared/utils.d.ts +0 -3
- package/dist/shared/utils.js +0 -8
- package/dist/shared/utils.js.map +0 -1
|
@@ -0,0 +1,4148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getOperationCard
|
|
3
|
+
} from "./chunk-OL4ARD3R.js";
|
|
4
|
+
|
|
5
|
+
// src/core/execution/cli/safe-runner.ts
|
|
6
|
+
import { spawn } from "child_process";
|
|
7
|
+
var DEFAULT_MAX_OUTPUT_BYTES = 1e6;
|
|
8
|
+
function createSafeCliCommandRunner(options) {
|
|
9
|
+
const maxOutputBytes = options?.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
|
|
10
|
+
return {
|
|
11
|
+
run(command, args, timeoutMs) {
|
|
12
|
+
if (timeoutMs <= 0) {
|
|
13
|
+
return Promise.reject(new Error("timeoutMs must be a positive number"));
|
|
14
|
+
}
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const child = spawn(command, args, {
|
|
17
|
+
shell: false,
|
|
18
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
19
|
+
});
|
|
20
|
+
const stdoutChunks = [];
|
|
21
|
+
const stderrChunks = [];
|
|
22
|
+
let stdoutSize = 0;
|
|
23
|
+
let stderrSize = 0;
|
|
24
|
+
let failureReason = null;
|
|
25
|
+
let settled = false;
|
|
26
|
+
const timer = setTimeout(() => {
|
|
27
|
+
if (failureReason === null) {
|
|
28
|
+
failureReason = "timeout";
|
|
29
|
+
}
|
|
30
|
+
child.kill("SIGKILL");
|
|
31
|
+
}, timeoutMs);
|
|
32
|
+
function settleError(error) {
|
|
33
|
+
if (settled) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
settled = true;
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
reject(error);
|
|
39
|
+
}
|
|
40
|
+
function settleSuccess(stdout, stderr, exitCode) {
|
|
41
|
+
if (settled) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
settled = true;
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
resolve({ stdout, stderr, exitCode });
|
|
47
|
+
}
|
|
48
|
+
child.stdout?.on("data", (chunk) => {
|
|
49
|
+
if (failureReason === "overflow") {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
stdoutSize += chunk.length;
|
|
53
|
+
if (stdoutSize + stderrSize > maxOutputBytes) {
|
|
54
|
+
if (failureReason === null) {
|
|
55
|
+
failureReason = "overflow";
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
child.kill("SIGKILL");
|
|
58
|
+
settleError(new Error(`CLI output exceeded ${maxOutputBytes} bytes`));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
child.kill("SIGKILL");
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
stdoutChunks.push(chunk);
|
|
65
|
+
});
|
|
66
|
+
child.stderr?.on("data", (chunk) => {
|
|
67
|
+
if (failureReason === "overflow") {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
stderrSize += chunk.length;
|
|
71
|
+
if (stdoutSize + stderrSize > maxOutputBytes) {
|
|
72
|
+
if (failureReason === null) {
|
|
73
|
+
failureReason = "overflow";
|
|
74
|
+
clearTimeout(timer);
|
|
75
|
+
child.kill("SIGKILL");
|
|
76
|
+
settleError(new Error(`CLI output exceeded ${maxOutputBytes} bytes`));
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
child.kill("SIGKILL");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
stderrChunks.push(chunk);
|
|
83
|
+
});
|
|
84
|
+
child.on("error", (error) => {
|
|
85
|
+
settleError(error);
|
|
86
|
+
});
|
|
87
|
+
child.on("close", (code) => {
|
|
88
|
+
if (failureReason === "timeout") {
|
|
89
|
+
settleError(new Error(`CLI command timed out after ${timeoutMs}ms`));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (failureReason === "overflow") {
|
|
93
|
+
settleError(new Error(`CLI output exceeded ${maxOutputBytes} bytes`));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
settleSuccess(
|
|
97
|
+
Buffer.concat(stdoutChunks).toString("utf8"),
|
|
98
|
+
Buffer.concat(stderrChunks).toString("utf8"),
|
|
99
|
+
code ?? 1
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/core/errors/codes.ts
|
|
108
|
+
var errorCodes = {
|
|
109
|
+
Auth: "AUTH",
|
|
110
|
+
NotFound: "NOT_FOUND",
|
|
111
|
+
Validation: "VALIDATION",
|
|
112
|
+
RateLimit: "RATE_LIMIT",
|
|
113
|
+
Network: "NETWORK",
|
|
114
|
+
Server: "SERVER",
|
|
115
|
+
AdapterUnsupported: "ADAPTER_UNSUPPORTED",
|
|
116
|
+
Unknown: "UNKNOWN"
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/core/execution/normalizer.ts
|
|
120
|
+
function buildMeta(route, options) {
|
|
121
|
+
const meta = {
|
|
122
|
+
capability_id: options.capabilityId,
|
|
123
|
+
route_used: route
|
|
124
|
+
};
|
|
125
|
+
if (options.reason !== void 0) {
|
|
126
|
+
meta.reason = options.reason;
|
|
127
|
+
}
|
|
128
|
+
if (options.pagination !== void 0) {
|
|
129
|
+
meta.pagination = options.pagination;
|
|
130
|
+
}
|
|
131
|
+
return meta;
|
|
132
|
+
}
|
|
133
|
+
function normalizeResult(data, route, options) {
|
|
134
|
+
return {
|
|
135
|
+
ok: true,
|
|
136
|
+
data,
|
|
137
|
+
meta: buildMeta(route, options)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function normalizeError(error, route, options) {
|
|
141
|
+
return {
|
|
142
|
+
ok: false,
|
|
143
|
+
error,
|
|
144
|
+
meta: buildMeta(route, options)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/core/registry/schema-validator.ts
|
|
149
|
+
import { Ajv } from "ajv";
|
|
150
|
+
var ajv = new Ajv({
|
|
151
|
+
allErrors: true,
|
|
152
|
+
strict: false
|
|
153
|
+
});
|
|
154
|
+
var validatorCache = /* @__PURE__ */ new WeakMap();
|
|
155
|
+
function mapAjvErrors(errors) {
|
|
156
|
+
if (!errors) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
return errors.map((error) => ({
|
|
160
|
+
instancePath: error.instancePath,
|
|
161
|
+
message: error.message ?? "schema validation failed",
|
|
162
|
+
keyword: error.keyword,
|
|
163
|
+
params: error.params
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
function getValidator(schema) {
|
|
167
|
+
const cached = validatorCache.get(schema);
|
|
168
|
+
if (cached) {
|
|
169
|
+
return cached;
|
|
170
|
+
}
|
|
171
|
+
const validator = ajv.compile(schema);
|
|
172
|
+
validatorCache.set(schema, validator);
|
|
173
|
+
return validator;
|
|
174
|
+
}
|
|
175
|
+
function validate(schema, payload) {
|
|
176
|
+
const validator = getValidator(schema);
|
|
177
|
+
const ok = validator(payload);
|
|
178
|
+
if (ok) {
|
|
179
|
+
return { ok: true };
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
ok: false,
|
|
183
|
+
errors: mapAjvErrors(validator.errors)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function validateInput(inputSchema, params) {
|
|
187
|
+
return validate(inputSchema, params);
|
|
188
|
+
}
|
|
189
|
+
function validateOutput(outputSchema, data) {
|
|
190
|
+
return validate(outputSchema, data);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/core/telemetry/logger.ts
|
|
194
|
+
var SENSITIVE_KEY_PATTERN = /(token|authorization|cookie|secret|password|api[_-]?key)/i;
|
|
195
|
+
function redactValue(value) {
|
|
196
|
+
if (Array.isArray(value)) {
|
|
197
|
+
return value.map(redactValue);
|
|
198
|
+
}
|
|
199
|
+
if (value && typeof value === "object") {
|
|
200
|
+
const redacted = {};
|
|
201
|
+
for (const [key, nested] of Object.entries(value)) {
|
|
202
|
+
redacted[key] = SENSITIVE_KEY_PATTERN.test(key) ? "[REDACTED]" : redactValue(nested);
|
|
203
|
+
}
|
|
204
|
+
return redacted;
|
|
205
|
+
}
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
function sanitizeTelemetryContext(context) {
|
|
209
|
+
return redactValue(context);
|
|
210
|
+
}
|
|
211
|
+
function logMetric(name, value, context = {}) {
|
|
212
|
+
if (process.env.GHX_TELEMETRY_STDOUT !== "1") {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const payload = {
|
|
216
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
217
|
+
metric: name,
|
|
218
|
+
value,
|
|
219
|
+
context: sanitizeTelemetryContext(context)
|
|
220
|
+
};
|
|
221
|
+
process.stdout.write(`${JSON.stringify(payload)}
|
|
222
|
+
`);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/core/execute/execute.ts
|
|
226
|
+
function parsePredicateValue(raw) {
|
|
227
|
+
const value = raw.trim();
|
|
228
|
+
if (value === "true") {
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
if (value === "false") {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
if (value === "null") {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const numeric = Number(value);
|
|
238
|
+
if (!Number.isNaN(numeric) && value.length > 0) {
|
|
239
|
+
return numeric;
|
|
240
|
+
}
|
|
241
|
+
return value.replace(/^['"]|['"]$/g, "");
|
|
242
|
+
}
|
|
243
|
+
function resolvePathValue(source, path) {
|
|
244
|
+
const segments = path.split(".").filter((segment) => segment.length > 0);
|
|
245
|
+
let current = source;
|
|
246
|
+
for (const segment of segments) {
|
|
247
|
+
if (typeof current !== "object" || current === null || Array.isArray(current)) {
|
|
248
|
+
return void 0;
|
|
249
|
+
}
|
|
250
|
+
current = current[segment];
|
|
251
|
+
}
|
|
252
|
+
return current;
|
|
253
|
+
}
|
|
254
|
+
function evaluateSuitabilityPreferred(card, params, routingContext) {
|
|
255
|
+
const rules = card.routing.suitability ?? [];
|
|
256
|
+
for (const rule of rules) {
|
|
257
|
+
const alwaysMatch = /^(cli|graphql|rest)$/i.exec(rule.predicate.trim());
|
|
258
|
+
const alwaysRoute = alwaysMatch?.[1];
|
|
259
|
+
if (rule.when === "always" && alwaysRoute) {
|
|
260
|
+
return alwaysRoute.toLowerCase();
|
|
261
|
+
}
|
|
262
|
+
const conditionalMatch = /^(cli|graphql|rest)\s+if\s+([a-zA-Z0-9_.]+)\s*(==|!=)\s*(.+)$/i.exec(
|
|
263
|
+
rule.predicate.trim()
|
|
264
|
+
);
|
|
265
|
+
if (!conditionalMatch) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const [, targetRouteRaw = "", rawPath = "", operator = "==", rawExpected = ""] = conditionalMatch;
|
|
269
|
+
const targetRoute = targetRouteRaw.toLowerCase();
|
|
270
|
+
const source = rule.when === "env" ? routingContext : params;
|
|
271
|
+
const path = rawPath.startsWith("params.") || rawPath.startsWith("env.") ? rawPath.split(".").slice(1).join(".") : rawPath;
|
|
272
|
+
const actual = resolvePathValue(source, path);
|
|
273
|
+
const expected = parsePredicateValue(rawExpected);
|
|
274
|
+
const matches = operator === "==" ? actual === expected : actual !== expected;
|
|
275
|
+
if (matches) {
|
|
276
|
+
return targetRoute;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return card.routing.preferred;
|
|
280
|
+
}
|
|
281
|
+
function routePlan(card, params, routingContext) {
|
|
282
|
+
const preferred = evaluateSuitabilityPreferred(card, params, routingContext);
|
|
283
|
+
const planned = /* @__PURE__ */ new Set([preferred, ...card.routing.fallbacks]);
|
|
284
|
+
return [...planned];
|
|
285
|
+
}
|
|
286
|
+
async function execute(options) {
|
|
287
|
+
const inputValidation = validateInput(options.card.input_schema, options.params);
|
|
288
|
+
if (!inputValidation.ok) {
|
|
289
|
+
return normalizeError(
|
|
290
|
+
{
|
|
291
|
+
code: errorCodes.Validation,
|
|
292
|
+
message: "Input schema validation failed",
|
|
293
|
+
retryable: false,
|
|
294
|
+
details: { ajvErrors: inputValidation.errors }
|
|
295
|
+
},
|
|
296
|
+
options.card.routing.preferred,
|
|
297
|
+
{
|
|
298
|
+
capabilityId: options.card.capability_id,
|
|
299
|
+
reason: "INPUT_VALIDATION"
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
const attempts = [];
|
|
304
|
+
const maxAttemptsPerRoute = Math.max(1, options.retry?.maxAttemptsPerRoute ?? 1);
|
|
305
|
+
let lastError;
|
|
306
|
+
let firstError;
|
|
307
|
+
const routingContext = options.routingContext ?? {};
|
|
308
|
+
for (const route of routePlan(options.card, options.params, routingContext)) {
|
|
309
|
+
logMetric("route.plan", 1, {
|
|
310
|
+
capability_id: options.card.capability_id,
|
|
311
|
+
route
|
|
312
|
+
});
|
|
313
|
+
const preflight = await options.preflight(route);
|
|
314
|
+
if (!preflight.ok) {
|
|
315
|
+
logMetric("route.preflight_skipped", 1, {
|
|
316
|
+
capability_id: options.card.capability_id,
|
|
317
|
+
route,
|
|
318
|
+
error_code: preflight.code
|
|
319
|
+
});
|
|
320
|
+
attempts.push({ route, status: "skipped", error_code: preflight.code });
|
|
321
|
+
lastError = {
|
|
322
|
+
code: preflight.code,
|
|
323
|
+
message: preflight.message,
|
|
324
|
+
retryable: preflight.retryable,
|
|
325
|
+
...preflight.details ? { details: preflight.details } : {}
|
|
326
|
+
};
|
|
327
|
+
firstError ??= lastError;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const routeHandler = options.routes[route];
|
|
331
|
+
if (typeof routeHandler !== "function") {
|
|
332
|
+
logMetric("route.missing_handler", 1, {
|
|
333
|
+
capability_id: options.card.capability_id,
|
|
334
|
+
route
|
|
335
|
+
});
|
|
336
|
+
const handlerError = {
|
|
337
|
+
code: errorCodes.AdapterUnsupported,
|
|
338
|
+
message: `No route handler configured for '${route}'`,
|
|
339
|
+
retryable: false,
|
|
340
|
+
details: { route }
|
|
341
|
+
};
|
|
342
|
+
attempts.push({ route, status: "skipped", error_code: errorCodes.AdapterUnsupported });
|
|
343
|
+
lastError = handlerError;
|
|
344
|
+
firstError ??= handlerError;
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
for (let attempt = 0; attempt < maxAttemptsPerRoute; attempt += 1) {
|
|
348
|
+
const result = await routeHandler(options.params);
|
|
349
|
+
logMetric("route.attempt", 1, {
|
|
350
|
+
capability_id: options.card.capability_id,
|
|
351
|
+
route,
|
|
352
|
+
ok: result.ok
|
|
353
|
+
});
|
|
354
|
+
const attemptRecord = {
|
|
355
|
+
route,
|
|
356
|
+
status: result.ok ? "success" : "error"
|
|
357
|
+
};
|
|
358
|
+
if (result.error?.code) {
|
|
359
|
+
attemptRecord.error_code = result.error.code;
|
|
360
|
+
}
|
|
361
|
+
attempts.push(attemptRecord);
|
|
362
|
+
if (result.ok) {
|
|
363
|
+
const outputValidation = validateOutput(options.card.output_schema, result.data);
|
|
364
|
+
if (!outputValidation.ok) {
|
|
365
|
+
const envelope2 = normalizeError(
|
|
366
|
+
{
|
|
367
|
+
code: errorCodes.Server,
|
|
368
|
+
message: "Output schema validation failed",
|
|
369
|
+
retryable: false,
|
|
370
|
+
details: { ajvErrors: outputValidation.errors }
|
|
371
|
+
},
|
|
372
|
+
route,
|
|
373
|
+
{
|
|
374
|
+
capabilityId: options.card.capability_id,
|
|
375
|
+
reason: "OUTPUT_VALIDATION"
|
|
376
|
+
}
|
|
377
|
+
);
|
|
378
|
+
if (options.trace) {
|
|
379
|
+
envelope2.meta.attempts = attempts;
|
|
380
|
+
}
|
|
381
|
+
return envelope2;
|
|
382
|
+
}
|
|
383
|
+
if (options.trace) {
|
|
384
|
+
result.meta.attempts = attempts;
|
|
385
|
+
}
|
|
386
|
+
return result;
|
|
387
|
+
}
|
|
388
|
+
lastError = result.error;
|
|
389
|
+
firstError ??= result.error;
|
|
390
|
+
if (!result.error?.retryable) {
|
|
391
|
+
if (result.error?.code !== errorCodes.AdapterUnsupported) {
|
|
392
|
+
if (options.trace) {
|
|
393
|
+
result.meta.attempts = attempts;
|
|
394
|
+
}
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
const finalError = lastError ?? firstError ?? {
|
|
402
|
+
code: errorCodes.Unknown,
|
|
403
|
+
message: "No route produced a result",
|
|
404
|
+
retryable: false
|
|
405
|
+
};
|
|
406
|
+
const envelope = normalizeError(finalError, options.card.routing.preferred, {
|
|
407
|
+
capabilityId: options.card.capability_id,
|
|
408
|
+
reason: "CARD_FALLBACK"
|
|
409
|
+
});
|
|
410
|
+
if (options.trace) {
|
|
411
|
+
envelope.meta.attempts = attempts;
|
|
412
|
+
}
|
|
413
|
+
return envelope;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// src/core/errors/map-error.ts
|
|
417
|
+
function toMessage(error) {
|
|
418
|
+
if (error instanceof Error) {
|
|
419
|
+
return error.message;
|
|
420
|
+
}
|
|
421
|
+
return String(error);
|
|
422
|
+
}
|
|
423
|
+
function mapErrorToCode(error) {
|
|
424
|
+
const message = toMessage(error).toLowerCase();
|
|
425
|
+
if (message.includes("rate limit") || message.includes(" 429") || message.includes("too many requests")) {
|
|
426
|
+
return errorCodes.RateLimit;
|
|
427
|
+
}
|
|
428
|
+
if (message.includes("timeout")) {
|
|
429
|
+
return errorCodes.Network;
|
|
430
|
+
}
|
|
431
|
+
if (message.includes("econn") || message.includes("enotfound") || message.includes("eai_again") || message.includes("network") || message.includes("connection reset")) {
|
|
432
|
+
return errorCodes.Network;
|
|
433
|
+
}
|
|
434
|
+
if (message.includes(" 500") || message.includes(" 502") || message.includes(" 503") || message.includes(" 504")) {
|
|
435
|
+
return errorCodes.Server;
|
|
436
|
+
}
|
|
437
|
+
if (message.includes("auth") || message.includes("forbidden") || message.includes("unauthorized")) {
|
|
438
|
+
return errorCodes.Auth;
|
|
439
|
+
}
|
|
440
|
+
if (message.includes("validation") || message.includes("invalid") || message.includes("required") || message.includes("positive integer")) {
|
|
441
|
+
return errorCodes.Validation;
|
|
442
|
+
}
|
|
443
|
+
if (message.includes("not found") || message.includes(" 404")) {
|
|
444
|
+
return errorCodes.NotFound;
|
|
445
|
+
}
|
|
446
|
+
return errorCodes.Unknown;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/core/errors/retryability.ts
|
|
450
|
+
var retryableCodes = /* @__PURE__ */ new Set([
|
|
451
|
+
errorCodes.Network,
|
|
452
|
+
errorCodes.RateLimit,
|
|
453
|
+
errorCodes.Server
|
|
454
|
+
]);
|
|
455
|
+
function isRetryableErrorCode(code) {
|
|
456
|
+
return retryableCodes.has(code);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// src/core/execution/adapters/cli-capability-adapter.ts
|
|
460
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
461
|
+
var DEFAULT_LIST_FIRST = 30;
|
|
462
|
+
var MAX_WORKFLOW_JOB_LOG_CHARS = 5e4;
|
|
463
|
+
var REDACTED_CLI_ERROR_MESSAGE = "gh command failed; stderr redacted for safety";
|
|
464
|
+
var NON_JSON_STDOUT_CAPABILITIES = /* @__PURE__ */ new Set([
|
|
465
|
+
"pr.checks.rerun_failed",
|
|
466
|
+
"pr.checks.rerun_all",
|
|
467
|
+
"pr.reviewers.request",
|
|
468
|
+
"pr.assignees.update",
|
|
469
|
+
"pr.branch.update",
|
|
470
|
+
"workflow_run.cancel",
|
|
471
|
+
"workflow_run.rerun_failed",
|
|
472
|
+
"workflow_run.rerun_all"
|
|
473
|
+
]);
|
|
474
|
+
var REPO_ISSUE_TYPES_GRAPHQL_QUERY = "query($owner:String!,$name:String!,$first:Int!,$after:String){repository(owner:$owner,name:$name){issueTypes(first:$first,after:$after){nodes{id name color isEnabled} pageInfo{hasNextPage endCursor}}}}";
|
|
475
|
+
var ISSUE_COMMENTS_GRAPHQL_QUERY = "query($owner:String!,$name:String!,$issueNumber:Int!,$first:Int!,$after:String){repository(owner:$owner,name:$name){issue(number:$issueNumber){comments(first:$first,after:$after){nodes{id body createdAt url author{login}} pageInfo{hasNextPage endCursor}}}}}";
|
|
476
|
+
function containsSensitiveText(value) {
|
|
477
|
+
return /(gh[pousr]_[A-Za-z0-9_]+|github_pat_[A-Za-z0-9_]+|authorization:\s*bearer\s+\S+|bearer\s+[A-Za-z0-9._-]{20,}|(?:api[_-]?key|token|secret|password)\s*[=:]\s*\S+)/i.test(
|
|
478
|
+
value
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
function sanitizeCliErrorMessage(stderr, exitCode) {
|
|
482
|
+
const trimmed = stderr.trim();
|
|
483
|
+
if (!trimmed) {
|
|
484
|
+
return `gh exited with code ${exitCode}`;
|
|
485
|
+
}
|
|
486
|
+
if (containsSensitiveText(trimmed)) {
|
|
487
|
+
return REDACTED_CLI_ERROR_MESSAGE;
|
|
488
|
+
}
|
|
489
|
+
return trimmed;
|
|
490
|
+
}
|
|
491
|
+
function shouldFallbackRerunFailedToAll(stderr) {
|
|
492
|
+
const normalized = stderr.toLowerCase();
|
|
493
|
+
return normalized.includes("cannot be rerun") && normalized.includes("cannot be retried");
|
|
494
|
+
}
|
|
495
|
+
function parseStrictPositiveInt(value) {
|
|
496
|
+
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : null;
|
|
497
|
+
}
|
|
498
|
+
function parseListFirst(value) {
|
|
499
|
+
if (value === void 0) {
|
|
500
|
+
return DEFAULT_LIST_FIRST;
|
|
501
|
+
}
|
|
502
|
+
return parseStrictPositiveInt(value);
|
|
503
|
+
}
|
|
504
|
+
function parseNonEmptyString(value) {
|
|
505
|
+
if (typeof value !== "string") {
|
|
506
|
+
return null;
|
|
507
|
+
}
|
|
508
|
+
const trimmed = value.trim();
|
|
509
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
510
|
+
}
|
|
511
|
+
function requireRepo(owner, name, capabilityId) {
|
|
512
|
+
if (!owner || !name) {
|
|
513
|
+
throw new Error(`Missing owner/name for ${capabilityId}`);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function commandTokens(card, fallbackCommand) {
|
|
517
|
+
const fromCard = card?.cli?.command;
|
|
518
|
+
const command = typeof fromCard === "string" && fromCard.trim().length > 0 ? fromCard : fallbackCommand;
|
|
519
|
+
return command.trim().split(/\s+/);
|
|
520
|
+
}
|
|
521
|
+
function jsonFieldsFromCard(card, fallbackFields) {
|
|
522
|
+
const fields = card?.cli?.jsonFields;
|
|
523
|
+
if (Array.isArray(fields) && fields.length > 0) {
|
|
524
|
+
return fields.join(",");
|
|
525
|
+
}
|
|
526
|
+
return fallbackFields;
|
|
527
|
+
}
|
|
528
|
+
function buildArgs(capabilityId, params, card) {
|
|
529
|
+
const owner = String(params.owner ?? "");
|
|
530
|
+
const name = String(params.name ?? "");
|
|
531
|
+
const repo = owner && name ? `${owner}/${name}` : "";
|
|
532
|
+
if (capabilityId === "repo.view") {
|
|
533
|
+
const args = commandTokens(card, "repo view");
|
|
534
|
+
if (repo) {
|
|
535
|
+
args.push(repo);
|
|
536
|
+
}
|
|
537
|
+
args.push(
|
|
538
|
+
"--json",
|
|
539
|
+
jsonFieldsFromCard(
|
|
540
|
+
card,
|
|
541
|
+
"id,name,nameWithOwner,isPrivate,stargazerCount,forkCount,url,defaultBranchRef"
|
|
542
|
+
)
|
|
543
|
+
);
|
|
544
|
+
return args;
|
|
545
|
+
}
|
|
546
|
+
if (capabilityId === "repo.labels.list") {
|
|
547
|
+
const first = parseListFirst(params.first);
|
|
548
|
+
if (first === null) {
|
|
549
|
+
throw new Error("Missing or invalid first for repo.labels.list");
|
|
550
|
+
}
|
|
551
|
+
const args = commandTokens(card, "label list");
|
|
552
|
+
if (repo) {
|
|
553
|
+
args.push("--repo", repo);
|
|
554
|
+
}
|
|
555
|
+
args.push(
|
|
556
|
+
"--limit",
|
|
557
|
+
String(first),
|
|
558
|
+
"--json",
|
|
559
|
+
jsonFieldsFromCard(card, "id,name,description,color,isDefault")
|
|
560
|
+
);
|
|
561
|
+
return args;
|
|
562
|
+
}
|
|
563
|
+
if (capabilityId === "repo.issue_types.list") {
|
|
564
|
+
const first = parseListFirst(params.first);
|
|
565
|
+
if (first === null) {
|
|
566
|
+
throw new Error("Missing or invalid first for repo.issue_types.list");
|
|
567
|
+
}
|
|
568
|
+
const after = params.after;
|
|
569
|
+
if (!(after === void 0 || after === null || typeof after === "string")) {
|
|
570
|
+
throw new Error("Invalid after cursor for repo.issue_types.list");
|
|
571
|
+
}
|
|
572
|
+
if (!owner || !name) {
|
|
573
|
+
throw new Error("Missing owner/name for repo.issue_types.list");
|
|
574
|
+
}
|
|
575
|
+
const args = [
|
|
576
|
+
...commandTokens(card, "api graphql"),
|
|
577
|
+
"-f",
|
|
578
|
+
`query=${REPO_ISSUE_TYPES_GRAPHQL_QUERY}`,
|
|
579
|
+
"-f",
|
|
580
|
+
`owner=${owner}`,
|
|
581
|
+
"-f",
|
|
582
|
+
`name=${name}`,
|
|
583
|
+
"-F",
|
|
584
|
+
`first=${first}`
|
|
585
|
+
];
|
|
586
|
+
if (typeof after === "string" && after.length > 0) {
|
|
587
|
+
args.push("-f", `after=${after}`);
|
|
588
|
+
}
|
|
589
|
+
return args;
|
|
590
|
+
}
|
|
591
|
+
if (capabilityId === "issue.view") {
|
|
592
|
+
const issueNumber = parseStrictPositiveInt(params.issueNumber);
|
|
593
|
+
if (issueNumber === null) {
|
|
594
|
+
throw new Error("Missing or invalid issueNumber for issue.view");
|
|
595
|
+
}
|
|
596
|
+
const args = [...commandTokens(card, "issue view"), String(issueNumber)];
|
|
597
|
+
if (repo) {
|
|
598
|
+
args.push("--repo", repo);
|
|
599
|
+
}
|
|
600
|
+
args.push("--json", jsonFieldsFromCard(card, "id,number,title,state,url"));
|
|
601
|
+
return args;
|
|
602
|
+
}
|
|
603
|
+
if (capabilityId === "issue.list") {
|
|
604
|
+
const first = parseListFirst(params.first);
|
|
605
|
+
if (first === null) {
|
|
606
|
+
throw new Error("Missing or invalid first for issue.list");
|
|
607
|
+
}
|
|
608
|
+
const args = commandTokens(card, "issue list");
|
|
609
|
+
if (repo) {
|
|
610
|
+
args.push("--repo", repo);
|
|
611
|
+
}
|
|
612
|
+
args.push(
|
|
613
|
+
"--limit",
|
|
614
|
+
String(first),
|
|
615
|
+
"--json",
|
|
616
|
+
jsonFieldsFromCard(card, "id,number,title,state,url")
|
|
617
|
+
);
|
|
618
|
+
return args;
|
|
619
|
+
}
|
|
620
|
+
if (capabilityId === "issue.comments.list") {
|
|
621
|
+
const issueNumber = parseStrictPositiveInt(params.issueNumber);
|
|
622
|
+
if (issueNumber === null) {
|
|
623
|
+
throw new Error("Missing or invalid issueNumber for issue.comments.list");
|
|
624
|
+
}
|
|
625
|
+
const first = parseStrictPositiveInt(params.first);
|
|
626
|
+
if (first === null) {
|
|
627
|
+
throw new Error("Missing or invalid first for issue.comments.list");
|
|
628
|
+
}
|
|
629
|
+
const after = params.after;
|
|
630
|
+
if (!(after === void 0 || after === null || typeof after === "string")) {
|
|
631
|
+
throw new Error("Invalid after cursor for issue.comments.list");
|
|
632
|
+
}
|
|
633
|
+
const args = [
|
|
634
|
+
...commandTokens(card, "api graphql"),
|
|
635
|
+
"-f",
|
|
636
|
+
`query=${ISSUE_COMMENTS_GRAPHQL_QUERY}`,
|
|
637
|
+
"-f",
|
|
638
|
+
`owner=${owner}`,
|
|
639
|
+
"-f",
|
|
640
|
+
`name=${name}`,
|
|
641
|
+
"-F",
|
|
642
|
+
`issueNumber=${issueNumber}`,
|
|
643
|
+
"-F",
|
|
644
|
+
`first=${first}`
|
|
645
|
+
];
|
|
646
|
+
if (typeof after === "string" && after.length > 0) {
|
|
647
|
+
args.push("-f", `after=${after}`);
|
|
648
|
+
}
|
|
649
|
+
return args;
|
|
650
|
+
}
|
|
651
|
+
if (capabilityId === "pr.view") {
|
|
652
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
653
|
+
if (prNumber === null) {
|
|
654
|
+
throw new Error("Missing or invalid prNumber for pr.view");
|
|
655
|
+
}
|
|
656
|
+
const args = [...commandTokens(card, "pr view"), String(prNumber)];
|
|
657
|
+
if (repo) {
|
|
658
|
+
args.push("--repo", repo);
|
|
659
|
+
}
|
|
660
|
+
args.push("--json", jsonFieldsFromCard(card, "id,number,title,state,url"));
|
|
661
|
+
return args;
|
|
662
|
+
}
|
|
663
|
+
if (capabilityId === "pr.list") {
|
|
664
|
+
const first = parseListFirst(params.first);
|
|
665
|
+
if (first === null) {
|
|
666
|
+
throw new Error("Missing or invalid first for pr.list");
|
|
667
|
+
}
|
|
668
|
+
const args = commandTokens(card, "pr list");
|
|
669
|
+
if (repo) {
|
|
670
|
+
args.push("--repo", repo);
|
|
671
|
+
}
|
|
672
|
+
args.push(
|
|
673
|
+
"--limit",
|
|
674
|
+
String(first),
|
|
675
|
+
"--json",
|
|
676
|
+
jsonFieldsFromCard(card, "id,number,title,state,url")
|
|
677
|
+
);
|
|
678
|
+
return args;
|
|
679
|
+
}
|
|
680
|
+
if (capabilityId === "pr.status.checks" || capabilityId === "pr.checks.get_failed") {
|
|
681
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
682
|
+
if (prNumber === null) {
|
|
683
|
+
throw new Error(`Missing or invalid prNumber for ${capabilityId}`);
|
|
684
|
+
}
|
|
685
|
+
const args = [...commandTokens(card, "pr checks"), String(prNumber)];
|
|
686
|
+
if (repo) {
|
|
687
|
+
args.push("--repo", repo);
|
|
688
|
+
}
|
|
689
|
+
args.push("--json", jsonFieldsFromCard(card, "name,state,bucket,workflow,link"));
|
|
690
|
+
return args;
|
|
691
|
+
}
|
|
692
|
+
if (capabilityId === "pr.mergeability.view") {
|
|
693
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
694
|
+
if (prNumber === null) {
|
|
695
|
+
throw new Error("Missing or invalid prNumber for pr.mergeability.view");
|
|
696
|
+
}
|
|
697
|
+
const args = [...commandTokens(card, "pr view"), String(prNumber)];
|
|
698
|
+
if (repo) {
|
|
699
|
+
args.push("--repo", repo);
|
|
700
|
+
}
|
|
701
|
+
args.push(
|
|
702
|
+
"--json",
|
|
703
|
+
jsonFieldsFromCard(card, "mergeable,mergeStateStatus,reviewDecision,isDraft,state")
|
|
704
|
+
);
|
|
705
|
+
return args;
|
|
706
|
+
}
|
|
707
|
+
if (capabilityId === "pr.ready_for_review.set") {
|
|
708
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
709
|
+
if (prNumber === null) {
|
|
710
|
+
throw new Error("Missing or invalid prNumber for pr.ready_for_review.set");
|
|
711
|
+
}
|
|
712
|
+
if (typeof params.ready !== "boolean") {
|
|
713
|
+
throw new Error("Missing or invalid ready for pr.ready_for_review.set");
|
|
714
|
+
}
|
|
715
|
+
const args = [...commandTokens(card, "pr ready"), String(prNumber)];
|
|
716
|
+
if (repo) {
|
|
717
|
+
args.push("--repo", repo);
|
|
718
|
+
}
|
|
719
|
+
if (!params.ready) {
|
|
720
|
+
args.push("--undo");
|
|
721
|
+
}
|
|
722
|
+
return args;
|
|
723
|
+
}
|
|
724
|
+
if (capabilityId === "pr.review.submit_approve" || capabilityId === "pr.review.submit_request_changes" || capabilityId === "pr.review.submit_comment") {
|
|
725
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
726
|
+
if (prNumber === null) {
|
|
727
|
+
throw new Error(`Missing or invalid prNumber for ${capabilityId}`);
|
|
728
|
+
}
|
|
729
|
+
const args = [...commandTokens(card, "pr review"), String(prNumber)];
|
|
730
|
+
if (repo) {
|
|
731
|
+
args.push("--repo", repo);
|
|
732
|
+
}
|
|
733
|
+
if (capabilityId === "pr.review.submit_approve") {
|
|
734
|
+
args.push("--approve");
|
|
735
|
+
const body2 = parseNonEmptyString(params.body);
|
|
736
|
+
if (body2) {
|
|
737
|
+
args.push("--body", body2);
|
|
738
|
+
}
|
|
739
|
+
return args;
|
|
740
|
+
}
|
|
741
|
+
const body = parseNonEmptyString(params.body);
|
|
742
|
+
if (body === null) {
|
|
743
|
+
throw new Error(`Missing or invalid body for ${capabilityId}`);
|
|
744
|
+
}
|
|
745
|
+
if (capabilityId === "pr.review.submit_request_changes") {
|
|
746
|
+
args.push("--request-changes", "--body", body);
|
|
747
|
+
return args;
|
|
748
|
+
}
|
|
749
|
+
args.push("--comment", "--body", body);
|
|
750
|
+
return args;
|
|
751
|
+
}
|
|
752
|
+
if (capabilityId === "pr.merge.execute") {
|
|
753
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
754
|
+
if (prNumber === null) {
|
|
755
|
+
throw new Error("Missing or invalid prNumber for pr.merge.execute");
|
|
756
|
+
}
|
|
757
|
+
const method = params.method === void 0 ? "merge" : params.method;
|
|
758
|
+
if (method !== "merge" && method !== "squash" && method !== "rebase") {
|
|
759
|
+
throw new Error("Missing or invalid method for pr.merge.execute");
|
|
760
|
+
}
|
|
761
|
+
if (params.deleteBranch !== void 0 && typeof params.deleteBranch !== "boolean") {
|
|
762
|
+
throw new Error("Missing or invalid deleteBranch for pr.merge.execute");
|
|
763
|
+
}
|
|
764
|
+
const args = [...commandTokens(card, "pr merge"), String(prNumber)];
|
|
765
|
+
if (repo) {
|
|
766
|
+
args.push("--repo", repo);
|
|
767
|
+
}
|
|
768
|
+
args.push(`--${method}`);
|
|
769
|
+
if (params.deleteBranch === true) {
|
|
770
|
+
args.push("--delete-branch");
|
|
771
|
+
}
|
|
772
|
+
return args;
|
|
773
|
+
}
|
|
774
|
+
if (capabilityId === "pr.checks.rerun_failed" || capabilityId === "pr.checks.rerun_all") {
|
|
775
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
776
|
+
if (prNumber === null) {
|
|
777
|
+
throw new Error(`Missing or invalid prNumber for ${capabilityId}`);
|
|
778
|
+
}
|
|
779
|
+
const runId = parseStrictPositiveInt(params.runId);
|
|
780
|
+
if (runId === null) {
|
|
781
|
+
throw new Error(`Missing or invalid runId for ${capabilityId}`);
|
|
782
|
+
}
|
|
783
|
+
const args = [...commandTokens(card, "run rerun"), String(runId)];
|
|
784
|
+
if (repo) {
|
|
785
|
+
args.push("--repo", repo);
|
|
786
|
+
}
|
|
787
|
+
if (capabilityId === "pr.checks.rerun_failed") {
|
|
788
|
+
args.push("--failed");
|
|
789
|
+
}
|
|
790
|
+
return args;
|
|
791
|
+
}
|
|
792
|
+
if (capabilityId === "pr.reviewers.request") {
|
|
793
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
794
|
+
if (prNumber === null) {
|
|
795
|
+
throw new Error("Missing or invalid prNumber for pr.reviewers.request");
|
|
796
|
+
}
|
|
797
|
+
const reviewers = Array.isArray(params.reviewers) ? params.reviewers.filter(
|
|
798
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
799
|
+
) : [];
|
|
800
|
+
if (reviewers.length === 0) {
|
|
801
|
+
throw new Error("Missing or invalid reviewers for pr.reviewers.request");
|
|
802
|
+
}
|
|
803
|
+
const args = [...commandTokens(card, "pr edit"), String(prNumber)];
|
|
804
|
+
if (repo) {
|
|
805
|
+
args.push("--repo", repo);
|
|
806
|
+
}
|
|
807
|
+
args.push("--add-reviewer", reviewers.join(","));
|
|
808
|
+
return args;
|
|
809
|
+
}
|
|
810
|
+
if (capabilityId === "pr.assignees.update") {
|
|
811
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
812
|
+
if (prNumber === null) {
|
|
813
|
+
throw new Error("Missing or invalid prNumber for pr.assignees.update");
|
|
814
|
+
}
|
|
815
|
+
const addAssignees = Array.isArray(params.add) ? params.add.filter(
|
|
816
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
817
|
+
) : [];
|
|
818
|
+
const removeAssignees = Array.isArray(params.remove) ? params.remove.filter(
|
|
819
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
820
|
+
) : [];
|
|
821
|
+
if (addAssignees.length === 0 && removeAssignees.length === 0) {
|
|
822
|
+
throw new Error("Missing or invalid add/remove assignees for pr.assignees.update");
|
|
823
|
+
}
|
|
824
|
+
const args = [...commandTokens(card, "pr edit"), String(prNumber)];
|
|
825
|
+
if (repo) {
|
|
826
|
+
args.push("--repo", repo);
|
|
827
|
+
}
|
|
828
|
+
if (addAssignees.length > 0) {
|
|
829
|
+
args.push("--add-assignee", addAssignees.join(","));
|
|
830
|
+
}
|
|
831
|
+
if (removeAssignees.length > 0) {
|
|
832
|
+
args.push("--remove-assignee", removeAssignees.join(","));
|
|
833
|
+
}
|
|
834
|
+
return args;
|
|
835
|
+
}
|
|
836
|
+
if (capabilityId === "pr.branch.update") {
|
|
837
|
+
const prNumber = parseStrictPositiveInt(params.prNumber);
|
|
838
|
+
if (prNumber === null) {
|
|
839
|
+
throw new Error("Missing or invalid prNumber for pr.branch.update");
|
|
840
|
+
}
|
|
841
|
+
const args = [...commandTokens(card, "pr update-branch"), String(prNumber)];
|
|
842
|
+
if (repo) {
|
|
843
|
+
args.push("--repo", repo);
|
|
844
|
+
}
|
|
845
|
+
return args;
|
|
846
|
+
}
|
|
847
|
+
if (capabilityId === "check_run.annotations.list") {
|
|
848
|
+
const checkRunId = parseStrictPositiveInt(params.checkRunId);
|
|
849
|
+
if (checkRunId === null) {
|
|
850
|
+
throw new Error("Missing or invalid checkRunId for check_run.annotations.list");
|
|
851
|
+
}
|
|
852
|
+
if (!owner || !name) {
|
|
853
|
+
throw new Error("Missing owner/name for check_run.annotations.list");
|
|
854
|
+
}
|
|
855
|
+
const args = [
|
|
856
|
+
...commandTokens(card, "api"),
|
|
857
|
+
`repos/${owner}/${name}/check-runs/${checkRunId}/annotations`
|
|
858
|
+
];
|
|
859
|
+
return args;
|
|
860
|
+
}
|
|
861
|
+
if (capabilityId === "workflow_runs.list") {
|
|
862
|
+
const first = parseListFirst(params.first);
|
|
863
|
+
if (first === null) {
|
|
864
|
+
throw new Error("Missing or invalid first for workflow_runs.list");
|
|
865
|
+
}
|
|
866
|
+
const args = commandTokens(card, "run list");
|
|
867
|
+
if (repo) {
|
|
868
|
+
args.push("--repo", repo);
|
|
869
|
+
}
|
|
870
|
+
if (typeof params.branch === "string" && params.branch.length > 0) {
|
|
871
|
+
args.push("--branch", params.branch);
|
|
872
|
+
}
|
|
873
|
+
if (typeof params.event === "string" && params.event.length > 0) {
|
|
874
|
+
args.push("--event", params.event);
|
|
875
|
+
}
|
|
876
|
+
if (typeof params.status === "string" && params.status.length > 0) {
|
|
877
|
+
args.push("--status", params.status);
|
|
878
|
+
}
|
|
879
|
+
args.push(
|
|
880
|
+
"--limit",
|
|
881
|
+
String(first),
|
|
882
|
+
"--json",
|
|
883
|
+
jsonFieldsFromCard(card, "databaseId,workflowName,status,conclusion,headBranch,url")
|
|
884
|
+
);
|
|
885
|
+
return args;
|
|
886
|
+
}
|
|
887
|
+
if (capabilityId === "workflow_run.jobs.list") {
|
|
888
|
+
const runId = parseStrictPositiveInt(params.runId);
|
|
889
|
+
if (runId === null) {
|
|
890
|
+
throw new Error("Missing or invalid runId for workflow_run.jobs.list");
|
|
891
|
+
}
|
|
892
|
+
const args = [...commandTokens(card, "run view"), String(runId)];
|
|
893
|
+
if (repo) {
|
|
894
|
+
args.push("--repo", repo);
|
|
895
|
+
}
|
|
896
|
+
args.push("--json", "jobs");
|
|
897
|
+
return args;
|
|
898
|
+
}
|
|
899
|
+
if (capabilityId === "workflow_job.logs.get" || capabilityId === "workflow_job.logs.analyze") {
|
|
900
|
+
const jobId = parseStrictPositiveInt(params.jobId);
|
|
901
|
+
if (jobId === null) {
|
|
902
|
+
throw new Error(`Missing or invalid jobId for ${capabilityId}`);
|
|
903
|
+
}
|
|
904
|
+
const args = [...commandTokens(card, "run view"), "--job", String(jobId), "--log"];
|
|
905
|
+
if (repo) {
|
|
906
|
+
args.push("--repo", repo);
|
|
907
|
+
}
|
|
908
|
+
return args;
|
|
909
|
+
}
|
|
910
|
+
if (capabilityId === "workflow.list") {
|
|
911
|
+
const first = parseListFirst(params.first);
|
|
912
|
+
if (first === null) {
|
|
913
|
+
throw new Error("Missing or invalid first for workflow.list");
|
|
914
|
+
}
|
|
915
|
+
const args = commandTokens(card, "workflow list");
|
|
916
|
+
if (repo) {
|
|
917
|
+
args.push("--repo", repo);
|
|
918
|
+
}
|
|
919
|
+
args.push("--limit", String(first), "--json", jsonFieldsFromCard(card, "id,name,path,state"));
|
|
920
|
+
return args;
|
|
921
|
+
}
|
|
922
|
+
if (capabilityId === "workflow.get") {
|
|
923
|
+
const workflowId = parseNonEmptyString(params.workflowId) ?? (typeof params.workflowId === "number" ? String(params.workflowId) : null);
|
|
924
|
+
if (workflowId === null) {
|
|
925
|
+
throw new Error("Missing or invalid workflowId for workflow.get");
|
|
926
|
+
}
|
|
927
|
+
const args = [...commandTokens(card, "workflow view"), workflowId];
|
|
928
|
+
if (repo) {
|
|
929
|
+
args.push("--repo", repo);
|
|
930
|
+
}
|
|
931
|
+
args.push("--json", jsonFieldsFromCard(card, "id,name,path,state,url"));
|
|
932
|
+
return args;
|
|
933
|
+
}
|
|
934
|
+
if (capabilityId === "workflow_run.get") {
|
|
935
|
+
const runId = parseStrictPositiveInt(params.runId);
|
|
936
|
+
if (runId === null) {
|
|
937
|
+
throw new Error("Missing or invalid runId for workflow_run.get");
|
|
938
|
+
}
|
|
939
|
+
const args = [...commandTokens(card, "run view"), String(runId)];
|
|
940
|
+
if (repo) {
|
|
941
|
+
args.push("--repo", repo);
|
|
942
|
+
}
|
|
943
|
+
args.push(
|
|
944
|
+
"--json",
|
|
945
|
+
jsonFieldsFromCard(
|
|
946
|
+
card,
|
|
947
|
+
"databaseId,workflowName,status,conclusion,headBranch,headSha,url,event,createdAt,updatedAt,startedAt"
|
|
948
|
+
)
|
|
949
|
+
);
|
|
950
|
+
return args;
|
|
951
|
+
}
|
|
952
|
+
if (capabilityId === "workflow_run.rerun_all" || capabilityId === "workflow_run.cancel") {
|
|
953
|
+
const runId = parseStrictPositiveInt(params.runId);
|
|
954
|
+
if (runId === null) {
|
|
955
|
+
throw new Error(`Missing or invalid runId for ${capabilityId}`);
|
|
956
|
+
}
|
|
957
|
+
const args = [
|
|
958
|
+
...commandTokens(
|
|
959
|
+
card,
|
|
960
|
+
capabilityId === "workflow_run.rerun_all" ? "run rerun" : "run cancel"
|
|
961
|
+
),
|
|
962
|
+
String(runId)
|
|
963
|
+
];
|
|
964
|
+
if (repo) {
|
|
965
|
+
args.push("--repo", repo);
|
|
966
|
+
}
|
|
967
|
+
return args;
|
|
968
|
+
}
|
|
969
|
+
if (capabilityId === "workflow_run.artifacts.list") {
|
|
970
|
+
const runId = parseStrictPositiveInt(params.runId);
|
|
971
|
+
if (runId === null) {
|
|
972
|
+
throw new Error("Missing or invalid runId for workflow_run.artifacts.list");
|
|
973
|
+
}
|
|
974
|
+
const args = [...commandTokens(card, "run view"), String(runId)];
|
|
975
|
+
if (repo) {
|
|
976
|
+
args.push("--repo", repo);
|
|
977
|
+
}
|
|
978
|
+
args.push("--json", jsonFieldsFromCard(card, "artifacts"));
|
|
979
|
+
return args;
|
|
980
|
+
}
|
|
981
|
+
if (capabilityId === "project_v2.org.get" || capabilityId === "project_v2.user.get") {
|
|
982
|
+
const ownerParam = capabilityId === "project_v2.org.get" ? params.org : params.user;
|
|
983
|
+
const owner2 = parseNonEmptyString(ownerParam);
|
|
984
|
+
const projectNumber = parseStrictPositiveInt(params.projectNumber);
|
|
985
|
+
if (owner2 === null || projectNumber === null) {
|
|
986
|
+
throw new Error(`Missing or invalid owner/projectNumber for ${capabilityId}`);
|
|
987
|
+
}
|
|
988
|
+
const args = [
|
|
989
|
+
...commandTokens(card, "project view"),
|
|
990
|
+
String(projectNumber),
|
|
991
|
+
"--owner",
|
|
992
|
+
owner2,
|
|
993
|
+
"--format",
|
|
994
|
+
"json"
|
|
995
|
+
];
|
|
996
|
+
return args;
|
|
997
|
+
}
|
|
998
|
+
if (capabilityId === "project_v2.fields.list") {
|
|
999
|
+
const projectNumber = parseStrictPositiveInt(params.projectNumber);
|
|
1000
|
+
const projectOwner = parseNonEmptyString(params.owner);
|
|
1001
|
+
if (projectNumber === null || projectOwner === null) {
|
|
1002
|
+
throw new Error("Missing or invalid owner/projectNumber for project_v2.fields.list");
|
|
1003
|
+
}
|
|
1004
|
+
const args = [
|
|
1005
|
+
...commandTokens(card, "project field-list"),
|
|
1006
|
+
String(projectNumber),
|
|
1007
|
+
"--owner",
|
|
1008
|
+
projectOwner,
|
|
1009
|
+
"--format",
|
|
1010
|
+
"json"
|
|
1011
|
+
];
|
|
1012
|
+
return args;
|
|
1013
|
+
}
|
|
1014
|
+
if (capabilityId === "project_v2.items.list") {
|
|
1015
|
+
const projectNumber = parseStrictPositiveInt(params.projectNumber);
|
|
1016
|
+
const projectOwner = parseNonEmptyString(params.owner);
|
|
1017
|
+
const first = parseListFirst(params.first);
|
|
1018
|
+
if (projectNumber === null || projectOwner === null || first === null) {
|
|
1019
|
+
throw new Error("Missing or invalid owner/projectNumber/first for project_v2.items.list");
|
|
1020
|
+
}
|
|
1021
|
+
const args = [
|
|
1022
|
+
...commandTokens(card, "project item-list"),
|
|
1023
|
+
String(projectNumber),
|
|
1024
|
+
"--owner",
|
|
1025
|
+
projectOwner,
|
|
1026
|
+
"--format",
|
|
1027
|
+
"json",
|
|
1028
|
+
"--limit",
|
|
1029
|
+
String(first)
|
|
1030
|
+
];
|
|
1031
|
+
return args;
|
|
1032
|
+
}
|
|
1033
|
+
if (capabilityId === "release.list") {
|
|
1034
|
+
requireRepo(owner, name, capabilityId);
|
|
1035
|
+
const first = parseListFirst(params.first);
|
|
1036
|
+
if (first === null) {
|
|
1037
|
+
throw new Error("Missing or invalid first for release.list");
|
|
1038
|
+
}
|
|
1039
|
+
const args = [
|
|
1040
|
+
...commandTokens(card, "api"),
|
|
1041
|
+
`repos/${owner}/${name}/releases`,
|
|
1042
|
+
"-F",
|
|
1043
|
+
`per_page=${first}`
|
|
1044
|
+
];
|
|
1045
|
+
return args;
|
|
1046
|
+
}
|
|
1047
|
+
if (capabilityId === "release.get") {
|
|
1048
|
+
requireRepo(owner, name, capabilityId);
|
|
1049
|
+
const tagName = parseNonEmptyString(params.tagName);
|
|
1050
|
+
if (tagName === null) {
|
|
1051
|
+
throw new Error("Missing or invalid tagName for release.get");
|
|
1052
|
+
}
|
|
1053
|
+
const args = [
|
|
1054
|
+
...commandTokens(card, "api"),
|
|
1055
|
+
`repos/${owner}/${name}/releases/tags/${encodeURIComponent(tagName)}`
|
|
1056
|
+
];
|
|
1057
|
+
return args;
|
|
1058
|
+
}
|
|
1059
|
+
if (capabilityId === "release.create_draft") {
|
|
1060
|
+
requireRepo(owner, name, capabilityId);
|
|
1061
|
+
const tagName = parseNonEmptyString(params.tagName);
|
|
1062
|
+
if (tagName === null) {
|
|
1063
|
+
throw new Error("Missing or invalid tagName for release.create_draft");
|
|
1064
|
+
}
|
|
1065
|
+
const args = [
|
|
1066
|
+
...commandTokens(card, "api"),
|
|
1067
|
+
`repos/${owner}/${name}/releases`,
|
|
1068
|
+
"--method",
|
|
1069
|
+
"POST",
|
|
1070
|
+
"-f",
|
|
1071
|
+
`tag_name=${tagName}`,
|
|
1072
|
+
"-F",
|
|
1073
|
+
"draft=true"
|
|
1074
|
+
];
|
|
1075
|
+
const title = parseNonEmptyString(params.title);
|
|
1076
|
+
if (title) {
|
|
1077
|
+
args.push("-f", `name=${title}`);
|
|
1078
|
+
}
|
|
1079
|
+
const notes = parseNonEmptyString(params.notes);
|
|
1080
|
+
if (notes) {
|
|
1081
|
+
args.push("-f", `body=${notes}`);
|
|
1082
|
+
}
|
|
1083
|
+
const target = parseNonEmptyString(params.targetCommitish);
|
|
1084
|
+
if (target) {
|
|
1085
|
+
args.push("-f", `target_commitish=${target}`);
|
|
1086
|
+
}
|
|
1087
|
+
if (typeof params.prerelease === "boolean") {
|
|
1088
|
+
args.push("-F", `prerelease=${params.prerelease ? "true" : "false"}`);
|
|
1089
|
+
}
|
|
1090
|
+
return args;
|
|
1091
|
+
}
|
|
1092
|
+
if (capabilityId === "release.update") {
|
|
1093
|
+
requireRepo(owner, name, capabilityId);
|
|
1094
|
+
const releaseId = parseStrictPositiveInt(params.releaseId);
|
|
1095
|
+
if (releaseId === null) {
|
|
1096
|
+
throw new Error("Missing or invalid releaseId for release.update");
|
|
1097
|
+
}
|
|
1098
|
+
if (params.draft !== void 0 && params.draft !== true) {
|
|
1099
|
+
throw new Error(
|
|
1100
|
+
"release.update only supports draft=true; use release.publish_draft to publish"
|
|
1101
|
+
);
|
|
1102
|
+
}
|
|
1103
|
+
const args = [
|
|
1104
|
+
...commandTokens(card, "api"),
|
|
1105
|
+
`repos/${owner}/${name}/releases/${releaseId}`,
|
|
1106
|
+
"--method",
|
|
1107
|
+
"PATCH",
|
|
1108
|
+
"-F",
|
|
1109
|
+
"draft=true"
|
|
1110
|
+
];
|
|
1111
|
+
const tagName = parseNonEmptyString(params.tagName);
|
|
1112
|
+
if (tagName) {
|
|
1113
|
+
args.push("-f", `tag_name=${tagName}`);
|
|
1114
|
+
}
|
|
1115
|
+
const title = parseNonEmptyString(params.title);
|
|
1116
|
+
if (title) {
|
|
1117
|
+
args.push("-f", `name=${title}`);
|
|
1118
|
+
}
|
|
1119
|
+
const notes = parseNonEmptyString(params.notes);
|
|
1120
|
+
if (notes) {
|
|
1121
|
+
args.push("-f", `body=${notes}`);
|
|
1122
|
+
}
|
|
1123
|
+
const target = parseNonEmptyString(params.targetCommitish);
|
|
1124
|
+
if (target) {
|
|
1125
|
+
args.push("-f", `target_commitish=${target}`);
|
|
1126
|
+
}
|
|
1127
|
+
if (typeof params.prerelease === "boolean") {
|
|
1128
|
+
args.push("-F", `prerelease=${params.prerelease ? "true" : "false"}`);
|
|
1129
|
+
}
|
|
1130
|
+
return args;
|
|
1131
|
+
}
|
|
1132
|
+
if (capabilityId === "release.publish_draft") {
|
|
1133
|
+
requireRepo(owner, name, capabilityId);
|
|
1134
|
+
const releaseId = parseStrictPositiveInt(params.releaseId);
|
|
1135
|
+
if (releaseId === null) {
|
|
1136
|
+
throw new Error("Missing or invalid releaseId for release.publish_draft");
|
|
1137
|
+
}
|
|
1138
|
+
const args = [
|
|
1139
|
+
...commandTokens(card, "api"),
|
|
1140
|
+
`repos/${owner}/${name}/releases/${releaseId}`,
|
|
1141
|
+
"--method",
|
|
1142
|
+
"PATCH",
|
|
1143
|
+
"-F",
|
|
1144
|
+
"draft=false"
|
|
1145
|
+
];
|
|
1146
|
+
const title = parseNonEmptyString(params.title);
|
|
1147
|
+
if (title) {
|
|
1148
|
+
args.push("-f", `name=${title}`);
|
|
1149
|
+
}
|
|
1150
|
+
const notes = parseNonEmptyString(params.notes);
|
|
1151
|
+
if (notes) {
|
|
1152
|
+
args.push("-f", `body=${notes}`);
|
|
1153
|
+
}
|
|
1154
|
+
if (typeof params.prerelease === "boolean") {
|
|
1155
|
+
args.push("-F", `prerelease=${params.prerelease ? "true" : "false"}`);
|
|
1156
|
+
}
|
|
1157
|
+
return args;
|
|
1158
|
+
}
|
|
1159
|
+
if (capabilityId === "workflow_dispatch.run") {
|
|
1160
|
+
requireRepo(owner, name, capabilityId);
|
|
1161
|
+
const workflowId = parseNonEmptyString(params.workflowId);
|
|
1162
|
+
if (workflowId === null) {
|
|
1163
|
+
throw new Error("Missing or invalid workflowId for workflow_dispatch.run");
|
|
1164
|
+
}
|
|
1165
|
+
const ref = parseNonEmptyString(params.ref);
|
|
1166
|
+
if (ref === null) {
|
|
1167
|
+
throw new Error("Missing or invalid ref for workflow_dispatch.run");
|
|
1168
|
+
}
|
|
1169
|
+
const args = [
|
|
1170
|
+
...commandTokens(card, "api"),
|
|
1171
|
+
`repos/${owner}/${name}/actions/workflows/${encodeURIComponent(workflowId)}/dispatches`,
|
|
1172
|
+
"--method",
|
|
1173
|
+
"POST",
|
|
1174
|
+
"-f",
|
|
1175
|
+
`ref=${ref}`
|
|
1176
|
+
];
|
|
1177
|
+
if (params.inputs !== void 0) {
|
|
1178
|
+
if (typeof params.inputs !== "object" || params.inputs === null || Array.isArray(params.inputs)) {
|
|
1179
|
+
throw new Error("Missing or invalid inputs for workflow_dispatch.run");
|
|
1180
|
+
}
|
|
1181
|
+
const inputEntries = Object.entries(params.inputs);
|
|
1182
|
+
for (const [key, value] of inputEntries) {
|
|
1183
|
+
if (!key.trim()) {
|
|
1184
|
+
throw new Error("Missing or invalid inputs for workflow_dispatch.run");
|
|
1185
|
+
}
|
|
1186
|
+
if (!(typeof value === "string" || typeof value === "number" || typeof value === "boolean")) {
|
|
1187
|
+
throw new Error("Missing or invalid inputs for workflow_dispatch.run");
|
|
1188
|
+
}
|
|
1189
|
+
args.push("-f", `inputs[${key}]=${String(value)}`);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
return args;
|
|
1193
|
+
}
|
|
1194
|
+
if (capabilityId === "workflow_run.rerun_failed") {
|
|
1195
|
+
requireRepo(owner, name, capabilityId);
|
|
1196
|
+
const runId = parseStrictPositiveInt(params.runId);
|
|
1197
|
+
if (runId === null) {
|
|
1198
|
+
throw new Error("Missing or invalid runId for workflow_run.rerun_failed");
|
|
1199
|
+
}
|
|
1200
|
+
const args = [
|
|
1201
|
+
...commandTokens(card, "api"),
|
|
1202
|
+
`repos/${owner}/${name}/actions/runs/${runId}/rerun-failed-jobs`,
|
|
1203
|
+
"--method",
|
|
1204
|
+
"POST"
|
|
1205
|
+
];
|
|
1206
|
+
return args;
|
|
1207
|
+
}
|
|
1208
|
+
if (capabilityId === "project_v2.item.add_issue") {
|
|
1209
|
+
const projectNumber = parseStrictPositiveInt(params.projectNumber);
|
|
1210
|
+
const projectOwner = parseNonEmptyString(params.owner);
|
|
1211
|
+
const issueUrl = parseNonEmptyString(params.issueUrl);
|
|
1212
|
+
if (projectNumber === null || projectOwner === null || issueUrl === null) {
|
|
1213
|
+
throw new Error(
|
|
1214
|
+
"Missing or invalid owner/projectNumber/issueUrl for project_v2.item.add_issue"
|
|
1215
|
+
);
|
|
1216
|
+
}
|
|
1217
|
+
const args = [
|
|
1218
|
+
...commandTokens(card, "project item-add"),
|
|
1219
|
+
String(projectNumber),
|
|
1220
|
+
"--owner",
|
|
1221
|
+
projectOwner,
|
|
1222
|
+
"--url",
|
|
1223
|
+
issueUrl,
|
|
1224
|
+
"--format",
|
|
1225
|
+
"json"
|
|
1226
|
+
];
|
|
1227
|
+
return args;
|
|
1228
|
+
}
|
|
1229
|
+
if (capabilityId === "project_v2.item.field.update") {
|
|
1230
|
+
const projectId = parseNonEmptyString(params.projectId);
|
|
1231
|
+
const itemId = parseNonEmptyString(params.itemId);
|
|
1232
|
+
const fieldId = parseNonEmptyString(params.fieldId);
|
|
1233
|
+
if (projectId === null || itemId === null || fieldId === null) {
|
|
1234
|
+
throw new Error(
|
|
1235
|
+
"Missing or invalid projectId/itemId/fieldId for project_v2.item.field.update"
|
|
1236
|
+
);
|
|
1237
|
+
}
|
|
1238
|
+
const args = [
|
|
1239
|
+
...commandTokens(card, "project item-edit"),
|
|
1240
|
+
"--project-id",
|
|
1241
|
+
projectId,
|
|
1242
|
+
"--id",
|
|
1243
|
+
itemId,
|
|
1244
|
+
"--field-id",
|
|
1245
|
+
fieldId
|
|
1246
|
+
];
|
|
1247
|
+
const valueText = parseNonEmptyString(params.valueText);
|
|
1248
|
+
const valueDate = parseNonEmptyString(params.valueDate);
|
|
1249
|
+
const valueSingleSelectOptionId = parseNonEmptyString(params.valueSingleSelectOptionId);
|
|
1250
|
+
const valueIterationId = parseNonEmptyString(params.valueIterationId);
|
|
1251
|
+
const clear = params.clear === true;
|
|
1252
|
+
if (valueText !== null) {
|
|
1253
|
+
args.push("--text", valueText);
|
|
1254
|
+
} else if (typeof params.valueNumber === "number" && Number.isFinite(params.valueNumber)) {
|
|
1255
|
+
args.push("--number", String(params.valueNumber));
|
|
1256
|
+
} else if (valueDate !== null) {
|
|
1257
|
+
args.push("--date", valueDate);
|
|
1258
|
+
} else if (valueSingleSelectOptionId !== null) {
|
|
1259
|
+
args.push("--single-select-option-id", valueSingleSelectOptionId);
|
|
1260
|
+
} else if (valueIterationId !== null) {
|
|
1261
|
+
args.push("--iteration-id", valueIterationId);
|
|
1262
|
+
} else if (clear) {
|
|
1263
|
+
args.push("--clear");
|
|
1264
|
+
} else {
|
|
1265
|
+
throw new Error("Missing field value update for project_v2.item.field.update");
|
|
1266
|
+
}
|
|
1267
|
+
return args;
|
|
1268
|
+
}
|
|
1269
|
+
throw new Error(`Unsupported CLI capability: ${capabilityId}`);
|
|
1270
|
+
}
|
|
1271
|
+
function parseCliData(stdout) {
|
|
1272
|
+
const trimmed = stdout.trim();
|
|
1273
|
+
if (!trimmed) {
|
|
1274
|
+
return {};
|
|
1275
|
+
}
|
|
1276
|
+
return JSON.parse(trimmed);
|
|
1277
|
+
}
|
|
1278
|
+
function normalizeListItem(item) {
|
|
1279
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
1280
|
+
return {};
|
|
1281
|
+
}
|
|
1282
|
+
const input = item;
|
|
1283
|
+
return {
|
|
1284
|
+
id: input.id,
|
|
1285
|
+
number: input.number,
|
|
1286
|
+
title: input.title,
|
|
1287
|
+
state: input.state,
|
|
1288
|
+
url: input.url
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
function normalizeWorkflowItem(item) {
|
|
1292
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
1293
|
+
return {
|
|
1294
|
+
id: 0,
|
|
1295
|
+
name: null,
|
|
1296
|
+
path: null,
|
|
1297
|
+
state: null
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
const input = item;
|
|
1301
|
+
return {
|
|
1302
|
+
id: typeof input.id === "number" ? input.id : 0,
|
|
1303
|
+
name: typeof input.name === "string" ? input.name : null,
|
|
1304
|
+
path: typeof input.path === "string" ? input.path : null,
|
|
1305
|
+
state: typeof input.state === "string" ? input.state : null
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
function normalizeProjectV2Summary(data) {
|
|
1309
|
+
const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1310
|
+
return {
|
|
1311
|
+
id: typeof input.id === "string" ? input.id : null,
|
|
1312
|
+
title: typeof input.title === "string" ? input.title : null,
|
|
1313
|
+
shortDescription: typeof input.shortDescription === "string" ? input.shortDescription : null,
|
|
1314
|
+
public: typeof input.public === "boolean" ? input.public : null,
|
|
1315
|
+
closed: typeof input.closed === "boolean" ? input.closed : null,
|
|
1316
|
+
url: typeof input.url === "string" ? input.url : null
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
function normalizeCheckItem(item) {
|
|
1320
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
1321
|
+
return {
|
|
1322
|
+
name: null,
|
|
1323
|
+
state: null,
|
|
1324
|
+
bucket: null,
|
|
1325
|
+
workflow: null,
|
|
1326
|
+
link: null
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
const input = item;
|
|
1330
|
+
return {
|
|
1331
|
+
name: typeof input.name === "string" ? input.name : null,
|
|
1332
|
+
state: typeof input.state === "string" ? input.state : null,
|
|
1333
|
+
bucket: typeof input.bucket === "string" ? input.bucket : null,
|
|
1334
|
+
workflow: typeof input.workflow === "string" ? input.workflow : null,
|
|
1335
|
+
link: typeof input.link === "string" ? input.link : null
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
function normalizeCheckBucket(value) {
|
|
1339
|
+
if (typeof value !== "string") {
|
|
1340
|
+
return null;
|
|
1341
|
+
}
|
|
1342
|
+
return value.trim().toLowerCase();
|
|
1343
|
+
}
|
|
1344
|
+
function isCheckFailureBucket(bucket) {
|
|
1345
|
+
const normalized = normalizeCheckBucket(bucket);
|
|
1346
|
+
if (!normalized) {
|
|
1347
|
+
return false;
|
|
1348
|
+
}
|
|
1349
|
+
return normalized === "fail" || normalized === "cancel";
|
|
1350
|
+
}
|
|
1351
|
+
function isCheckPendingBucket(bucket) {
|
|
1352
|
+
const normalized = normalizeCheckBucket(bucket);
|
|
1353
|
+
if (!normalized) {
|
|
1354
|
+
return false;
|
|
1355
|
+
}
|
|
1356
|
+
return normalized === "pending";
|
|
1357
|
+
}
|
|
1358
|
+
function isCheckPassBucket(bucket) {
|
|
1359
|
+
const normalized = normalizeCheckBucket(bucket);
|
|
1360
|
+
if (!normalized) {
|
|
1361
|
+
return false;
|
|
1362
|
+
}
|
|
1363
|
+
return normalized === "pass";
|
|
1364
|
+
}
|
|
1365
|
+
function normalizeCliData(capabilityId, data, params) {
|
|
1366
|
+
const normalizeRelease = (input) => {
|
|
1367
|
+
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
1368
|
+
return {
|
|
1369
|
+
id: 0,
|
|
1370
|
+
tagName: null,
|
|
1371
|
+
name: null,
|
|
1372
|
+
isDraft: false,
|
|
1373
|
+
isPrerelease: false,
|
|
1374
|
+
url: null,
|
|
1375
|
+
targetCommitish: null,
|
|
1376
|
+
createdAt: null,
|
|
1377
|
+
publishedAt: null
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
const record = input;
|
|
1381
|
+
return {
|
|
1382
|
+
id: typeof record.id === "number" ? record.id : 0,
|
|
1383
|
+
tagName: typeof record.tag_name === "string" ? record.tag_name : null,
|
|
1384
|
+
name: typeof record.name === "string" ? record.name : null,
|
|
1385
|
+
isDraft: typeof record.draft === "boolean" ? record.draft : false,
|
|
1386
|
+
isPrerelease: typeof record.prerelease === "boolean" ? record.prerelease : false,
|
|
1387
|
+
url: typeof record.html_url === "string" ? record.html_url : null,
|
|
1388
|
+
targetCommitish: typeof record.target_commitish === "string" ? record.target_commitish : null,
|
|
1389
|
+
createdAt: typeof record.created_at === "string" ? record.created_at : null,
|
|
1390
|
+
publishedAt: typeof record.published_at === "string" ? record.published_at : null
|
|
1391
|
+
};
|
|
1392
|
+
};
|
|
1393
|
+
if (capabilityId === "repo.view") {
|
|
1394
|
+
const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1395
|
+
const defaultBranchRef = typeof input.defaultBranchRef === "object" && input.defaultBranchRef !== null ? input.defaultBranchRef : null;
|
|
1396
|
+
return {
|
|
1397
|
+
id: input.id,
|
|
1398
|
+
name: input.name,
|
|
1399
|
+
nameWithOwner: input.nameWithOwner,
|
|
1400
|
+
isPrivate: input.isPrivate,
|
|
1401
|
+
stargazerCount: input.stargazerCount,
|
|
1402
|
+
forkCount: input.forkCount,
|
|
1403
|
+
url: input.url,
|
|
1404
|
+
defaultBranch: typeof defaultBranchRef?.name === "string" ? defaultBranchRef.name : null
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
if (capabilityId === "repo.labels.list") {
|
|
1408
|
+
const labels = Array.isArray(data) ? data : [];
|
|
1409
|
+
return {
|
|
1410
|
+
items: labels.map((label) => {
|
|
1411
|
+
if (typeof label !== "object" || label === null || Array.isArray(label)) {
|
|
1412
|
+
return {
|
|
1413
|
+
id: null,
|
|
1414
|
+
name: null,
|
|
1415
|
+
description: null,
|
|
1416
|
+
color: null,
|
|
1417
|
+
isDefault: null
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
const record = label;
|
|
1421
|
+
return {
|
|
1422
|
+
id: typeof record.id === "string" ? record.id : null,
|
|
1423
|
+
name: typeof record.name === "string" ? record.name : null,
|
|
1424
|
+
description: typeof record.description === "string" ? record.description : null,
|
|
1425
|
+
color: typeof record.color === "string" ? record.color : null,
|
|
1426
|
+
isDefault: typeof record.isDefault === "boolean" ? record.isDefault : null
|
|
1427
|
+
};
|
|
1428
|
+
}),
|
|
1429
|
+
pageInfo: {
|
|
1430
|
+
hasNextPage: false,
|
|
1431
|
+
endCursor: null
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
if (capabilityId === "repo.issue_types.list") {
|
|
1436
|
+
const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1437
|
+
const payload = typeof root.data === "object" && root.data !== null && !Array.isArray(root.data) ? root.data : {};
|
|
1438
|
+
const repository = typeof payload.repository === "object" && payload.repository !== null && !Array.isArray(payload.repository) ? payload.repository : {};
|
|
1439
|
+
const connection = typeof repository.issueTypes === "object" && repository.issueTypes !== null && !Array.isArray(repository.issueTypes) ? repository.issueTypes : {};
|
|
1440
|
+
const nodes = Array.isArray(connection.nodes) ? connection.nodes : [];
|
|
1441
|
+
const pageInfo = typeof connection.pageInfo === "object" && connection.pageInfo !== null && !Array.isArray(connection.pageInfo) ? connection.pageInfo : {};
|
|
1442
|
+
return {
|
|
1443
|
+
items: nodes.map((node) => {
|
|
1444
|
+
if (typeof node !== "object" || node === null || Array.isArray(node)) {
|
|
1445
|
+
return {
|
|
1446
|
+
id: null,
|
|
1447
|
+
name: null,
|
|
1448
|
+
color: null,
|
|
1449
|
+
isEnabled: null
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
const record = node;
|
|
1453
|
+
return {
|
|
1454
|
+
id: typeof record.id === "string" ? record.id : null,
|
|
1455
|
+
name: typeof record.name === "string" ? record.name : null,
|
|
1456
|
+
color: typeof record.color === "string" ? record.color : null,
|
|
1457
|
+
isEnabled: typeof record.isEnabled === "boolean" ? record.isEnabled : null
|
|
1458
|
+
};
|
|
1459
|
+
}),
|
|
1460
|
+
pageInfo: {
|
|
1461
|
+
hasNextPage: typeof pageInfo.hasNextPage === "boolean" ? pageInfo.hasNextPage : false,
|
|
1462
|
+
endCursor: typeof pageInfo.endCursor === "string" ? pageInfo.endCursor : null
|
|
1463
|
+
}
|
|
1464
|
+
};
|
|
1465
|
+
}
|
|
1466
|
+
if (capabilityId === "issue.list" || capabilityId === "pr.list") {
|
|
1467
|
+
const items = Array.isArray(data) ? data.map((entry) => normalizeListItem(entry)) : [];
|
|
1468
|
+
return {
|
|
1469
|
+
items,
|
|
1470
|
+
pageInfo: {
|
|
1471
|
+
hasNextPage: false,
|
|
1472
|
+
endCursor: null
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
if (capabilityId === "issue.comments.list") {
|
|
1477
|
+
if (parseStrictPositiveInt(params.first) === null) {
|
|
1478
|
+
throw new Error("Missing or invalid first for issue.comments.list");
|
|
1479
|
+
}
|
|
1480
|
+
const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1481
|
+
const commentsConnection = typeof input.data === "object" && input.data !== null && !Array.isArray(input.data) ? input.data.repository : null;
|
|
1482
|
+
const repository = typeof commentsConnection === "object" && commentsConnection !== null && !Array.isArray(commentsConnection) ? commentsConnection : null;
|
|
1483
|
+
const issue = typeof repository?.issue === "object" && repository.issue !== null && !Array.isArray(repository.issue) ? repository.issue : null;
|
|
1484
|
+
const comments = typeof issue?.comments === "object" && issue.comments !== null && !Array.isArray(issue.comments) ? issue.comments : null;
|
|
1485
|
+
const nodes = Array.isArray(comments?.nodes) ? comments.nodes : null;
|
|
1486
|
+
const pageInfo = typeof comments?.pageInfo === "object" && comments.pageInfo !== null && !Array.isArray(comments.pageInfo) ? comments.pageInfo : null;
|
|
1487
|
+
if (nodes === null || pageInfo === null || typeof pageInfo.hasNextPage !== "boolean") {
|
|
1488
|
+
throw new Error("Invalid CLI payload: comments connection is malformed");
|
|
1489
|
+
}
|
|
1490
|
+
const normalizedItems = nodes.flatMap((comment) => {
|
|
1491
|
+
if (typeof comment !== "object" || comment === null || Array.isArray(comment)) {
|
|
1492
|
+
throw new Error("Invalid CLI payload: comment item must be an object");
|
|
1493
|
+
}
|
|
1494
|
+
const commentRecord = comment;
|
|
1495
|
+
const author = typeof commentRecord.author === "object" && commentRecord.author !== null ? commentRecord.author : null;
|
|
1496
|
+
if (typeof commentRecord.id !== "string" || typeof commentRecord.body !== "string" || typeof commentRecord.url !== "string" || typeof commentRecord.createdAt !== "string") {
|
|
1497
|
+
throw new Error("Invalid CLI payload: comment item has invalid field types");
|
|
1498
|
+
}
|
|
1499
|
+
return [
|
|
1500
|
+
{
|
|
1501
|
+
id: commentRecord.id,
|
|
1502
|
+
body: commentRecord.body,
|
|
1503
|
+
authorLogin: typeof author?.login === "string" ? author.login : null,
|
|
1504
|
+
url: commentRecord.url,
|
|
1505
|
+
createdAt: commentRecord.createdAt
|
|
1506
|
+
}
|
|
1507
|
+
];
|
|
1508
|
+
});
|
|
1509
|
+
return {
|
|
1510
|
+
items: normalizedItems,
|
|
1511
|
+
pageInfo: {
|
|
1512
|
+
hasNextPage: pageInfo.hasNextPage,
|
|
1513
|
+
endCursor: typeof pageInfo.endCursor === "string" ? pageInfo.endCursor : null
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
if (capabilityId === "pr.status.checks" || capabilityId === "pr.checks.get_failed") {
|
|
1518
|
+
const checks = Array.isArray(data) ? data.map((entry) => normalizeCheckItem(entry)) : [];
|
|
1519
|
+
const failed = checks.filter((entry) => isCheckFailureBucket(entry.bucket));
|
|
1520
|
+
const pending = checks.filter((entry) => isCheckPendingBucket(entry.bucket));
|
|
1521
|
+
const passed = checks.filter((entry) => isCheckPassBucket(entry.bucket));
|
|
1522
|
+
return {
|
|
1523
|
+
items: capabilityId === "pr.checks.get_failed" ? failed : checks,
|
|
1524
|
+
summary: {
|
|
1525
|
+
total: checks.length,
|
|
1526
|
+
failed: failed.length,
|
|
1527
|
+
pending: pending.length,
|
|
1528
|
+
passed: passed.length
|
|
1529
|
+
}
|
|
1530
|
+
};
|
|
1531
|
+
}
|
|
1532
|
+
if (capabilityId === "pr.mergeability.view") {
|
|
1533
|
+
const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1534
|
+
return {
|
|
1535
|
+
mergeable: typeof input.mergeable === "string" ? input.mergeable : null,
|
|
1536
|
+
mergeStateStatus: typeof input.mergeStateStatus === "string" ? input.mergeStateStatus : null,
|
|
1537
|
+
reviewDecision: typeof input.reviewDecision === "string" ? input.reviewDecision : null,
|
|
1538
|
+
isDraft: Boolean(input.isDraft),
|
|
1539
|
+
state: typeof input.state === "string" ? input.state : "UNKNOWN"
|
|
1540
|
+
};
|
|
1541
|
+
}
|
|
1542
|
+
if (capabilityId === "pr.ready_for_review.set") {
|
|
1543
|
+
const prNumber = Number(params.prNumber);
|
|
1544
|
+
const ready = Boolean(params.ready);
|
|
1545
|
+
return {
|
|
1546
|
+
prNumber,
|
|
1547
|
+
isDraft: !ready
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
if (capabilityId === "pr.review.submit_approve" || capabilityId === "pr.review.submit_request_changes" || capabilityId === "pr.review.submit_comment") {
|
|
1551
|
+
const prNumber = Number(params.prNumber);
|
|
1552
|
+
const event = capabilityId === "pr.review.submit_approve" ? "APPROVE" : capabilityId === "pr.review.submit_request_changes" ? "REQUEST_CHANGES" : "COMMENT";
|
|
1553
|
+
return {
|
|
1554
|
+
prNumber,
|
|
1555
|
+
event,
|
|
1556
|
+
submitted: true,
|
|
1557
|
+
body: typeof params.body === "string" ? params.body : null
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
if (capabilityId === "pr.merge.execute") {
|
|
1561
|
+
const method = params.method === "squash" || params.method === "rebase" ? params.method : "merge";
|
|
1562
|
+
return {
|
|
1563
|
+
prNumber: Number(params.prNumber),
|
|
1564
|
+
method,
|
|
1565
|
+
queued: true,
|
|
1566
|
+
deleteBranch: params.deleteBranch === true
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
if (capabilityId === "pr.checks.rerun_failed" || capabilityId === "pr.checks.rerun_all") {
|
|
1570
|
+
const effectiveMode = params.__effectiveRerunMode === "all" ? "all" : capabilityId === "pr.checks.rerun_failed" ? "failed" : "all";
|
|
1571
|
+
return {
|
|
1572
|
+
prNumber: Number(params.prNumber),
|
|
1573
|
+
runId: Number(params.runId),
|
|
1574
|
+
mode: effectiveMode,
|
|
1575
|
+
queued: true
|
|
1576
|
+
};
|
|
1577
|
+
}
|
|
1578
|
+
if (capabilityId === "pr.reviewers.request") {
|
|
1579
|
+
const reviewers = Array.isArray(params.reviewers) ? params.reviewers.filter(
|
|
1580
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
1581
|
+
) : [];
|
|
1582
|
+
return {
|
|
1583
|
+
prNumber: Number(params.prNumber),
|
|
1584
|
+
reviewers,
|
|
1585
|
+
updated: true
|
|
1586
|
+
};
|
|
1587
|
+
}
|
|
1588
|
+
if (capabilityId === "pr.assignees.update") {
|
|
1589
|
+
const add = Array.isArray(params.add) ? params.add.filter(
|
|
1590
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
1591
|
+
) : [];
|
|
1592
|
+
const remove = Array.isArray(params.remove) ? params.remove.filter(
|
|
1593
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
1594
|
+
) : [];
|
|
1595
|
+
return {
|
|
1596
|
+
prNumber: Number(params.prNumber),
|
|
1597
|
+
add,
|
|
1598
|
+
remove,
|
|
1599
|
+
updated: true
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
if (capabilityId === "pr.branch.update") {
|
|
1603
|
+
return {
|
|
1604
|
+
prNumber: Number(params.prNumber),
|
|
1605
|
+
updated: true
|
|
1606
|
+
};
|
|
1607
|
+
}
|
|
1608
|
+
if (capabilityId === "check_run.annotations.list") {
|
|
1609
|
+
const annotations = Array.isArray(data) ? data : [];
|
|
1610
|
+
return {
|
|
1611
|
+
items: annotations.map((annotation) => {
|
|
1612
|
+
if (typeof annotation !== "object" || annotation === null || Array.isArray(annotation)) {
|
|
1613
|
+
return {
|
|
1614
|
+
path: null,
|
|
1615
|
+
startLine: null,
|
|
1616
|
+
endLine: null,
|
|
1617
|
+
level: null,
|
|
1618
|
+
message: null,
|
|
1619
|
+
title: null,
|
|
1620
|
+
details: null
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
const record = annotation;
|
|
1624
|
+
return {
|
|
1625
|
+
path: typeof record.path === "string" ? record.path : null,
|
|
1626
|
+
startLine: typeof record.start_line === "number" ? record.start_line : null,
|
|
1627
|
+
endLine: typeof record.end_line === "number" ? record.end_line : null,
|
|
1628
|
+
level: typeof record.annotation_level === "string" ? record.annotation_level : null,
|
|
1629
|
+
message: typeof record.message === "string" ? record.message : null,
|
|
1630
|
+
title: typeof record.title === "string" ? record.title : null,
|
|
1631
|
+
details: typeof record.raw_details === "string" ? record.raw_details : null
|
|
1632
|
+
};
|
|
1633
|
+
})
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
if (capabilityId === "workflow_runs.list") {
|
|
1637
|
+
const runs = Array.isArray(data) ? data : [];
|
|
1638
|
+
return {
|
|
1639
|
+
items: runs.map((run) => {
|
|
1640
|
+
if (typeof run !== "object" || run === null || Array.isArray(run)) {
|
|
1641
|
+
return {
|
|
1642
|
+
id: 0,
|
|
1643
|
+
workflowName: null,
|
|
1644
|
+
status: null,
|
|
1645
|
+
conclusion: null,
|
|
1646
|
+
headBranch: null,
|
|
1647
|
+
url: null
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
const record = run;
|
|
1651
|
+
return {
|
|
1652
|
+
id: typeof record.databaseId === "number" ? record.databaseId : 0,
|
|
1653
|
+
workflowName: typeof record.workflowName === "string" ? record.workflowName : null,
|
|
1654
|
+
status: typeof record.status === "string" ? record.status : null,
|
|
1655
|
+
conclusion: typeof record.conclusion === "string" ? record.conclusion : null,
|
|
1656
|
+
headBranch: typeof record.headBranch === "string" ? record.headBranch : null,
|
|
1657
|
+
url: typeof record.url === "string" ? record.url : null
|
|
1658
|
+
};
|
|
1659
|
+
}),
|
|
1660
|
+
pageInfo: {
|
|
1661
|
+
hasNextPage: false,
|
|
1662
|
+
endCursor: null
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
if (capabilityId === "workflow_run.jobs.list") {
|
|
1667
|
+
const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1668
|
+
const jobs = Array.isArray(root.jobs) ? root.jobs : [];
|
|
1669
|
+
return {
|
|
1670
|
+
items: jobs.map((job) => {
|
|
1671
|
+
if (typeof job !== "object" || job === null || Array.isArray(job)) {
|
|
1672
|
+
return {
|
|
1673
|
+
id: 0,
|
|
1674
|
+
name: null,
|
|
1675
|
+
status: null,
|
|
1676
|
+
conclusion: null,
|
|
1677
|
+
startedAt: null,
|
|
1678
|
+
completedAt: null,
|
|
1679
|
+
url: null
|
|
1680
|
+
};
|
|
1681
|
+
}
|
|
1682
|
+
const record = job;
|
|
1683
|
+
return {
|
|
1684
|
+
id: typeof record.databaseId === "number" ? record.databaseId : 0,
|
|
1685
|
+
name: typeof record.name === "string" ? record.name : null,
|
|
1686
|
+
status: typeof record.status === "string" ? record.status : null,
|
|
1687
|
+
conclusion: typeof record.conclusion === "string" ? record.conclusion : null,
|
|
1688
|
+
startedAt: typeof record.startedAt === "string" ? record.startedAt : null,
|
|
1689
|
+
completedAt: typeof record.completedAt === "string" ? record.completedAt : null,
|
|
1690
|
+
url: typeof record.url === "string" ? record.url : null
|
|
1691
|
+
};
|
|
1692
|
+
})
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
if (capabilityId === "workflow_job.logs.get") {
|
|
1696
|
+
const jobId = Number(params.jobId);
|
|
1697
|
+
const rawLog = typeof data === "string" ? data : String(data);
|
|
1698
|
+
const truncated = rawLog.length > MAX_WORKFLOW_JOB_LOG_CHARS;
|
|
1699
|
+
return {
|
|
1700
|
+
jobId,
|
|
1701
|
+
log: truncated ? rawLog.slice(0, MAX_WORKFLOW_JOB_LOG_CHARS) : rawLog,
|
|
1702
|
+
truncated
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
if (capabilityId === "workflow_job.logs.analyze") {
|
|
1706
|
+
const jobId = Number(params.jobId);
|
|
1707
|
+
const rawLog = typeof data === "string" ? data : String(data);
|
|
1708
|
+
const truncated = rawLog.length > MAX_WORKFLOW_JOB_LOG_CHARS;
|
|
1709
|
+
const boundedLog = truncated ? rawLog.slice(0, MAX_WORKFLOW_JOB_LOG_CHARS) : rawLog;
|
|
1710
|
+
const lines = boundedLog.split(/\r?\n/);
|
|
1711
|
+
const errorLines = lines.filter((line) => /\berror\b/i.test(line));
|
|
1712
|
+
const topErrorLines = errorLines.slice(0, 10);
|
|
1713
|
+
const warningLines = lines.filter((line) => /\bwarn(ing)?\b/i.test(line));
|
|
1714
|
+
return {
|
|
1715
|
+
jobId,
|
|
1716
|
+
truncated,
|
|
1717
|
+
summary: {
|
|
1718
|
+
errorCount: errorLines.length,
|
|
1719
|
+
warningCount: warningLines.length,
|
|
1720
|
+
topErrorLines
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
if (capabilityId === "workflow.list") {
|
|
1725
|
+
const workflows = Array.isArray(data) ? data : [];
|
|
1726
|
+
return {
|
|
1727
|
+
items: workflows.map((workflow) => normalizeWorkflowItem(workflow)),
|
|
1728
|
+
pageInfo: {
|
|
1729
|
+
hasNextPage: false,
|
|
1730
|
+
endCursor: null
|
|
1731
|
+
}
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
if (capabilityId === "release.list") {
|
|
1735
|
+
const items = Array.isArray(data) ? data.map((item) => normalizeRelease(item)) : [];
|
|
1736
|
+
return {
|
|
1737
|
+
items,
|
|
1738
|
+
pageInfo: {
|
|
1739
|
+
hasNextPage: false,
|
|
1740
|
+
endCursor: null
|
|
1741
|
+
}
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
if (capabilityId === "workflow.get") {
|
|
1745
|
+
const input = normalizeWorkflowItem(data);
|
|
1746
|
+
const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1747
|
+
return {
|
|
1748
|
+
...input,
|
|
1749
|
+
url: typeof root.url === "string" ? root.url : null
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
if (capabilityId === "workflow_run.get") {
|
|
1753
|
+
const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1754
|
+
return {
|
|
1755
|
+
id: typeof input.databaseId === "number" ? input.databaseId : 0,
|
|
1756
|
+
workflowName: typeof input.workflowName === "string" ? input.workflowName : null,
|
|
1757
|
+
status: typeof input.status === "string" ? input.status : null,
|
|
1758
|
+
conclusion: typeof input.conclusion === "string" ? input.conclusion : null,
|
|
1759
|
+
headBranch: typeof input.headBranch === "string" ? input.headBranch : null,
|
|
1760
|
+
headSha: typeof input.headSha === "string" ? input.headSha : null,
|
|
1761
|
+
event: typeof input.event === "string" ? input.event : null,
|
|
1762
|
+
createdAt: typeof input.createdAt === "string" ? input.createdAt : null,
|
|
1763
|
+
updatedAt: typeof input.updatedAt === "string" ? input.updatedAt : null,
|
|
1764
|
+
startedAt: typeof input.startedAt === "string" ? input.startedAt : null,
|
|
1765
|
+
url: typeof input.url === "string" ? input.url : null
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
if (capabilityId === "workflow_run.rerun_all") {
|
|
1769
|
+
return {
|
|
1770
|
+
runId: Number(params.runId),
|
|
1771
|
+
status: "requested"
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
if (capabilityId === "workflow_run.cancel") {
|
|
1775
|
+
return {
|
|
1776
|
+
runId: Number(params.runId),
|
|
1777
|
+
status: "cancel_requested"
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
if (capabilityId === "workflow_run.artifacts.list") {
|
|
1781
|
+
const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1782
|
+
const artifacts = Array.isArray(root.artifacts) ? root.artifacts : [];
|
|
1783
|
+
return {
|
|
1784
|
+
items: artifacts.map((artifact) => {
|
|
1785
|
+
if (typeof artifact !== "object" || artifact === null || Array.isArray(artifact)) {
|
|
1786
|
+
return {
|
|
1787
|
+
id: 0,
|
|
1788
|
+
name: null,
|
|
1789
|
+
sizeInBytes: null,
|
|
1790
|
+
archiveDownloadUrl: null
|
|
1791
|
+
};
|
|
1792
|
+
}
|
|
1793
|
+
const record = artifact;
|
|
1794
|
+
return {
|
|
1795
|
+
id: typeof record.id === "number" ? record.id : 0,
|
|
1796
|
+
name: typeof record.name === "string" ? record.name : null,
|
|
1797
|
+
sizeInBytes: typeof record.sizeInBytes === "number" ? record.sizeInBytes : null,
|
|
1798
|
+
archiveDownloadUrl: typeof record.archiveDownloadUrl === "string" ? record.archiveDownloadUrl : null
|
|
1799
|
+
};
|
|
1800
|
+
}),
|
|
1801
|
+
pageInfo: {
|
|
1802
|
+
hasNextPage: false,
|
|
1803
|
+
endCursor: null
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
}
|
|
1807
|
+
if (capabilityId === "project_v2.org.get" || capabilityId === "project_v2.user.get") {
|
|
1808
|
+
return normalizeProjectV2Summary(data);
|
|
1809
|
+
}
|
|
1810
|
+
if (capabilityId === "project_v2.fields.list") {
|
|
1811
|
+
const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1812
|
+
const fields = Array.isArray(root.fields) ? root.fields : [];
|
|
1813
|
+
return {
|
|
1814
|
+
items: fields.map((field) => {
|
|
1815
|
+
if (typeof field !== "object" || field === null || Array.isArray(field)) {
|
|
1816
|
+
return {
|
|
1817
|
+
id: null,
|
|
1818
|
+
name: null,
|
|
1819
|
+
dataType: null
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1822
|
+
const record = field;
|
|
1823
|
+
return {
|
|
1824
|
+
id: typeof record.id === "string" ? record.id : null,
|
|
1825
|
+
name: typeof record.name === "string" ? record.name : null,
|
|
1826
|
+
dataType: typeof record.dataType === "string" ? record.dataType : null
|
|
1827
|
+
};
|
|
1828
|
+
}),
|
|
1829
|
+
pageInfo: {
|
|
1830
|
+
hasNextPage: false,
|
|
1831
|
+
endCursor: null
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
}
|
|
1835
|
+
if (capabilityId === "project_v2.items.list") {
|
|
1836
|
+
const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1837
|
+
const items = Array.isArray(root.items) ? root.items : [];
|
|
1838
|
+
return {
|
|
1839
|
+
items: items.map((item) => {
|
|
1840
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
1841
|
+
return {
|
|
1842
|
+
id: null,
|
|
1843
|
+
contentType: null,
|
|
1844
|
+
contentNumber: null,
|
|
1845
|
+
contentTitle: null
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
const record = item;
|
|
1849
|
+
const content = typeof record.content === "object" && record.content !== null && !Array.isArray(record.content) ? record.content : {};
|
|
1850
|
+
return {
|
|
1851
|
+
id: typeof record.id === "string" ? record.id : null,
|
|
1852
|
+
contentType: typeof content.type === "string" ? content.type : null,
|
|
1853
|
+
contentNumber: typeof content.number === "number" ? content.number : null,
|
|
1854
|
+
contentTitle: typeof content.title === "string" ? content.title : null
|
|
1855
|
+
};
|
|
1856
|
+
}),
|
|
1857
|
+
pageInfo: {
|
|
1858
|
+
hasNextPage: false,
|
|
1859
|
+
endCursor: null
|
|
1860
|
+
}
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
if (capabilityId === "project_v2.item.add_issue") {
|
|
1864
|
+
const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
|
|
1865
|
+
return {
|
|
1866
|
+
itemId: typeof root.id === "string" ? root.id : null,
|
|
1867
|
+
added: true
|
|
1868
|
+
};
|
|
1869
|
+
}
|
|
1870
|
+
if (capabilityId === "project_v2.item.field.update") {
|
|
1871
|
+
return {
|
|
1872
|
+
itemId: parseNonEmptyString(params.itemId),
|
|
1873
|
+
updated: true
|
|
1874
|
+
};
|
|
1875
|
+
}
|
|
1876
|
+
if (capabilityId === "release.get" || capabilityId === "release.create_draft" || capabilityId === "release.update") {
|
|
1877
|
+
return normalizeRelease(data);
|
|
1878
|
+
}
|
|
1879
|
+
if (capabilityId === "release.publish_draft") {
|
|
1880
|
+
const release = normalizeRelease(data);
|
|
1881
|
+
return {
|
|
1882
|
+
...release,
|
|
1883
|
+
wasDraft: Boolean(params.__wasDraft)
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
if (capabilityId === "workflow_dispatch.run") {
|
|
1887
|
+
return {
|
|
1888
|
+
workflowId: String(params.workflowId),
|
|
1889
|
+
ref: String(params.ref),
|
|
1890
|
+
dispatched: true
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
if (capabilityId === "workflow_run.rerun_failed") {
|
|
1894
|
+
return {
|
|
1895
|
+
runId: Number(params.runId),
|
|
1896
|
+
rerunFailed: true
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
if (capabilityId === "issue.view" || capabilityId === "pr.view") {
|
|
1900
|
+
return normalizeListItem(data);
|
|
1901
|
+
}
|
|
1902
|
+
return data;
|
|
1903
|
+
}
|
|
1904
|
+
async function runCliCapability(runner, capabilityId, params, card) {
|
|
1905
|
+
try {
|
|
1906
|
+
if (capabilityId === "release.publish_draft") {
|
|
1907
|
+
const owner = String(params.owner ?? "");
|
|
1908
|
+
const name = String(params.name ?? "");
|
|
1909
|
+
const releaseId = parseStrictPositiveInt(params.releaseId);
|
|
1910
|
+
if (!owner || !name || releaseId === null) {
|
|
1911
|
+
throw new Error("Missing owner/name/releaseId for release.publish_draft");
|
|
1912
|
+
}
|
|
1913
|
+
const readArgs = [
|
|
1914
|
+
...commandTokens(card, "api"),
|
|
1915
|
+
`repos/${owner}/${name}/releases/${releaseId}`
|
|
1916
|
+
];
|
|
1917
|
+
const readResult = await runner.run("gh", readArgs, DEFAULT_TIMEOUT_MS);
|
|
1918
|
+
if (readResult.exitCode !== 0) {
|
|
1919
|
+
const code = mapErrorToCode(readResult.stderr);
|
|
1920
|
+
return normalizeError(
|
|
1921
|
+
{
|
|
1922
|
+
code,
|
|
1923
|
+
message: sanitizeCliErrorMessage(readResult.stderr, readResult.exitCode),
|
|
1924
|
+
retryable: isRetryableErrorCode(code),
|
|
1925
|
+
details: { capabilityId, exitCode: readResult.exitCode }
|
|
1926
|
+
},
|
|
1927
|
+
"cli",
|
|
1928
|
+
{ capabilityId, reason: "CARD_FALLBACK" }
|
|
1929
|
+
);
|
|
1930
|
+
}
|
|
1931
|
+
const currentRelease = parseCliData(readResult.stdout);
|
|
1932
|
+
const currentDraftValue = typeof currentRelease === "object" && currentRelease !== null && !Array.isArray(currentRelease) ? currentRelease.draft : void 0;
|
|
1933
|
+
if (currentDraftValue !== true) {
|
|
1934
|
+
return normalizeError(
|
|
1935
|
+
{
|
|
1936
|
+
code: errorCodes.Validation,
|
|
1937
|
+
message: "release.publish_draft requires an existing draft release",
|
|
1938
|
+
retryable: false
|
|
1939
|
+
},
|
|
1940
|
+
"cli",
|
|
1941
|
+
{ capabilityId, reason: "CARD_FALLBACK" }
|
|
1942
|
+
);
|
|
1943
|
+
}
|
|
1944
|
+
const args2 = buildArgs(capabilityId, params, card);
|
|
1945
|
+
const result2 = await runner.run("gh", args2, DEFAULT_TIMEOUT_MS);
|
|
1946
|
+
if (result2.exitCode !== 0) {
|
|
1947
|
+
const code = mapErrorToCode(result2.stderr);
|
|
1948
|
+
return normalizeError(
|
|
1949
|
+
{
|
|
1950
|
+
code,
|
|
1951
|
+
message: sanitizeCliErrorMessage(result2.stderr, result2.exitCode),
|
|
1952
|
+
retryable: isRetryableErrorCode(code),
|
|
1953
|
+
details: { capabilityId, exitCode: result2.exitCode }
|
|
1954
|
+
},
|
|
1955
|
+
"cli",
|
|
1956
|
+
{ capabilityId, reason: "CARD_FALLBACK" }
|
|
1957
|
+
);
|
|
1958
|
+
}
|
|
1959
|
+
const normalized2 = normalizeCliData(capabilityId, parseCliData(result2.stdout), {
|
|
1960
|
+
...params,
|
|
1961
|
+
__wasDraft: true
|
|
1962
|
+
});
|
|
1963
|
+
return normalizeResult(normalized2, "cli", { capabilityId, reason: "CARD_FALLBACK" });
|
|
1964
|
+
}
|
|
1965
|
+
const args = buildArgs(capabilityId, params, card);
|
|
1966
|
+
const result = await runner.run("gh", args, DEFAULT_TIMEOUT_MS);
|
|
1967
|
+
let failureStderr = result.stderr;
|
|
1968
|
+
if (result.exitCode !== 0) {
|
|
1969
|
+
if (capabilityId === "pr.checks.rerun_failed" && shouldFallbackRerunFailedToAll(result.stderr)) {
|
|
1970
|
+
const rerunAllArgs = buildArgs("pr.checks.rerun_all", params, card);
|
|
1971
|
+
const rerunAllResult = await runner.run("gh", rerunAllArgs, DEFAULT_TIMEOUT_MS);
|
|
1972
|
+
if (rerunAllResult.exitCode === 0) {
|
|
1973
|
+
const rerunData = NON_JSON_STDOUT_CAPABILITIES.has(capabilityId) ? {} : parseCliData(rerunAllResult.stdout);
|
|
1974
|
+
const fallbackData = normalizeCliData(capabilityId, rerunData, {
|
|
1975
|
+
...params,
|
|
1976
|
+
__effectiveRerunMode: "all"
|
|
1977
|
+
});
|
|
1978
|
+
return normalizeResult(fallbackData, "cli", { capabilityId, reason: "CARD_FALLBACK" });
|
|
1979
|
+
}
|
|
1980
|
+
failureStderr = rerunAllResult.stderr || rerunAllResult.stdout || result.stderr;
|
|
1981
|
+
}
|
|
1982
|
+
const code = mapErrorToCode(failureStderr);
|
|
1983
|
+
return normalizeError(
|
|
1984
|
+
{
|
|
1985
|
+
code,
|
|
1986
|
+
message: sanitizeCliErrorMessage(failureStderr, result.exitCode),
|
|
1987
|
+
retryable: isRetryableErrorCode(code),
|
|
1988
|
+
details: { capabilityId, exitCode: result.exitCode }
|
|
1989
|
+
},
|
|
1990
|
+
"cli",
|
|
1991
|
+
{ capabilityId, reason: "CARD_FALLBACK" }
|
|
1992
|
+
);
|
|
1993
|
+
}
|
|
1994
|
+
const data = capabilityId === "workflow_job.logs.get" || capabilityId === "workflow_job.logs.analyze" ? result.stdout : NON_JSON_STDOUT_CAPABILITIES.has(capabilityId) ? {} : parseCliData(result.stdout);
|
|
1995
|
+
const normalized = normalizeCliData(capabilityId, data, params);
|
|
1996
|
+
return normalizeResult(normalized, "cli", { capabilityId, reason: "CARD_FALLBACK" });
|
|
1997
|
+
} catch (error) {
|
|
1998
|
+
if (error instanceof SyntaxError) {
|
|
1999
|
+
return normalizeError(
|
|
2000
|
+
{
|
|
2001
|
+
code: errorCodes.Server,
|
|
2002
|
+
message: "Failed to parse CLI JSON output",
|
|
2003
|
+
retryable: false
|
|
2004
|
+
},
|
|
2005
|
+
"cli",
|
|
2006
|
+
{ capabilityId, reason: "CARD_FALLBACK" }
|
|
2007
|
+
);
|
|
2008
|
+
}
|
|
2009
|
+
if (error instanceof Error && error.message.toLowerCase().includes("invalid cli payload")) {
|
|
2010
|
+
return normalizeError(
|
|
2011
|
+
{
|
|
2012
|
+
code: errorCodes.Server,
|
|
2013
|
+
message: error.message,
|
|
2014
|
+
retryable: false
|
|
2015
|
+
},
|
|
2016
|
+
"cli",
|
|
2017
|
+
{ capabilityId, reason: "CARD_FALLBACK" }
|
|
2018
|
+
);
|
|
2019
|
+
}
|
|
2020
|
+
if (error instanceof Error && error.message.toLowerCase().includes("invalid after cursor")) {
|
|
2021
|
+
return normalizeError(
|
|
2022
|
+
{
|
|
2023
|
+
code: errorCodes.Validation,
|
|
2024
|
+
message: error.message,
|
|
2025
|
+
retryable: false
|
|
2026
|
+
},
|
|
2027
|
+
"cli",
|
|
2028
|
+
{ capabilityId, reason: "CARD_FALLBACK" }
|
|
2029
|
+
);
|
|
2030
|
+
}
|
|
2031
|
+
if (error instanceof Error && error.message.toLowerCase().includes("only supports draft=true")) {
|
|
2032
|
+
return normalizeError(
|
|
2033
|
+
{
|
|
2034
|
+
code: errorCodes.Validation,
|
|
2035
|
+
message: error.message,
|
|
2036
|
+
retryable: false
|
|
2037
|
+
},
|
|
2038
|
+
"cli",
|
|
2039
|
+
{ capabilityId, reason: "CARD_FALLBACK" }
|
|
2040
|
+
);
|
|
2041
|
+
}
|
|
2042
|
+
const code = mapErrorToCode(error);
|
|
2043
|
+
return normalizeError(
|
|
2044
|
+
{
|
|
2045
|
+
code,
|
|
2046
|
+
message: error instanceof Error ? error.message : String(error),
|
|
2047
|
+
retryable: isRetryableErrorCode(code)
|
|
2048
|
+
},
|
|
2049
|
+
"cli",
|
|
2050
|
+
{ capabilityId, reason: "CARD_FALLBACK" }
|
|
2051
|
+
);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
// src/core/execution/adapters/graphql-capability-adapter.ts
|
|
2056
|
+
var DEFAULT_LIST_FIRST2 = 30;
|
|
2057
|
+
function unsupportedGraphqlCapability(capabilityId) {
|
|
2058
|
+
return normalizeError(
|
|
2059
|
+
{
|
|
2060
|
+
code: errorCodes.AdapterUnsupported,
|
|
2061
|
+
message: `Unsupported GraphQL capability: ${capabilityId}`,
|
|
2062
|
+
retryable: false
|
|
2063
|
+
},
|
|
2064
|
+
"graphql",
|
|
2065
|
+
{ capabilityId, reason: "CAPABILITY_LIMIT" }
|
|
2066
|
+
);
|
|
2067
|
+
}
|
|
2068
|
+
function withDefaultFirst(params) {
|
|
2069
|
+
if (params.first === void 0) {
|
|
2070
|
+
return {
|
|
2071
|
+
...params,
|
|
2072
|
+
first: DEFAULT_LIST_FIRST2
|
|
2073
|
+
};
|
|
2074
|
+
}
|
|
2075
|
+
return params;
|
|
2076
|
+
}
|
|
2077
|
+
function requireNonEmptyString(params, field, capabilityId) {
|
|
2078
|
+
const value = params[field];
|
|
2079
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
2080
|
+
throw new Error(`Missing or invalid ${field} for ${capabilityId}`);
|
|
2081
|
+
}
|
|
2082
|
+
return value;
|
|
2083
|
+
}
|
|
2084
|
+
async function runGraphqlCapability(client, capabilityId, params) {
|
|
2085
|
+
try {
|
|
2086
|
+
if (capabilityId === "repo.view") {
|
|
2087
|
+
const data = await client.fetchRepoView(params);
|
|
2088
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2089
|
+
}
|
|
2090
|
+
if (capabilityId === "issue.view") {
|
|
2091
|
+
const data = await client.fetchIssueView(params);
|
|
2092
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2093
|
+
}
|
|
2094
|
+
if (capabilityId === "issue.list") {
|
|
2095
|
+
const data = await client.fetchIssueList(withDefaultFirst(params));
|
|
2096
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2097
|
+
}
|
|
2098
|
+
if (capabilityId === "issue.comments.list") {
|
|
2099
|
+
const data = await client.fetchIssueCommentsList(params);
|
|
2100
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2101
|
+
}
|
|
2102
|
+
if (capabilityId === "issue.create") {
|
|
2103
|
+
if (!client.createIssue) {
|
|
2104
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2105
|
+
}
|
|
2106
|
+
const data = await client.createIssue(params);
|
|
2107
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2108
|
+
}
|
|
2109
|
+
if (capabilityId === "issue.update") {
|
|
2110
|
+
if (!client.updateIssue) {
|
|
2111
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2112
|
+
}
|
|
2113
|
+
const data = await client.updateIssue(params);
|
|
2114
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2115
|
+
}
|
|
2116
|
+
if (capabilityId === "issue.close") {
|
|
2117
|
+
if (!client.closeIssue) {
|
|
2118
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2119
|
+
}
|
|
2120
|
+
const data = await client.closeIssue(params);
|
|
2121
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2122
|
+
}
|
|
2123
|
+
if (capabilityId === "issue.reopen") {
|
|
2124
|
+
if (!client.reopenIssue) {
|
|
2125
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2126
|
+
}
|
|
2127
|
+
const data = await client.reopenIssue(params);
|
|
2128
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2129
|
+
}
|
|
2130
|
+
if (capabilityId === "issue.delete") {
|
|
2131
|
+
if (!client.deleteIssue) {
|
|
2132
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2133
|
+
}
|
|
2134
|
+
const data = await client.deleteIssue(params);
|
|
2135
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2136
|
+
}
|
|
2137
|
+
if (capabilityId === "issue.labels.update") {
|
|
2138
|
+
if (!client.updateIssueLabels) {
|
|
2139
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2140
|
+
}
|
|
2141
|
+
const data = await client.updateIssueLabels(params);
|
|
2142
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2143
|
+
}
|
|
2144
|
+
if (capabilityId === "issue.assignees.update") {
|
|
2145
|
+
if (!client.updateIssueAssignees) {
|
|
2146
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2147
|
+
}
|
|
2148
|
+
const data = await client.updateIssueAssignees(params);
|
|
2149
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2150
|
+
}
|
|
2151
|
+
if (capabilityId === "issue.milestone.set") {
|
|
2152
|
+
if (!client.setIssueMilestone) {
|
|
2153
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2154
|
+
}
|
|
2155
|
+
const data = await client.setIssueMilestone(params);
|
|
2156
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2157
|
+
}
|
|
2158
|
+
if (capabilityId === "issue.comments.create") {
|
|
2159
|
+
if (!client.createIssueComment) {
|
|
2160
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2161
|
+
}
|
|
2162
|
+
const data = await client.createIssueComment(params);
|
|
2163
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2164
|
+
}
|
|
2165
|
+
if (capabilityId === "issue.linked_prs.list") {
|
|
2166
|
+
if (!client.fetchIssueLinkedPrs) {
|
|
2167
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2168
|
+
}
|
|
2169
|
+
const data = await client.fetchIssueLinkedPrs(params);
|
|
2170
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2171
|
+
}
|
|
2172
|
+
if (capabilityId === "issue.relations.get") {
|
|
2173
|
+
if (!client.fetchIssueRelations) {
|
|
2174
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2175
|
+
}
|
|
2176
|
+
const data = await client.fetchIssueRelations(params);
|
|
2177
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2178
|
+
}
|
|
2179
|
+
if (capabilityId === "issue.parent.set") {
|
|
2180
|
+
if (!client.setIssueParent) {
|
|
2181
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2182
|
+
}
|
|
2183
|
+
const data = await client.setIssueParent(params);
|
|
2184
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2185
|
+
}
|
|
2186
|
+
if (capabilityId === "issue.parent.remove") {
|
|
2187
|
+
if (!client.removeIssueParent) {
|
|
2188
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2189
|
+
}
|
|
2190
|
+
const data = await client.removeIssueParent(params);
|
|
2191
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2192
|
+
}
|
|
2193
|
+
if (capabilityId === "issue.blocked_by.add") {
|
|
2194
|
+
if (!client.addIssueBlockedBy) {
|
|
2195
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2196
|
+
}
|
|
2197
|
+
const data = await client.addIssueBlockedBy(params);
|
|
2198
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2199
|
+
}
|
|
2200
|
+
if (capabilityId === "issue.blocked_by.remove") {
|
|
2201
|
+
if (!client.removeIssueBlockedBy) {
|
|
2202
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2203
|
+
}
|
|
2204
|
+
const data = await client.removeIssueBlockedBy(params);
|
|
2205
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2206
|
+
}
|
|
2207
|
+
if (capabilityId === "pr.view") {
|
|
2208
|
+
const data = await client.fetchPrView(params);
|
|
2209
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2210
|
+
}
|
|
2211
|
+
if (capabilityId === "pr.list") {
|
|
2212
|
+
const data = await client.fetchPrList(withDefaultFirst(params));
|
|
2213
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2214
|
+
}
|
|
2215
|
+
if (capabilityId === "pr.comments.list") {
|
|
2216
|
+
const data = await client.fetchPrCommentsList(withDefaultFirst(params));
|
|
2217
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2218
|
+
}
|
|
2219
|
+
if (capabilityId === "pr.reviews.list") {
|
|
2220
|
+
const data = await client.fetchPrReviewsList(withDefaultFirst(params));
|
|
2221
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2222
|
+
}
|
|
2223
|
+
if (capabilityId === "pr.diff.list_files") {
|
|
2224
|
+
const data = await client.fetchPrDiffListFiles(
|
|
2225
|
+
withDefaultFirst(params)
|
|
2226
|
+
);
|
|
2227
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2228
|
+
}
|
|
2229
|
+
if (capabilityId === "pr.comment.reply") {
|
|
2230
|
+
const threadId = requireNonEmptyString(params, "threadId", capabilityId);
|
|
2231
|
+
const body = requireNonEmptyString(params, "body", capabilityId);
|
|
2232
|
+
const data = await client.replyToReviewThread({ threadId, body });
|
|
2233
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2234
|
+
}
|
|
2235
|
+
if (capabilityId === "pr.comment.resolve") {
|
|
2236
|
+
const threadId = requireNonEmptyString(params, "threadId", capabilityId);
|
|
2237
|
+
const data = await client.resolveReviewThread({ threadId });
|
|
2238
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2239
|
+
}
|
|
2240
|
+
if (capabilityId === "pr.comment.unresolve") {
|
|
2241
|
+
const threadId = requireNonEmptyString(params, "threadId", capabilityId);
|
|
2242
|
+
const data = await client.unresolveReviewThread({ threadId });
|
|
2243
|
+
return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
|
|
2244
|
+
}
|
|
2245
|
+
return unsupportedGraphqlCapability(capabilityId);
|
|
2246
|
+
} catch (error) {
|
|
2247
|
+
const code = mapErrorToCode(error);
|
|
2248
|
+
return normalizeError(
|
|
2249
|
+
{
|
|
2250
|
+
code,
|
|
2251
|
+
message: error instanceof Error ? error.message : String(error),
|
|
2252
|
+
retryable: isRetryableErrorCode(code)
|
|
2253
|
+
},
|
|
2254
|
+
"graphql",
|
|
2255
|
+
{ capabilityId, reason: "CARD_PREFERRED" }
|
|
2256
|
+
);
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
// src/core/execution/preflight.ts
|
|
2261
|
+
function preflightCheck(input) {
|
|
2262
|
+
if (input.route === "rest") {
|
|
2263
|
+
return {
|
|
2264
|
+
ok: false,
|
|
2265
|
+
code: errorCodes.AdapterUnsupported,
|
|
2266
|
+
message: "REST route is planned but not implemented in v1",
|
|
2267
|
+
retryable: false,
|
|
2268
|
+
details: { route: input.route }
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
if (input.route === "cli" && input.ghCliAvailable === false) {
|
|
2272
|
+
return {
|
|
2273
|
+
ok: false,
|
|
2274
|
+
code: errorCodes.Validation,
|
|
2275
|
+
message: "GitHub CLI is required for cli route",
|
|
2276
|
+
retryable: false,
|
|
2277
|
+
details: { route: input.route }
|
|
2278
|
+
};
|
|
2279
|
+
}
|
|
2280
|
+
if (input.route === "cli" && input.ghAuthenticated === false) {
|
|
2281
|
+
return {
|
|
2282
|
+
ok: false,
|
|
2283
|
+
code: errorCodes.Auth,
|
|
2284
|
+
message: "GitHub CLI authentication is required for cli route",
|
|
2285
|
+
retryable: false,
|
|
2286
|
+
details: { route: input.route }
|
|
2287
|
+
};
|
|
2288
|
+
}
|
|
2289
|
+
if (input.route === "graphql") {
|
|
2290
|
+
const token = input.githubToken?.trim();
|
|
2291
|
+
if (!token) {
|
|
2292
|
+
return {
|
|
2293
|
+
ok: false,
|
|
2294
|
+
code: errorCodes.Auth,
|
|
2295
|
+
message: "GitHub token is required for graphql route",
|
|
2296
|
+
retryable: false,
|
|
2297
|
+
details: { route: input.route }
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
return { ok: true };
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
// src/core/routing/policy.ts
|
|
2305
|
+
var routePreferenceOrder = ["cli", "graphql"];
|
|
2306
|
+
|
|
2307
|
+
// src/core/routing/engine.ts
|
|
2308
|
+
function chooseRoute() {
|
|
2309
|
+
return routePreferenceOrder[0];
|
|
2310
|
+
}
|
|
2311
|
+
var DEFAULT_REASON = "DEFAULT_POLICY";
|
|
2312
|
+
var CLI_ENV_CACHE_TTL_MS = 3e4;
|
|
2313
|
+
var cliEnvironmentCache = /* @__PURE__ */ new WeakMap();
|
|
2314
|
+
var cliEnvironmentInFlight = /* @__PURE__ */ new WeakMap();
|
|
2315
|
+
var defaultCliRunner = createSafeCliCommandRunner();
|
|
2316
|
+
async function detectCliEnvironment(runner) {
|
|
2317
|
+
try {
|
|
2318
|
+
const version = await runner.run("gh", ["--version"], 1500);
|
|
2319
|
+
if (version.exitCode !== 0) {
|
|
2320
|
+
return {
|
|
2321
|
+
ghCliAvailable: false,
|
|
2322
|
+
ghAuthenticated: false
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
const auth = await runner.run("gh", ["auth", "status"], 2500);
|
|
2326
|
+
return {
|
|
2327
|
+
ghCliAvailable: true,
|
|
2328
|
+
ghAuthenticated: auth.exitCode === 0
|
|
2329
|
+
};
|
|
2330
|
+
} catch {
|
|
2331
|
+
return {
|
|
2332
|
+
ghCliAvailable: false,
|
|
2333
|
+
ghAuthenticated: false
|
|
2334
|
+
};
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2337
|
+
async function detectCliEnvironmentCached(runner) {
|
|
2338
|
+
const now = Date.now();
|
|
2339
|
+
const cached = cliEnvironmentCache.get(runner);
|
|
2340
|
+
if (cached && cached.expiresAt > now) {
|
|
2341
|
+
return cached.value;
|
|
2342
|
+
}
|
|
2343
|
+
const inFlight = cliEnvironmentInFlight.get(runner);
|
|
2344
|
+
if (inFlight) {
|
|
2345
|
+
return inFlight;
|
|
2346
|
+
}
|
|
2347
|
+
const probePromise = detectCliEnvironment(runner).then((value) => {
|
|
2348
|
+
cliEnvironmentCache.set(runner, {
|
|
2349
|
+
value,
|
|
2350
|
+
expiresAt: Date.now() + CLI_ENV_CACHE_TTL_MS
|
|
2351
|
+
});
|
|
2352
|
+
cliEnvironmentInFlight.delete(runner);
|
|
2353
|
+
return value;
|
|
2354
|
+
}).catch((error) => {
|
|
2355
|
+
cliEnvironmentInFlight.delete(runner);
|
|
2356
|
+
throw error;
|
|
2357
|
+
});
|
|
2358
|
+
cliEnvironmentInFlight.set(runner, probePromise);
|
|
2359
|
+
return probePromise;
|
|
2360
|
+
}
|
|
2361
|
+
async function executeTask(request, deps) {
|
|
2362
|
+
const reason = deps.reason ?? DEFAULT_REASON;
|
|
2363
|
+
const card = getOperationCard(request.task);
|
|
2364
|
+
if (!card) {
|
|
2365
|
+
return normalizeError(
|
|
2366
|
+
{
|
|
2367
|
+
code: errorCodes.Validation,
|
|
2368
|
+
message: `Unsupported task: ${request.task}`,
|
|
2369
|
+
retryable: false
|
|
2370
|
+
},
|
|
2371
|
+
chooseRoute(),
|
|
2372
|
+
{ capabilityId: request.task, reason }
|
|
2373
|
+
);
|
|
2374
|
+
}
|
|
2375
|
+
const cliRunner = deps.cliRunner ?? defaultCliRunner;
|
|
2376
|
+
return execute({
|
|
2377
|
+
card,
|
|
2378
|
+
params: request.input,
|
|
2379
|
+
routingContext: {
|
|
2380
|
+
ghCliAvailable: deps.ghCliAvailable,
|
|
2381
|
+
ghAuthenticated: deps.ghAuthenticated,
|
|
2382
|
+
githubTokenPresent: Boolean(deps.githubToken)
|
|
2383
|
+
},
|
|
2384
|
+
retry: {
|
|
2385
|
+
maxAttemptsPerRoute: 2
|
|
2386
|
+
},
|
|
2387
|
+
preflight: async (route) => {
|
|
2388
|
+
const preflightInput = { route };
|
|
2389
|
+
if (deps.githubToken !== void 0) {
|
|
2390
|
+
preflightInput.githubToken = deps.githubToken;
|
|
2391
|
+
}
|
|
2392
|
+
if (route === "cli") {
|
|
2393
|
+
if (deps.ghCliAvailable !== void 0) {
|
|
2394
|
+
preflightInput.ghCliAvailable = deps.ghCliAvailable;
|
|
2395
|
+
}
|
|
2396
|
+
if (deps.ghAuthenticated !== void 0) {
|
|
2397
|
+
preflightInput.ghAuthenticated = deps.ghAuthenticated;
|
|
2398
|
+
}
|
|
2399
|
+
if (preflightInput.ghCliAvailable === void 0 || preflightInput.ghAuthenticated === void 0) {
|
|
2400
|
+
if (deps.skipGhPreflight === true) {
|
|
2401
|
+
if (preflightInput.ghCliAvailable === void 0) {
|
|
2402
|
+
preflightInput.ghCliAvailable = true;
|
|
2403
|
+
}
|
|
2404
|
+
if (preflightInput.ghAuthenticated === void 0) {
|
|
2405
|
+
preflightInput.ghAuthenticated = true;
|
|
2406
|
+
}
|
|
2407
|
+
} else {
|
|
2408
|
+
const detected = await detectCliEnvironmentCached(cliRunner);
|
|
2409
|
+
if (preflightInput.ghCliAvailable === void 0) {
|
|
2410
|
+
preflightInput.ghCliAvailable = detected.ghCliAvailable;
|
|
2411
|
+
}
|
|
2412
|
+
if (preflightInput.ghAuthenticated === void 0) {
|
|
2413
|
+
preflightInput.ghAuthenticated = detected.ghAuthenticated;
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
return preflightCheck(preflightInput);
|
|
2419
|
+
},
|
|
2420
|
+
routes: {
|
|
2421
|
+
graphql: async () => runGraphqlCapability(
|
|
2422
|
+
deps.githubClient,
|
|
2423
|
+
request.task,
|
|
2424
|
+
request.input
|
|
2425
|
+
),
|
|
2426
|
+
cli: async () => {
|
|
2427
|
+
return runCliCapability(
|
|
2428
|
+
cliRunner,
|
|
2429
|
+
request.task,
|
|
2430
|
+
request.input,
|
|
2431
|
+
card
|
|
2432
|
+
);
|
|
2433
|
+
},
|
|
2434
|
+
rest: async () => normalizeError(
|
|
2435
|
+
{
|
|
2436
|
+
code: errorCodes.AdapterUnsupported,
|
|
2437
|
+
message: `Route 'rest' is not implemented for task '${request.task}'`,
|
|
2438
|
+
retryable: false,
|
|
2439
|
+
details: { route: "rest", task: request.task }
|
|
2440
|
+
},
|
|
2441
|
+
"rest",
|
|
2442
|
+
{ capabilityId: request.task, reason }
|
|
2443
|
+
)
|
|
2444
|
+
}
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
// src/gql/client.ts
|
|
2449
|
+
import { print } from "graphql";
|
|
2450
|
+
|
|
2451
|
+
// src/gql/operations/issue-comments-list.generated.ts
|
|
2452
|
+
var IssueCommentsListDocument = `
|
|
2453
|
+
query IssueCommentsList($owner: String!, $name: String!, $issueNumber: Int!, $first: Int!, $after: String) {
|
|
2454
|
+
repository(owner: $owner, name: $name) {
|
|
2455
|
+
issue(number: $issueNumber) {
|
|
2456
|
+
comments(first: $first, after: $after) {
|
|
2457
|
+
nodes {
|
|
2458
|
+
id
|
|
2459
|
+
body
|
|
2460
|
+
createdAt
|
|
2461
|
+
url
|
|
2462
|
+
author {
|
|
2463
|
+
login
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
pageInfo {
|
|
2467
|
+
endCursor
|
|
2468
|
+
hasNextPage
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
`;
|
|
2475
|
+
var defaultWrapper = (action, _operationName, _operationType, _variables) => action();
|
|
2476
|
+
function getSdk(client, withWrapper = defaultWrapper) {
|
|
2477
|
+
return {
|
|
2478
|
+
IssueCommentsList(variables, requestHeaders, signal) {
|
|
2479
|
+
return withWrapper(
|
|
2480
|
+
(wrappedRequestHeaders) => client.request({
|
|
2481
|
+
document: IssueCommentsListDocument,
|
|
2482
|
+
variables,
|
|
2483
|
+
requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
|
|
2484
|
+
signal
|
|
2485
|
+
}),
|
|
2486
|
+
"IssueCommentsList",
|
|
2487
|
+
"query",
|
|
2488
|
+
variables
|
|
2489
|
+
);
|
|
2490
|
+
}
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
// src/gql/operations/issue-list.generated.ts
|
|
2495
|
+
var IssueListDocument = `
|
|
2496
|
+
query IssueList($owner: String!, $name: String!, $first: Int!, $after: String) {
|
|
2497
|
+
repository(owner: $owner, name: $name) {
|
|
2498
|
+
issues(
|
|
2499
|
+
first: $first
|
|
2500
|
+
after: $after
|
|
2501
|
+
orderBy: {field: CREATED_AT, direction: DESC}
|
|
2502
|
+
) {
|
|
2503
|
+
nodes {
|
|
2504
|
+
id
|
|
2505
|
+
number
|
|
2506
|
+
title
|
|
2507
|
+
state
|
|
2508
|
+
url
|
|
2509
|
+
}
|
|
2510
|
+
pageInfo {
|
|
2511
|
+
endCursor
|
|
2512
|
+
hasNextPage
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
`;
|
|
2518
|
+
var defaultWrapper2 = (action, _operationName, _operationType, _variables) => action();
|
|
2519
|
+
function getSdk2(client, withWrapper = defaultWrapper2) {
|
|
2520
|
+
return {
|
|
2521
|
+
IssueList(variables, requestHeaders, signal) {
|
|
2522
|
+
return withWrapper(
|
|
2523
|
+
(wrappedRequestHeaders) => client.request({
|
|
2524
|
+
document: IssueListDocument,
|
|
2525
|
+
variables,
|
|
2526
|
+
requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
|
|
2527
|
+
signal
|
|
2528
|
+
}),
|
|
2529
|
+
"IssueList",
|
|
2530
|
+
"query",
|
|
2531
|
+
variables
|
|
2532
|
+
);
|
|
2533
|
+
}
|
|
2534
|
+
};
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
// src/gql/operations/issue-view.generated.ts
|
|
2538
|
+
var IssueViewDocument = `
|
|
2539
|
+
query IssueView($owner: String!, $name: String!, $issueNumber: Int!) {
|
|
2540
|
+
repository(owner: $owner, name: $name) {
|
|
2541
|
+
issue(number: $issueNumber) {
|
|
2542
|
+
id
|
|
2543
|
+
number
|
|
2544
|
+
title
|
|
2545
|
+
state
|
|
2546
|
+
url
|
|
2547
|
+
}
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
`;
|
|
2551
|
+
var defaultWrapper3 = (action, _operationName, _operationType, _variables) => action();
|
|
2552
|
+
function getSdk3(client, withWrapper = defaultWrapper3) {
|
|
2553
|
+
return {
|
|
2554
|
+
IssueView(variables, requestHeaders, signal) {
|
|
2555
|
+
return withWrapper(
|
|
2556
|
+
(wrappedRequestHeaders) => client.request({
|
|
2557
|
+
document: IssueViewDocument,
|
|
2558
|
+
variables,
|
|
2559
|
+
requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
|
|
2560
|
+
signal
|
|
2561
|
+
}),
|
|
2562
|
+
"IssueView",
|
|
2563
|
+
"query",
|
|
2564
|
+
variables
|
|
2565
|
+
);
|
|
2566
|
+
}
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
// src/gql/operations/pr-diff-list-files.generated.ts
|
|
2571
|
+
var PrDiffListFilesDocument = `
|
|
2572
|
+
query PrDiffListFiles($owner: String!, $name: String!, $prNumber: Int!, $first: Int!, $after: String) {
|
|
2573
|
+
repository(owner: $owner, name: $name) {
|
|
2574
|
+
pullRequest(number: $prNumber) {
|
|
2575
|
+
files(first: $first, after: $after) {
|
|
2576
|
+
nodes {
|
|
2577
|
+
path
|
|
2578
|
+
additions
|
|
2579
|
+
deletions
|
|
2580
|
+
}
|
|
2581
|
+
pageInfo {
|
|
2582
|
+
hasNextPage
|
|
2583
|
+
endCursor
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
`;
|
|
2590
|
+
var defaultWrapper4 = (action, _operationName, _operationType, _variables) => action();
|
|
2591
|
+
function getSdk4(client, withWrapper = defaultWrapper4) {
|
|
2592
|
+
return {
|
|
2593
|
+
PrDiffListFiles(variables, requestHeaders, signal) {
|
|
2594
|
+
return withWrapper(
|
|
2595
|
+
(wrappedRequestHeaders) => client.request({
|
|
2596
|
+
document: PrDiffListFilesDocument,
|
|
2597
|
+
variables,
|
|
2598
|
+
requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
|
|
2599
|
+
signal
|
|
2600
|
+
}),
|
|
2601
|
+
"PrDiffListFiles",
|
|
2602
|
+
"query",
|
|
2603
|
+
variables
|
|
2604
|
+
);
|
|
2605
|
+
}
|
|
2606
|
+
};
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
// src/gql/operations/pr-list.generated.ts
|
|
2610
|
+
var PrListDocument = `
|
|
2611
|
+
query PrList($owner: String!, $name: String!, $first: Int!, $after: String) {
|
|
2612
|
+
repository(owner: $owner, name: $name) {
|
|
2613
|
+
pullRequests(
|
|
2614
|
+
first: $first
|
|
2615
|
+
after: $after
|
|
2616
|
+
orderBy: {field: CREATED_AT, direction: DESC}
|
|
2617
|
+
) {
|
|
2618
|
+
nodes {
|
|
2619
|
+
id
|
|
2620
|
+
number
|
|
2621
|
+
title
|
|
2622
|
+
state
|
|
2623
|
+
url
|
|
2624
|
+
}
|
|
2625
|
+
pageInfo {
|
|
2626
|
+
endCursor
|
|
2627
|
+
hasNextPage
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
}
|
|
2632
|
+
`;
|
|
2633
|
+
var defaultWrapper5 = (action, _operationName, _operationType, _variables) => action();
|
|
2634
|
+
function getSdk5(client, withWrapper = defaultWrapper5) {
|
|
2635
|
+
return {
|
|
2636
|
+
PrList(variables, requestHeaders, signal) {
|
|
2637
|
+
return withWrapper(
|
|
2638
|
+
(wrappedRequestHeaders) => client.request({
|
|
2639
|
+
document: PrListDocument,
|
|
2640
|
+
variables,
|
|
2641
|
+
requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
|
|
2642
|
+
signal
|
|
2643
|
+
}),
|
|
2644
|
+
"PrList",
|
|
2645
|
+
"query",
|
|
2646
|
+
variables
|
|
2647
|
+
);
|
|
2648
|
+
}
|
|
2649
|
+
};
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
// src/gql/operations/pr-reviews-list.generated.ts
|
|
2653
|
+
var PrReviewsListDocument = `
|
|
2654
|
+
query PrReviewsList($owner: String!, $name: String!, $prNumber: Int!, $first: Int!, $after: String) {
|
|
2655
|
+
repository(owner: $owner, name: $name) {
|
|
2656
|
+
pullRequest(number: $prNumber) {
|
|
2657
|
+
reviews(first: $first, after: $after) {
|
|
2658
|
+
nodes {
|
|
2659
|
+
id
|
|
2660
|
+
author {
|
|
2661
|
+
login
|
|
2662
|
+
}
|
|
2663
|
+
body
|
|
2664
|
+
state
|
|
2665
|
+
submittedAt
|
|
2666
|
+
url
|
|
2667
|
+
commit {
|
|
2668
|
+
oid
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
pageInfo {
|
|
2672
|
+
hasNextPage
|
|
2673
|
+
endCursor
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
`;
|
|
2680
|
+
var defaultWrapper6 = (action, _operationName, _operationType, _variables) => action();
|
|
2681
|
+
function getSdk6(client, withWrapper = defaultWrapper6) {
|
|
2682
|
+
return {
|
|
2683
|
+
PrReviewsList(variables, requestHeaders, signal) {
|
|
2684
|
+
return withWrapper(
|
|
2685
|
+
(wrappedRequestHeaders) => client.request({
|
|
2686
|
+
document: PrReviewsListDocument,
|
|
2687
|
+
variables,
|
|
2688
|
+
requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
|
|
2689
|
+
signal
|
|
2690
|
+
}),
|
|
2691
|
+
"PrReviewsList",
|
|
2692
|
+
"query",
|
|
2693
|
+
variables
|
|
2694
|
+
);
|
|
2695
|
+
}
|
|
2696
|
+
};
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
// src/gql/operations/pr-view.generated.ts
|
|
2700
|
+
var PrViewDocument = `
|
|
2701
|
+
query PrView($owner: String!, $name: String!, $prNumber: Int!) {
|
|
2702
|
+
repository(owner: $owner, name: $name) {
|
|
2703
|
+
pullRequest(number: $prNumber) {
|
|
2704
|
+
id
|
|
2705
|
+
number
|
|
2706
|
+
title
|
|
2707
|
+
state
|
|
2708
|
+
url
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
`;
|
|
2713
|
+
var defaultWrapper7 = (action, _operationName, _operationType, _variables) => action();
|
|
2714
|
+
function getSdk7(client, withWrapper = defaultWrapper7) {
|
|
2715
|
+
return {
|
|
2716
|
+
PrView(variables, requestHeaders, signal) {
|
|
2717
|
+
return withWrapper(
|
|
2718
|
+
(wrappedRequestHeaders) => client.request({
|
|
2719
|
+
document: PrViewDocument,
|
|
2720
|
+
variables,
|
|
2721
|
+
requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
|
|
2722
|
+
signal
|
|
2723
|
+
}),
|
|
2724
|
+
"PrView",
|
|
2725
|
+
"query",
|
|
2726
|
+
variables
|
|
2727
|
+
);
|
|
2728
|
+
}
|
|
2729
|
+
};
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
// src/gql/operations/repo-view.generated.ts
|
|
2733
|
+
var RepoViewDocument = `
|
|
2734
|
+
query RepoView($owner: String!, $name: String!) {
|
|
2735
|
+
repository(owner: $owner, name: $name) {
|
|
2736
|
+
id
|
|
2737
|
+
name
|
|
2738
|
+
nameWithOwner
|
|
2739
|
+
isPrivate
|
|
2740
|
+
stargazerCount
|
|
2741
|
+
forkCount
|
|
2742
|
+
url
|
|
2743
|
+
defaultBranchRef {
|
|
2744
|
+
name
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
}
|
|
2748
|
+
`;
|
|
2749
|
+
var defaultWrapper8 = (action, _operationName, _operationType, _variables) => action();
|
|
2750
|
+
function getSdk8(client, withWrapper = defaultWrapper8) {
|
|
2751
|
+
return {
|
|
2752
|
+
RepoView(variables, requestHeaders, signal) {
|
|
2753
|
+
return withWrapper(
|
|
2754
|
+
(wrappedRequestHeaders) => client.request({
|
|
2755
|
+
document: RepoViewDocument,
|
|
2756
|
+
variables,
|
|
2757
|
+
requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
|
|
2758
|
+
signal
|
|
2759
|
+
}),
|
|
2760
|
+
"RepoView",
|
|
2761
|
+
"query",
|
|
2762
|
+
variables
|
|
2763
|
+
);
|
|
2764
|
+
}
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
// src/gql/client.ts
|
|
2769
|
+
function assertRepoInput(input) {
|
|
2770
|
+
if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
|
|
2771
|
+
throw new Error("Repository owner and name are required");
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
function assertIssueInput(input) {
|
|
2775
|
+
if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
|
|
2776
|
+
throw new Error("Repository owner and name are required");
|
|
2777
|
+
}
|
|
2778
|
+
if (!Number.isInteger(input.issueNumber) || input.issueNumber <= 0) {
|
|
2779
|
+
throw new Error("Issue number must be a positive integer");
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
function assertIssueListInput(input) {
|
|
2783
|
+
if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
|
|
2784
|
+
throw new Error("Repository owner and name are required");
|
|
2785
|
+
}
|
|
2786
|
+
if (!Number.isInteger(input.first) || input.first <= 0) {
|
|
2787
|
+
throw new Error("List page size must be a positive integer");
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
function assertIssueCommentsListInput(input) {
|
|
2791
|
+
if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
|
|
2792
|
+
throw new Error("Repository owner and name are required");
|
|
2793
|
+
}
|
|
2794
|
+
if (!Number.isInteger(input.issueNumber) || input.issueNumber <= 0) {
|
|
2795
|
+
throw new Error("Issue number must be a positive integer");
|
|
2796
|
+
}
|
|
2797
|
+
if (!Number.isInteger(input.first) || input.first <= 0) {
|
|
2798
|
+
throw new Error("List page size must be a positive integer");
|
|
2799
|
+
}
|
|
2800
|
+
if (input.after !== void 0 && input.after !== null && typeof input.after !== "string") {
|
|
2801
|
+
throw new Error("After cursor must be a string");
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
function assertNonEmptyString(value, fieldName) {
|
|
2805
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
2806
|
+
throw new Error(`${fieldName} is required`);
|
|
2807
|
+
}
|
|
2808
|
+
return value;
|
|
2809
|
+
}
|
|
2810
|
+
function assertOptionalString(value, fieldName) {
|
|
2811
|
+
if (value === void 0) {
|
|
2812
|
+
return void 0;
|
|
2813
|
+
}
|
|
2814
|
+
if (typeof value !== "string") {
|
|
2815
|
+
throw new Error(`${fieldName} must be a string`);
|
|
2816
|
+
}
|
|
2817
|
+
return value;
|
|
2818
|
+
}
|
|
2819
|
+
function assertStringArray(value, fieldName) {
|
|
2820
|
+
if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.trim().length === 0)) {
|
|
2821
|
+
throw new Error(`${fieldName} must be an array of non-empty strings`);
|
|
2822
|
+
}
|
|
2823
|
+
return value;
|
|
2824
|
+
}
|
|
2825
|
+
function assertIssueCreateInput(input) {
|
|
2826
|
+
assertRepoInput({ owner: input.owner, name: input.name });
|
|
2827
|
+
assertNonEmptyString(input.title, "Issue title");
|
|
2828
|
+
assertOptionalString(input.body, "Issue body");
|
|
2829
|
+
}
|
|
2830
|
+
function assertIssueUpdateInput(input) {
|
|
2831
|
+
assertNonEmptyString(input.issueId, "Issue id");
|
|
2832
|
+
if (input.title === void 0 && input.body === void 0) {
|
|
2833
|
+
throw new Error("Issue update requires at least one field");
|
|
2834
|
+
}
|
|
2835
|
+
if (input.title !== void 0) {
|
|
2836
|
+
assertOptionalString(input.title, "Issue title");
|
|
2837
|
+
}
|
|
2838
|
+
if (input.body !== void 0) {
|
|
2839
|
+
assertOptionalString(input.body, "Issue body");
|
|
2840
|
+
}
|
|
2841
|
+
}
|
|
2842
|
+
function assertIssueMutationInput(input) {
|
|
2843
|
+
assertNonEmptyString(input.issueId, "Issue id");
|
|
2844
|
+
}
|
|
2845
|
+
function assertIssueLabelsUpdateInput(input) {
|
|
2846
|
+
assertIssueMutationInput({ issueId: input.issueId });
|
|
2847
|
+
assertStringArray(input.labels, "Labels");
|
|
2848
|
+
}
|
|
2849
|
+
function assertIssueAssigneesUpdateInput(input) {
|
|
2850
|
+
assertIssueMutationInput({ issueId: input.issueId });
|
|
2851
|
+
assertStringArray(input.assignees, "Assignees");
|
|
2852
|
+
}
|
|
2853
|
+
function assertIssueMilestoneSetInput(input) {
|
|
2854
|
+
assertIssueMutationInput({ issueId: input.issueId });
|
|
2855
|
+
if (input.milestoneNumber !== null && (!Number.isInteger(input.milestoneNumber) || input.milestoneNumber <= 0)) {
|
|
2856
|
+
throw new Error("Milestone number must be a positive integer or null");
|
|
2857
|
+
}
|
|
2858
|
+
}
|
|
2859
|
+
function assertIssueCommentCreateInput(input) {
|
|
2860
|
+
assertIssueMutationInput({ issueId: input.issueId });
|
|
2861
|
+
assertNonEmptyString(input.body, "Issue comment body");
|
|
2862
|
+
}
|
|
2863
|
+
function assertIssueLinkedPrsListInput(input) {
|
|
2864
|
+
assertIssueInput(input);
|
|
2865
|
+
}
|
|
2866
|
+
function assertIssueRelationsGetInput(input) {
|
|
2867
|
+
assertIssueInput(input);
|
|
2868
|
+
}
|
|
2869
|
+
function assertIssueParentSetInput(input) {
|
|
2870
|
+
assertIssueMutationInput({ issueId: input.issueId });
|
|
2871
|
+
assertNonEmptyString(input.parentIssueId, "Parent issue id");
|
|
2872
|
+
}
|
|
2873
|
+
function assertIssueParentRemoveInput(input) {
|
|
2874
|
+
assertIssueMutationInput({ issueId: input.issueId });
|
|
2875
|
+
}
|
|
2876
|
+
function assertIssueBlockedByInput(input) {
|
|
2877
|
+
assertIssueMutationInput({ issueId: input.issueId });
|
|
2878
|
+
assertNonEmptyString(input.blockedByIssueId, "Blocked-by issue id");
|
|
2879
|
+
}
|
|
2880
|
+
function assertPrInput(input) {
|
|
2881
|
+
if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
|
|
2882
|
+
throw new Error("Repository owner and name are required");
|
|
2883
|
+
}
|
|
2884
|
+
if (!Number.isInteger(input.prNumber) || input.prNumber <= 0) {
|
|
2885
|
+
throw new Error("PR number must be a positive integer");
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
function assertPrListInput(input) {
|
|
2889
|
+
if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
|
|
2890
|
+
throw new Error("Repository owner and name are required");
|
|
2891
|
+
}
|
|
2892
|
+
if (!Number.isInteger(input.first) || input.first <= 0) {
|
|
2893
|
+
throw new Error("List page size must be a positive integer");
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
function assertPrReviewsListInput(input) {
|
|
2897
|
+
if (typeof input.owner !== "string" || typeof input.name !== "string" || input.owner.trim().length === 0 || input.name.trim().length === 0) {
|
|
2898
|
+
throw new Error("Repository owner and name are required");
|
|
2899
|
+
}
|
|
2900
|
+
if (!Number.isInteger(input.prNumber) || input.prNumber <= 0) {
|
|
2901
|
+
throw new Error("PR number must be a positive integer");
|
|
2902
|
+
}
|
|
2903
|
+
if (!Number.isInteger(input.first) || input.first <= 0) {
|
|
2904
|
+
throw new Error("List page size must be a positive integer");
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
function assertPrDiffListFilesInput(input) {
|
|
2908
|
+
if (typeof input.owner !== "string" || typeof input.name !== "string" || input.owner.trim().length === 0 || input.name.trim().length === 0) {
|
|
2909
|
+
throw new Error("Repository owner and name are required");
|
|
2910
|
+
}
|
|
2911
|
+
if (!Number.isInteger(input.prNumber) || input.prNumber <= 0) {
|
|
2912
|
+
throw new Error("PR number must be a positive integer");
|
|
2913
|
+
}
|
|
2914
|
+
if (!Number.isInteger(input.first) || input.first <= 0) {
|
|
2915
|
+
throw new Error("List page size must be a positive integer");
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
function assertPrCommentsListInput(input) {
|
|
2919
|
+
if (typeof input.owner !== "string" || typeof input.name !== "string" || input.owner.trim().length === 0 || input.name.trim().length === 0) {
|
|
2920
|
+
throw new Error("Repository owner and name are required");
|
|
2921
|
+
}
|
|
2922
|
+
if (!Number.isInteger(input.prNumber) || input.prNumber <= 0) {
|
|
2923
|
+
throw new Error("PR number must be a positive integer");
|
|
2924
|
+
}
|
|
2925
|
+
if (!Number.isInteger(input.first) || input.first <= 0) {
|
|
2926
|
+
throw new Error("List page size must be a positive integer");
|
|
2927
|
+
}
|
|
2928
|
+
if (input.unresolvedOnly !== void 0 && typeof input.unresolvedOnly !== "boolean") {
|
|
2929
|
+
throw new Error("unresolvedOnly must be a boolean");
|
|
2930
|
+
}
|
|
2931
|
+
if (input.includeOutdated !== void 0 && typeof input.includeOutdated !== "boolean") {
|
|
2932
|
+
throw new Error("includeOutdated must be a boolean");
|
|
2933
|
+
}
|
|
2934
|
+
if (input.after !== void 0 && input.after !== null && typeof input.after !== "string") {
|
|
2935
|
+
throw new Error("After cursor must be a string");
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
var PR_COMMENTS_LIST_QUERY = `
|
|
2939
|
+
query PrCommentsList($owner: String!, $name: String!, $prNumber: Int!, $first: Int!, $after: String) {
|
|
2940
|
+
repository(owner: $owner, name: $name) {
|
|
2941
|
+
pullRequest(number: $prNumber) {
|
|
2942
|
+
reviewThreads(first: $first, after: $after) {
|
|
2943
|
+
edges {
|
|
2944
|
+
cursor
|
|
2945
|
+
node {
|
|
2946
|
+
id
|
|
2947
|
+
path
|
|
2948
|
+
line
|
|
2949
|
+
startLine
|
|
2950
|
+
diffSide
|
|
2951
|
+
subjectType
|
|
2952
|
+
isResolved
|
|
2953
|
+
isOutdated
|
|
2954
|
+
viewerCanReply
|
|
2955
|
+
viewerCanResolve
|
|
2956
|
+
viewerCanUnresolve
|
|
2957
|
+
resolvedBy {
|
|
2958
|
+
login
|
|
2959
|
+
}
|
|
2960
|
+
comments(first: 20) {
|
|
2961
|
+
nodes {
|
|
2962
|
+
id
|
|
2963
|
+
body
|
|
2964
|
+
createdAt
|
|
2965
|
+
url
|
|
2966
|
+
author {
|
|
2967
|
+
login
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
pageInfo {
|
|
2974
|
+
endCursor
|
|
2975
|
+
hasNextPage
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
}
|
|
2981
|
+
`;
|
|
2982
|
+
var PR_COMMENT_REPLY_MUTATION = `
|
|
2983
|
+
mutation PrCommentReply($threadId: ID!, $body: String!) {
|
|
2984
|
+
addPullRequestReviewThreadReply(input: { pullRequestReviewThreadId: $threadId, body: $body }) {
|
|
2985
|
+
comment {
|
|
2986
|
+
id
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
`;
|
|
2991
|
+
var PR_COMMENT_RESOLVE_MUTATION = `
|
|
2992
|
+
mutation PrCommentResolve($threadId: ID!) {
|
|
2993
|
+
resolveReviewThread(input: { threadId: $threadId }) {
|
|
2994
|
+
thread {
|
|
2995
|
+
id
|
|
2996
|
+
isResolved
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
`;
|
|
3001
|
+
var PR_COMMENT_UNRESOLVE_MUTATION = `
|
|
3002
|
+
mutation PrCommentUnresolve($threadId: ID!) {
|
|
3003
|
+
unresolveReviewThread(input: { threadId: $threadId }) {
|
|
3004
|
+
thread {
|
|
3005
|
+
id
|
|
3006
|
+
isResolved
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
`;
|
|
3011
|
+
var REVIEW_THREAD_STATE_QUERY = `
|
|
3012
|
+
query ReviewThreadState($threadId: ID!) {
|
|
3013
|
+
node(id: $threadId) {
|
|
3014
|
+
... on PullRequestReviewThread {
|
|
3015
|
+
id
|
|
3016
|
+
isResolved
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
`;
|
|
3021
|
+
var ISSUE_CREATE_REPOSITORY_ID_QUERY = `
|
|
3022
|
+
query IssueCreateRepositoryId($owner: String!, $name: String!) {
|
|
3023
|
+
repository(owner: $owner, name: $name) {
|
|
3024
|
+
id
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
`;
|
|
3028
|
+
var ISSUE_CREATE_MUTATION = `
|
|
3029
|
+
mutation IssueCreate($repositoryId: ID!, $title: String!, $body: String) {
|
|
3030
|
+
createIssue(input: { repositoryId: $repositoryId, title: $title, body: $body }) {
|
|
3031
|
+
issue {
|
|
3032
|
+
id
|
|
3033
|
+
number
|
|
3034
|
+
title
|
|
3035
|
+
state
|
|
3036
|
+
url
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
`;
|
|
3041
|
+
var ISSUE_UPDATE_MUTATION = `
|
|
3042
|
+
mutation IssueUpdate($issueId: ID!, $title: String, $body: String) {
|
|
3043
|
+
updateIssue(input: { id: $issueId, title: $title, body: $body }) {
|
|
3044
|
+
issue {
|
|
3045
|
+
id
|
|
3046
|
+
number
|
|
3047
|
+
title
|
|
3048
|
+
state
|
|
3049
|
+
url
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
`;
|
|
3054
|
+
var ISSUE_CLOSE_MUTATION = `
|
|
3055
|
+
mutation IssueClose($issueId: ID!) {
|
|
3056
|
+
closeIssue(input: { issueId: $issueId }) {
|
|
3057
|
+
issue {
|
|
3058
|
+
id
|
|
3059
|
+
number
|
|
3060
|
+
state
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
`;
|
|
3065
|
+
var ISSUE_REOPEN_MUTATION = `
|
|
3066
|
+
mutation IssueReopen($issueId: ID!) {
|
|
3067
|
+
reopenIssue(input: { issueId: $issueId }) {
|
|
3068
|
+
issue {
|
|
3069
|
+
id
|
|
3070
|
+
number
|
|
3071
|
+
state
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
`;
|
|
3076
|
+
var ISSUE_DELETE_MUTATION = `
|
|
3077
|
+
mutation IssueDelete($issueId: ID!) {
|
|
3078
|
+
deleteIssue(input: { issueId: $issueId }) {
|
|
3079
|
+
clientMutationId
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
`;
|
|
3083
|
+
var ISSUE_LABELS_UPDATE_MUTATION = `
|
|
3084
|
+
mutation IssueLabelsUpdate($issueId: ID!, $labelIds: [ID!]!) {
|
|
3085
|
+
updateIssue(input: { id: $issueId, labelIds: $labelIds }) {
|
|
3086
|
+
issue {
|
|
3087
|
+
id
|
|
3088
|
+
labels(first: 50) {
|
|
3089
|
+
nodes {
|
|
3090
|
+
name
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
`;
|
|
3097
|
+
var ISSUE_ASSIGNEES_UPDATE_MUTATION = `
|
|
3098
|
+
mutation IssueAssigneesUpdate($issueId: ID!, $assigneeIds: [ID!]!) {
|
|
3099
|
+
updateIssue(input: { id: $issueId, assigneeIds: $assigneeIds }) {
|
|
3100
|
+
issue {
|
|
3101
|
+
id
|
|
3102
|
+
assignees(first: 50) {
|
|
3103
|
+
nodes {
|
|
3104
|
+
login
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
}
|
|
3110
|
+
`;
|
|
3111
|
+
var ISSUE_MILESTONE_SET_MUTATION = `
|
|
3112
|
+
mutation IssueMilestoneSet($issueId: ID!, $milestoneId: ID) {
|
|
3113
|
+
updateIssue(input: { id: $issueId, milestoneId: $milestoneId }) {
|
|
3114
|
+
issue {
|
|
3115
|
+
id
|
|
3116
|
+
milestone {
|
|
3117
|
+
number
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
`;
|
|
3123
|
+
var ISSUE_LABELS_LOOKUP_QUERY = `
|
|
3124
|
+
query IssueLabelsLookup($issueId: ID!) {
|
|
3125
|
+
node(id: $issueId) {
|
|
3126
|
+
... on Issue {
|
|
3127
|
+
repository {
|
|
3128
|
+
labels(first: 100) {
|
|
3129
|
+
nodes {
|
|
3130
|
+
id
|
|
3131
|
+
name
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
`;
|
|
3139
|
+
var ISSUE_ASSIGNEES_LOOKUP_QUERY = `
|
|
3140
|
+
query IssueAssigneesLookup($issueId: ID!) {
|
|
3141
|
+
node(id: $issueId) {
|
|
3142
|
+
... on Issue {
|
|
3143
|
+
repository {
|
|
3144
|
+
assignableUsers(first: 100) {
|
|
3145
|
+
nodes {
|
|
3146
|
+
id
|
|
3147
|
+
login
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
`;
|
|
3155
|
+
var ISSUE_MILESTONE_LOOKUP_QUERY = `
|
|
3156
|
+
query IssueMilestoneLookup($issueId: ID!, $milestoneNumber: Int!) {
|
|
3157
|
+
node(id: $issueId) {
|
|
3158
|
+
... on Issue {
|
|
3159
|
+
repository {
|
|
3160
|
+
milestone(number: $milestoneNumber) {
|
|
3161
|
+
id
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
`;
|
|
3168
|
+
var ISSUE_COMMENT_CREATE_MUTATION = `
|
|
3169
|
+
mutation IssueCommentCreate($issueId: ID!, $body: String!) {
|
|
3170
|
+
addComment(input: { subjectId: $issueId, body: $body }) {
|
|
3171
|
+
commentEdge {
|
|
3172
|
+
node {
|
|
3173
|
+
id
|
|
3174
|
+
body
|
|
3175
|
+
url
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
`;
|
|
3181
|
+
var ISSUE_LINKED_PRS_LIST_QUERY = `
|
|
3182
|
+
query IssueLinkedPrsList($owner: String!, $name: String!, $issueNumber: Int!) {
|
|
3183
|
+
repository(owner: $owner, name: $name) {
|
|
3184
|
+
issue(number: $issueNumber) {
|
|
3185
|
+
timelineItems(first: 50, itemTypes: [CONNECTED_EVENT]) {
|
|
3186
|
+
nodes {
|
|
3187
|
+
__typename
|
|
3188
|
+
... on ConnectedEvent {
|
|
3189
|
+
subject {
|
|
3190
|
+
__typename
|
|
3191
|
+
... on PullRequest {
|
|
3192
|
+
id
|
|
3193
|
+
number
|
|
3194
|
+
title
|
|
3195
|
+
state
|
|
3196
|
+
url
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
}
|
|
3204
|
+
}
|
|
3205
|
+
`;
|
|
3206
|
+
var ISSUE_RELATIONS_GET_QUERY = `
|
|
3207
|
+
query IssueRelationsGet($owner: String!, $name: String!, $issueNumber: Int!) {
|
|
3208
|
+
repository(owner: $owner, name: $name) {
|
|
3209
|
+
issue(number: $issueNumber) {
|
|
3210
|
+
id
|
|
3211
|
+
number
|
|
3212
|
+
parent {
|
|
3213
|
+
id
|
|
3214
|
+
number
|
|
3215
|
+
}
|
|
3216
|
+
subIssues(first: 50) {
|
|
3217
|
+
nodes {
|
|
3218
|
+
id
|
|
3219
|
+
number
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
blockedBy(first: 50) {
|
|
3223
|
+
nodes {
|
|
3224
|
+
id
|
|
3225
|
+
number
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
`;
|
|
3232
|
+
var ISSUE_PARENT_LOOKUP_QUERY = `
|
|
3233
|
+
query IssueParentLookup($issueId: ID!) {
|
|
3234
|
+
node(id: $issueId) {
|
|
3235
|
+
... on Issue {
|
|
3236
|
+
id
|
|
3237
|
+
parent {
|
|
3238
|
+
id
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
`;
|
|
3244
|
+
var ISSUE_PARENT_SET_MUTATION = `
|
|
3245
|
+
mutation IssueParentSet($issueId: ID!, $parentIssueId: ID!) {
|
|
3246
|
+
addSubIssue(input: { issueId: $parentIssueId, subIssueId: $issueId }) {
|
|
3247
|
+
issue { id }
|
|
3248
|
+
subIssue { id }
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
`;
|
|
3252
|
+
var ISSUE_PARENT_REMOVE_MUTATION = `
|
|
3253
|
+
mutation IssueParentRemove($issueId: ID!, $parentIssueId: ID!) {
|
|
3254
|
+
removeSubIssue(input: { issueId: $parentIssueId, subIssueId: $issueId }) {
|
|
3255
|
+
issue { id }
|
|
3256
|
+
subIssue { id }
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
`;
|
|
3260
|
+
var ISSUE_BLOCKED_BY_ADD_MUTATION = `
|
|
3261
|
+
mutation IssueBlockedByAdd($issueId: ID!, $blockedByIssueId: ID!) {
|
|
3262
|
+
addBlockedBy(input: { issueId: $issueId, blockingIssueId: $blockedByIssueId }) {
|
|
3263
|
+
issue { id }
|
|
3264
|
+
blockingIssue { id }
|
|
3265
|
+
}
|
|
3266
|
+
}
|
|
3267
|
+
`;
|
|
3268
|
+
var ISSUE_BLOCKED_BY_REMOVE_MUTATION = `
|
|
3269
|
+
mutation IssueBlockedByRemove($issueId: ID!, $blockedByIssueId: ID!) {
|
|
3270
|
+
removeBlockedBy(input: { issueId: $issueId, blockingIssueId: $blockedByIssueId }) {
|
|
3271
|
+
issue { id }
|
|
3272
|
+
blockingIssue { id }
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
`;
|
|
3276
|
+
function createSdkClients(transport) {
|
|
3277
|
+
const client = {
|
|
3278
|
+
request(documentOrOptions, ...variablesAndRequestHeaders) {
|
|
3279
|
+
const options = typeof documentOrOptions === "object" && documentOrOptions !== null && "document" in documentOrOptions ? documentOrOptions : {
|
|
3280
|
+
document: documentOrOptions,
|
|
3281
|
+
variables: variablesAndRequestHeaders[0]
|
|
3282
|
+
};
|
|
3283
|
+
const queryText = queryToString(options.document);
|
|
3284
|
+
assertQuery(queryText);
|
|
3285
|
+
return transport.execute(queryText, options.variables);
|
|
3286
|
+
}
|
|
3287
|
+
};
|
|
3288
|
+
const graphqlRequestClient = client;
|
|
3289
|
+
return {
|
|
3290
|
+
issueCommentsList: getSdk(graphqlRequestClient),
|
|
3291
|
+
issueList: getSdk2(graphqlRequestClient),
|
|
3292
|
+
issue: getSdk3(graphqlRequestClient),
|
|
3293
|
+
prDiffListFiles: getSdk4(graphqlRequestClient),
|
|
3294
|
+
prList: getSdk5(graphqlRequestClient),
|
|
3295
|
+
prReviewsList: getSdk6(graphqlRequestClient),
|
|
3296
|
+
pr: getSdk7(graphqlRequestClient),
|
|
3297
|
+
repo: getSdk8(graphqlRequestClient)
|
|
3298
|
+
};
|
|
3299
|
+
}
|
|
3300
|
+
async function runRepoView(sdk, input) {
|
|
3301
|
+
assertRepoInput(input);
|
|
3302
|
+
const result = await sdk.RepoView(input);
|
|
3303
|
+
if (!result.repository) {
|
|
3304
|
+
throw new Error("Repository not found");
|
|
3305
|
+
}
|
|
3306
|
+
return {
|
|
3307
|
+
id: result.repository.id,
|
|
3308
|
+
name: result.repository.name,
|
|
3309
|
+
nameWithOwner: result.repository.nameWithOwner,
|
|
3310
|
+
isPrivate: result.repository.isPrivate,
|
|
3311
|
+
stargazerCount: result.repository.stargazerCount,
|
|
3312
|
+
forkCount: result.repository.forkCount,
|
|
3313
|
+
url: result.repository.url,
|
|
3314
|
+
defaultBranch: result.repository.defaultBranchRef?.name ?? null
|
|
3315
|
+
};
|
|
3316
|
+
}
|
|
3317
|
+
async function runIssueView(sdk, input) {
|
|
3318
|
+
assertIssueInput(input);
|
|
3319
|
+
const result = await sdk.IssueView(input);
|
|
3320
|
+
const issue = result.repository?.issue;
|
|
3321
|
+
if (!issue) {
|
|
3322
|
+
throw new Error("Issue not found");
|
|
3323
|
+
}
|
|
3324
|
+
return {
|
|
3325
|
+
id: issue.id,
|
|
3326
|
+
number: issue.number,
|
|
3327
|
+
title: issue.title,
|
|
3328
|
+
state: issue.state,
|
|
3329
|
+
url: issue.url
|
|
3330
|
+
};
|
|
3331
|
+
}
|
|
3332
|
+
async function runIssueList(sdk, input) {
|
|
3333
|
+
assertIssueListInput(input);
|
|
3334
|
+
const result = await sdk.IssueList(input);
|
|
3335
|
+
const issues = result.repository?.issues;
|
|
3336
|
+
if (!issues) {
|
|
3337
|
+
throw new Error("Issues not found");
|
|
3338
|
+
}
|
|
3339
|
+
return {
|
|
3340
|
+
items: (issues.nodes ?? []).flatMap(
|
|
3341
|
+
(issue) => issue ? [
|
|
3342
|
+
{
|
|
3343
|
+
id: issue.id,
|
|
3344
|
+
number: issue.number,
|
|
3345
|
+
title: issue.title,
|
|
3346
|
+
state: issue.state,
|
|
3347
|
+
url: issue.url
|
|
3348
|
+
}
|
|
3349
|
+
] : []
|
|
3350
|
+
),
|
|
3351
|
+
pageInfo: {
|
|
3352
|
+
endCursor: issues.pageInfo.endCursor ?? null,
|
|
3353
|
+
hasNextPage: issues.pageInfo.hasNextPage
|
|
3354
|
+
}
|
|
3355
|
+
};
|
|
3356
|
+
}
|
|
3357
|
+
async function runIssueCommentsList(sdk, input) {
|
|
3358
|
+
assertIssueCommentsListInput(input);
|
|
3359
|
+
const result = await sdk.IssueCommentsList(input);
|
|
3360
|
+
const comments = result.repository?.issue?.comments;
|
|
3361
|
+
if (!comments) {
|
|
3362
|
+
throw new Error("Issue comments not found");
|
|
3363
|
+
}
|
|
3364
|
+
return {
|
|
3365
|
+
items: (comments.nodes ?? []).flatMap(
|
|
3366
|
+
(comment) => comment ? [
|
|
3367
|
+
{
|
|
3368
|
+
id: comment.id,
|
|
3369
|
+
body: comment.body,
|
|
3370
|
+
authorLogin: comment.author?.login ?? null,
|
|
3371
|
+
createdAt: comment.createdAt,
|
|
3372
|
+
url: String(comment.url)
|
|
3373
|
+
}
|
|
3374
|
+
] : []
|
|
3375
|
+
),
|
|
3376
|
+
pageInfo: {
|
|
3377
|
+
endCursor: comments.pageInfo.endCursor ?? null,
|
|
3378
|
+
hasNextPage: comments.pageInfo.hasNextPage
|
|
3379
|
+
}
|
|
3380
|
+
};
|
|
3381
|
+
}
|
|
3382
|
+
function parseIssueNode(issue) {
|
|
3383
|
+
const issueRecord = asRecord(issue);
|
|
3384
|
+
if (!issueRecord || typeof issueRecord.id !== "string" || typeof issueRecord.number !== "number") {
|
|
3385
|
+
throw new Error("Issue mutation failed");
|
|
3386
|
+
}
|
|
3387
|
+
const result = {
|
|
3388
|
+
id: issueRecord.id,
|
|
3389
|
+
number: issueRecord.number
|
|
3390
|
+
};
|
|
3391
|
+
if (typeof issueRecord.title === "string") {
|
|
3392
|
+
result.title = issueRecord.title;
|
|
3393
|
+
}
|
|
3394
|
+
if (typeof issueRecord.state === "string") {
|
|
3395
|
+
result.state = issueRecord.state;
|
|
3396
|
+
}
|
|
3397
|
+
if (typeof issueRecord.url === "string") {
|
|
3398
|
+
result.url = issueRecord.url;
|
|
3399
|
+
}
|
|
3400
|
+
return result;
|
|
3401
|
+
}
|
|
3402
|
+
async function runIssueCreate(graphqlClient, input) {
|
|
3403
|
+
assertIssueCreateInput(input);
|
|
3404
|
+
const repositoryLookupResult = await graphqlClient.query(
|
|
3405
|
+
ISSUE_CREATE_REPOSITORY_ID_QUERY,
|
|
3406
|
+
{
|
|
3407
|
+
owner: input.owner,
|
|
3408
|
+
name: input.name
|
|
3409
|
+
}
|
|
3410
|
+
);
|
|
3411
|
+
const repositoryId = asRecord(asRecord(repositoryLookupResult)?.repository)?.id;
|
|
3412
|
+
if (typeof repositoryId !== "string" || repositoryId.length === 0) {
|
|
3413
|
+
throw new Error("Repository not found");
|
|
3414
|
+
}
|
|
3415
|
+
const result = await graphqlClient.query(ISSUE_CREATE_MUTATION, {
|
|
3416
|
+
repositoryId,
|
|
3417
|
+
title: input.title,
|
|
3418
|
+
body: input.body
|
|
3419
|
+
});
|
|
3420
|
+
const issue = asRecord(asRecord(result)?.createIssue)?.issue;
|
|
3421
|
+
return parseIssueNode(issue);
|
|
3422
|
+
}
|
|
3423
|
+
async function runIssueUpdate(graphqlClient, input) {
|
|
3424
|
+
assertIssueUpdateInput(input);
|
|
3425
|
+
const result = await graphqlClient.query(ISSUE_UPDATE_MUTATION, {
|
|
3426
|
+
issueId: input.issueId,
|
|
3427
|
+
title: input.title,
|
|
3428
|
+
body: input.body
|
|
3429
|
+
});
|
|
3430
|
+
const issue = asRecord(asRecord(result)?.updateIssue)?.issue;
|
|
3431
|
+
return parseIssueNode(issue);
|
|
3432
|
+
}
|
|
3433
|
+
async function runIssueClose(graphqlClient, input) {
|
|
3434
|
+
assertIssueMutationInput(input);
|
|
3435
|
+
const result = await graphqlClient.query(ISSUE_CLOSE_MUTATION, {
|
|
3436
|
+
issueId: input.issueId
|
|
3437
|
+
});
|
|
3438
|
+
const issueData = parseIssueNode(asRecord(asRecord(result)?.closeIssue)?.issue);
|
|
3439
|
+
return {
|
|
3440
|
+
...issueData,
|
|
3441
|
+
closed: issueData.state === "CLOSED"
|
|
3442
|
+
};
|
|
3443
|
+
}
|
|
3444
|
+
async function runIssueReopen(graphqlClient, input) {
|
|
3445
|
+
assertIssueMutationInput(input);
|
|
3446
|
+
const result = await graphqlClient.query(ISSUE_REOPEN_MUTATION, {
|
|
3447
|
+
issueId: input.issueId
|
|
3448
|
+
});
|
|
3449
|
+
const issueData = parseIssueNode(asRecord(asRecord(result)?.reopenIssue)?.issue);
|
|
3450
|
+
return {
|
|
3451
|
+
...issueData,
|
|
3452
|
+
reopened: issueData.state === "OPEN"
|
|
3453
|
+
};
|
|
3454
|
+
}
|
|
3455
|
+
async function runIssueDelete(graphqlClient, input) {
|
|
3456
|
+
assertIssueMutationInput(input);
|
|
3457
|
+
const result = await graphqlClient.query(ISSUE_DELETE_MUTATION, {
|
|
3458
|
+
issueId: input.issueId
|
|
3459
|
+
});
|
|
3460
|
+
const mutation = asRecord(asRecord(result)?.deleteIssue);
|
|
3461
|
+
if (!mutation) {
|
|
3462
|
+
throw new Error("Issue deletion failed");
|
|
3463
|
+
}
|
|
3464
|
+
return {
|
|
3465
|
+
id: input.issueId,
|
|
3466
|
+
number: 0,
|
|
3467
|
+
deleted: true
|
|
3468
|
+
};
|
|
3469
|
+
}
|
|
3470
|
+
async function runIssueLabelsUpdate(graphqlClient, input) {
|
|
3471
|
+
assertIssueLabelsUpdateInput(input);
|
|
3472
|
+
const lookupResult = await graphqlClient.query(
|
|
3473
|
+
ISSUE_LABELS_LOOKUP_QUERY,
|
|
3474
|
+
{
|
|
3475
|
+
issueId: input.issueId
|
|
3476
|
+
}
|
|
3477
|
+
);
|
|
3478
|
+
const availableLabels = Array.isArray(
|
|
3479
|
+
asRecord(asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.labels)?.nodes
|
|
3480
|
+
) ? asRecord(asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.labels)?.nodes : [];
|
|
3481
|
+
const labelIdsByName = /* @__PURE__ */ new Map();
|
|
3482
|
+
for (const label of availableLabels) {
|
|
3483
|
+
const labelRecord = asRecord(label);
|
|
3484
|
+
if (typeof labelRecord?.name === "string" && typeof labelRecord?.id === "string") {
|
|
3485
|
+
labelIdsByName.set(labelRecord.name.toLowerCase(), labelRecord.id);
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
const labelIds = input.labels.map((labelName) => {
|
|
3489
|
+
const id = labelIdsByName.get(labelName.toLowerCase());
|
|
3490
|
+
if (!id) {
|
|
3491
|
+
throw new Error(`Label not found: ${labelName}`);
|
|
3492
|
+
}
|
|
3493
|
+
return id;
|
|
3494
|
+
});
|
|
3495
|
+
const result = await graphqlClient.query(
|
|
3496
|
+
ISSUE_LABELS_UPDATE_MUTATION,
|
|
3497
|
+
{
|
|
3498
|
+
issueId: input.issueId,
|
|
3499
|
+
labelIds
|
|
3500
|
+
}
|
|
3501
|
+
);
|
|
3502
|
+
const mutation = asRecord(asRecord(result)?.["updateIssue"]);
|
|
3503
|
+
const issue = asRecord(mutation?.["issue"]);
|
|
3504
|
+
const labels = asRecord(issue?.["labels"]);
|
|
3505
|
+
const labelNodes = Array.isArray(labels?.["nodes"]) ? labels["nodes"] : [];
|
|
3506
|
+
return {
|
|
3507
|
+
id: assertNonEmptyString(issue?.["id"], "Issue id"),
|
|
3508
|
+
labels: labelNodes.map((label) => asRecord(label)?.["name"]).filter((name) => typeof name === "string")
|
|
3509
|
+
};
|
|
3510
|
+
}
|
|
3511
|
+
async function runIssueAssigneesUpdate(graphqlClient, input) {
|
|
3512
|
+
assertIssueAssigneesUpdateInput(input);
|
|
3513
|
+
const lookupResult = await graphqlClient.query(
|
|
3514
|
+
ISSUE_ASSIGNEES_LOOKUP_QUERY,
|
|
3515
|
+
{
|
|
3516
|
+
issueId: input.issueId
|
|
3517
|
+
}
|
|
3518
|
+
);
|
|
3519
|
+
const availableAssignees = Array.isArray(
|
|
3520
|
+
asRecord(asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.assignableUsers)?.nodes
|
|
3521
|
+
) ? asRecord(asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.assignableUsers)?.nodes : [];
|
|
3522
|
+
const assigneeIdsByLogin = /* @__PURE__ */ new Map();
|
|
3523
|
+
for (const assignee of availableAssignees) {
|
|
3524
|
+
const assigneeRecord = asRecord(assignee);
|
|
3525
|
+
if (typeof assigneeRecord?.login === "string" && typeof assigneeRecord?.id === "string") {
|
|
3526
|
+
assigneeIdsByLogin.set(assigneeRecord.login.toLowerCase(), assigneeRecord.id);
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
const assigneeIds = input.assignees.map((login) => {
|
|
3530
|
+
const id = assigneeIdsByLogin.get(login.toLowerCase());
|
|
3531
|
+
if (!id) {
|
|
3532
|
+
throw new Error(`Assignee not found: ${login}`);
|
|
3533
|
+
}
|
|
3534
|
+
return id;
|
|
3535
|
+
});
|
|
3536
|
+
const result = await graphqlClient.query(
|
|
3537
|
+
ISSUE_ASSIGNEES_UPDATE_MUTATION,
|
|
3538
|
+
{
|
|
3539
|
+
issueId: input.issueId,
|
|
3540
|
+
assigneeIds
|
|
3541
|
+
}
|
|
3542
|
+
);
|
|
3543
|
+
const mutation = asRecord(asRecord(result)?.["updateIssue"]);
|
|
3544
|
+
const issue = asRecord(mutation?.["issue"]);
|
|
3545
|
+
const assignees = asRecord(issue?.["assignees"]);
|
|
3546
|
+
const assigneeNodes = Array.isArray(assignees?.["nodes"]) ? assignees["nodes"] : [];
|
|
3547
|
+
return {
|
|
3548
|
+
id: assertNonEmptyString(issue?.["id"], "Issue id"),
|
|
3549
|
+
assignees: assigneeNodes.map((assignee) => asRecord(assignee)?.["login"]).filter((login) => typeof login === "string")
|
|
3550
|
+
};
|
|
3551
|
+
}
|
|
3552
|
+
async function runIssueMilestoneSet(graphqlClient, input) {
|
|
3553
|
+
assertIssueMilestoneSetInput(input);
|
|
3554
|
+
let milestoneId = null;
|
|
3555
|
+
if (input.milestoneNumber !== null) {
|
|
3556
|
+
const lookupResult = await graphqlClient.query(
|
|
3557
|
+
ISSUE_MILESTONE_LOOKUP_QUERY,
|
|
3558
|
+
{
|
|
3559
|
+
issueId: input.issueId,
|
|
3560
|
+
milestoneNumber: input.milestoneNumber
|
|
3561
|
+
}
|
|
3562
|
+
);
|
|
3563
|
+
const resolvedId = asRecord(
|
|
3564
|
+
asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.milestone
|
|
3565
|
+
)?.id;
|
|
3566
|
+
if (typeof resolvedId !== "string" || resolvedId.length === 0) {
|
|
3567
|
+
throw new Error(`Milestone not found: ${input.milestoneNumber}`);
|
|
3568
|
+
}
|
|
3569
|
+
milestoneId = resolvedId;
|
|
3570
|
+
}
|
|
3571
|
+
const result = await graphqlClient.query(
|
|
3572
|
+
ISSUE_MILESTONE_SET_MUTATION,
|
|
3573
|
+
{
|
|
3574
|
+
issueId: input.issueId,
|
|
3575
|
+
milestoneId
|
|
3576
|
+
}
|
|
3577
|
+
);
|
|
3578
|
+
const mutation = asRecord(asRecord(result)?.["updateIssue"]);
|
|
3579
|
+
const issue = asRecord(mutation?.["issue"]);
|
|
3580
|
+
const milestone = asRecord(issue?.["milestone"]);
|
|
3581
|
+
return {
|
|
3582
|
+
id: assertNonEmptyString(issue?.["id"], "Issue id"),
|
|
3583
|
+
milestoneNumber: typeof milestone?.["number"] === "number" ? milestone["number"] : null
|
|
3584
|
+
};
|
|
3585
|
+
}
|
|
3586
|
+
async function runIssueCommentCreate(graphqlClient, input) {
|
|
3587
|
+
assertIssueCommentCreateInput(input);
|
|
3588
|
+
const result = await graphqlClient.query(
|
|
3589
|
+
ISSUE_COMMENT_CREATE_MUTATION,
|
|
3590
|
+
{
|
|
3591
|
+
issueId: input.issueId,
|
|
3592
|
+
body: input.body
|
|
3593
|
+
}
|
|
3594
|
+
);
|
|
3595
|
+
const mutation = asRecord(asRecord(result)?.["addComment"]);
|
|
3596
|
+
const commentEdge = asRecord(mutation?.["commentEdge"]);
|
|
3597
|
+
const node = asRecord(commentEdge?.["node"]);
|
|
3598
|
+
if (!node || typeof node["id"] !== "string" || typeof node["body"] !== "string") {
|
|
3599
|
+
throw new Error("Issue comment creation failed");
|
|
3600
|
+
}
|
|
3601
|
+
return {
|
|
3602
|
+
id: node["id"],
|
|
3603
|
+
body: node["body"],
|
|
3604
|
+
url: typeof node["url"] === "string" ? node["url"] : ""
|
|
3605
|
+
};
|
|
3606
|
+
}
|
|
3607
|
+
async function runIssueLinkedPrsList(graphqlClient, input) {
|
|
3608
|
+
assertIssueLinkedPrsListInput(input);
|
|
3609
|
+
const result = await graphqlClient.query(ISSUE_LINKED_PRS_LIST_QUERY, {
|
|
3610
|
+
owner: input.owner,
|
|
3611
|
+
name: input.name,
|
|
3612
|
+
issueNumber: input.issueNumber
|
|
3613
|
+
});
|
|
3614
|
+
const issue = asRecord(asRecord(asRecord(result)?.repository)?.issue);
|
|
3615
|
+
const timelineItems = asRecord(issue?.timelineItems);
|
|
3616
|
+
const nodes = Array.isArray(timelineItems?.nodes) ? timelineItems.nodes : [];
|
|
3617
|
+
return {
|
|
3618
|
+
items: nodes.map((node) => asRecord(asRecord(node)?.["subject"])).filter(
|
|
3619
|
+
(subject) => Boolean(subject) && subject?.["__typename"] === "PullRequest"
|
|
3620
|
+
).flatMap((subject) => {
|
|
3621
|
+
if (!subject) {
|
|
3622
|
+
return [];
|
|
3623
|
+
}
|
|
3624
|
+
if (typeof subject["id"] !== "string" || typeof subject["number"] !== "number" || typeof subject["title"] !== "string" || typeof subject["state"] !== "string" || typeof subject["url"] !== "string") {
|
|
3625
|
+
return [];
|
|
3626
|
+
}
|
|
3627
|
+
return [
|
|
3628
|
+
{
|
|
3629
|
+
id: subject["id"],
|
|
3630
|
+
number: subject["number"],
|
|
3631
|
+
title: subject["title"],
|
|
3632
|
+
state: subject["state"],
|
|
3633
|
+
url: subject["url"]
|
|
3634
|
+
}
|
|
3635
|
+
];
|
|
3636
|
+
})
|
|
3637
|
+
};
|
|
3638
|
+
}
|
|
3639
|
+
function parseIssueRelationNode(node) {
|
|
3640
|
+
const record = asRecord(node);
|
|
3641
|
+
if (!record || typeof record.id !== "string" || typeof record.number !== "number") {
|
|
3642
|
+
return null;
|
|
3643
|
+
}
|
|
3644
|
+
return {
|
|
3645
|
+
id: record.id,
|
|
3646
|
+
number: record.number
|
|
3647
|
+
};
|
|
3648
|
+
}
|
|
3649
|
+
async function runIssueRelationsGet(graphqlClient, input) {
|
|
3650
|
+
assertIssueRelationsGetInput(input);
|
|
3651
|
+
const result = await graphqlClient.query(ISSUE_RELATIONS_GET_QUERY, {
|
|
3652
|
+
owner: input.owner,
|
|
3653
|
+
name: input.name,
|
|
3654
|
+
issueNumber: input.issueNumber
|
|
3655
|
+
});
|
|
3656
|
+
const issue = asRecord(asRecord(asRecord(result)?.repository)?.issue);
|
|
3657
|
+
const currentIssue = parseIssueRelationNode(issue);
|
|
3658
|
+
if (!currentIssue) {
|
|
3659
|
+
throw new Error("Issue relations not found");
|
|
3660
|
+
}
|
|
3661
|
+
const parent = parseIssueRelationNode(issue?.parent);
|
|
3662
|
+
const subIssues = asRecord(issue?.["subIssues"]);
|
|
3663
|
+
const blockedByConnection = asRecord(issue?.["blockedBy"]);
|
|
3664
|
+
const childrenNodes = Array.isArray(subIssues?.["nodes"]) ? subIssues["nodes"] : [];
|
|
3665
|
+
const blockedByNodes = Array.isArray(blockedByConnection?.["nodes"]) ? blockedByConnection["nodes"] : [];
|
|
3666
|
+
return {
|
|
3667
|
+
issue: currentIssue,
|
|
3668
|
+
parent,
|
|
3669
|
+
children: childrenNodes.map((node) => parseIssueRelationNode(node)).flatMap((node) => node ? [node] : []),
|
|
3670
|
+
blockedBy: blockedByNodes.map((node) => parseIssueRelationNode(node)).flatMap((node) => node ? [node] : [])
|
|
3671
|
+
};
|
|
3672
|
+
}
|
|
3673
|
+
async function runIssueParentSet(graphqlClient, input) {
|
|
3674
|
+
assertIssueParentSetInput(input);
|
|
3675
|
+
const result = await graphqlClient.query(ISSUE_PARENT_SET_MUTATION, {
|
|
3676
|
+
issueId: input.issueId,
|
|
3677
|
+
parentIssueId: input.parentIssueId
|
|
3678
|
+
});
|
|
3679
|
+
const mutation = asRecord(asRecord(result)?.addSubIssue);
|
|
3680
|
+
const parentIssue = asRecord(mutation?.issue);
|
|
3681
|
+
const subIssue = asRecord(mutation?.subIssue);
|
|
3682
|
+
if (typeof parentIssue?.id !== "string" || typeof subIssue?.id !== "string") {
|
|
3683
|
+
throw new Error("Issue parent update failed");
|
|
3684
|
+
}
|
|
3685
|
+
return {
|
|
3686
|
+
issueId: subIssue.id,
|
|
3687
|
+
parentIssueId: parentIssue.id
|
|
3688
|
+
};
|
|
3689
|
+
}
|
|
3690
|
+
async function runIssueParentRemove(graphqlClient, input) {
|
|
3691
|
+
assertIssueParentRemoveInput(input);
|
|
3692
|
+
const lookupResult = await graphqlClient.query(
|
|
3693
|
+
ISSUE_PARENT_LOOKUP_QUERY,
|
|
3694
|
+
{
|
|
3695
|
+
issueId: input.issueId
|
|
3696
|
+
}
|
|
3697
|
+
);
|
|
3698
|
+
const parentIssueId = asRecord(asRecord(asRecord(lookupResult)?.node)?.parent)?.id;
|
|
3699
|
+
if (typeof parentIssueId !== "string" || parentIssueId.length === 0) {
|
|
3700
|
+
throw new Error("Issue parent removal failed");
|
|
3701
|
+
}
|
|
3702
|
+
const result = await graphqlClient.query(
|
|
3703
|
+
ISSUE_PARENT_REMOVE_MUTATION,
|
|
3704
|
+
{
|
|
3705
|
+
issueId: input.issueId,
|
|
3706
|
+
parentIssueId
|
|
3707
|
+
}
|
|
3708
|
+
);
|
|
3709
|
+
const mutation = asRecord(asRecord(result)?.removeSubIssue);
|
|
3710
|
+
const parentIssue = asRecord(mutation?.issue);
|
|
3711
|
+
const subIssue = asRecord(mutation?.subIssue);
|
|
3712
|
+
if (typeof parentIssue?.id !== "string" || typeof subIssue?.id !== "string") {
|
|
3713
|
+
throw new Error("Issue parent removal failed");
|
|
3714
|
+
}
|
|
3715
|
+
return {
|
|
3716
|
+
issueId: subIssue.id,
|
|
3717
|
+
parentRemoved: true
|
|
3718
|
+
};
|
|
3719
|
+
}
|
|
3720
|
+
async function runIssueBlockedByAdd(graphqlClient, input) {
|
|
3721
|
+
assertIssueBlockedByInput(input);
|
|
3722
|
+
const result = await graphqlClient.query(
|
|
3723
|
+
ISSUE_BLOCKED_BY_ADD_MUTATION,
|
|
3724
|
+
{
|
|
3725
|
+
issueId: input.issueId,
|
|
3726
|
+
blockedByIssueId: input.blockedByIssueId
|
|
3727
|
+
}
|
|
3728
|
+
);
|
|
3729
|
+
const mutation = asRecord(asRecord(result)?.addBlockedBy);
|
|
3730
|
+
const issue = asRecord(mutation?.issue);
|
|
3731
|
+
const blockingIssue = asRecord(mutation?.blockingIssue);
|
|
3732
|
+
if (typeof issue?.id !== "string" || typeof blockingIssue?.id !== "string") {
|
|
3733
|
+
throw new Error("Issue dependency mutation failed");
|
|
3734
|
+
}
|
|
3735
|
+
return {
|
|
3736
|
+
issueId: issue.id,
|
|
3737
|
+
blockedByIssueId: blockingIssue.id
|
|
3738
|
+
};
|
|
3739
|
+
}
|
|
3740
|
+
async function runIssueBlockedByRemove(graphqlClient, input) {
|
|
3741
|
+
assertIssueBlockedByInput(input);
|
|
3742
|
+
const result = await graphqlClient.query(
|
|
3743
|
+
ISSUE_BLOCKED_BY_REMOVE_MUTATION,
|
|
3744
|
+
{
|
|
3745
|
+
issueId: input.issueId,
|
|
3746
|
+
blockedByIssueId: input.blockedByIssueId
|
|
3747
|
+
}
|
|
3748
|
+
);
|
|
3749
|
+
const mutation = asRecord(asRecord(result)?.removeBlockedBy);
|
|
3750
|
+
const issue = asRecord(mutation?.issue);
|
|
3751
|
+
const blockingIssue = asRecord(mutation?.blockingIssue);
|
|
3752
|
+
if (typeof issue?.id !== "string" || typeof blockingIssue?.id !== "string") {
|
|
3753
|
+
throw new Error("Issue dependency mutation failed");
|
|
3754
|
+
}
|
|
3755
|
+
return {
|
|
3756
|
+
issueId: issue.id,
|
|
3757
|
+
blockedByIssueId: blockingIssue.id,
|
|
3758
|
+
removed: true
|
|
3759
|
+
};
|
|
3760
|
+
}
|
|
3761
|
+
async function runPrView(sdk, input) {
|
|
3762
|
+
assertPrInput(input);
|
|
3763
|
+
const result = await sdk.PrView(input);
|
|
3764
|
+
const pr = result.repository?.pullRequest;
|
|
3765
|
+
if (!pr) {
|
|
3766
|
+
throw new Error("Pull request not found");
|
|
3767
|
+
}
|
|
3768
|
+
return {
|
|
3769
|
+
id: pr.id,
|
|
3770
|
+
number: pr.number,
|
|
3771
|
+
title: pr.title,
|
|
3772
|
+
state: pr.state,
|
|
3773
|
+
url: pr.url
|
|
3774
|
+
};
|
|
3775
|
+
}
|
|
3776
|
+
async function runPrList(sdk, input) {
|
|
3777
|
+
assertPrListInput(input);
|
|
3778
|
+
const result = await sdk.PrList(input);
|
|
3779
|
+
const prs = result.repository?.pullRequests;
|
|
3780
|
+
if (!prs) {
|
|
3781
|
+
throw new Error("Pull requests not found");
|
|
3782
|
+
}
|
|
3783
|
+
return {
|
|
3784
|
+
items: (prs.nodes ?? []).flatMap(
|
|
3785
|
+
(pr) => pr ? [
|
|
3786
|
+
{
|
|
3787
|
+
id: pr.id,
|
|
3788
|
+
number: pr.number,
|
|
3789
|
+
title: pr.title,
|
|
3790
|
+
state: pr.state,
|
|
3791
|
+
url: pr.url
|
|
3792
|
+
}
|
|
3793
|
+
] : []
|
|
3794
|
+
),
|
|
3795
|
+
pageInfo: {
|
|
3796
|
+
endCursor: prs.pageInfo.endCursor ?? null,
|
|
3797
|
+
hasNextPage: prs.pageInfo.hasNextPage
|
|
3798
|
+
}
|
|
3799
|
+
};
|
|
3800
|
+
}
|
|
3801
|
+
async function runPrReviewsList(sdk, input) {
|
|
3802
|
+
assertPrReviewsListInput(input);
|
|
3803
|
+
const result = await sdk.PrReviewsList(input);
|
|
3804
|
+
const reviews = result.repository?.pullRequest?.reviews;
|
|
3805
|
+
if (!reviews) {
|
|
3806
|
+
throw new Error("Pull request reviews not found");
|
|
3807
|
+
}
|
|
3808
|
+
return {
|
|
3809
|
+
items: (reviews.nodes ?? []).flatMap(
|
|
3810
|
+
(review) => review ? [
|
|
3811
|
+
{
|
|
3812
|
+
id: review.id,
|
|
3813
|
+
authorLogin: review.author?.login ?? null,
|
|
3814
|
+
body: review.body,
|
|
3815
|
+
state: review.state,
|
|
3816
|
+
submittedAt: review.submittedAt ?? null,
|
|
3817
|
+
url: review.url,
|
|
3818
|
+
commitOid: review.commit?.oid ?? null
|
|
3819
|
+
}
|
|
3820
|
+
] : []
|
|
3821
|
+
),
|
|
3822
|
+
pageInfo: {
|
|
3823
|
+
endCursor: reviews.pageInfo.endCursor ?? null,
|
|
3824
|
+
hasNextPage: reviews.pageInfo.hasNextPage
|
|
3825
|
+
}
|
|
3826
|
+
};
|
|
3827
|
+
}
|
|
3828
|
+
async function runPrDiffListFiles(sdk, input) {
|
|
3829
|
+
assertPrDiffListFilesInput(input);
|
|
3830
|
+
const result = await sdk.PrDiffListFiles(input);
|
|
3831
|
+
const files = result.repository?.pullRequest?.files;
|
|
3832
|
+
if (!files) {
|
|
3833
|
+
throw new Error("Pull request files not found");
|
|
3834
|
+
}
|
|
3835
|
+
return {
|
|
3836
|
+
items: (files.nodes ?? []).flatMap(
|
|
3837
|
+
(file) => file ? [
|
|
3838
|
+
{
|
|
3839
|
+
path: file.path,
|
|
3840
|
+
additions: file.additions,
|
|
3841
|
+
deletions: file.deletions
|
|
3842
|
+
}
|
|
3843
|
+
] : []
|
|
3844
|
+
),
|
|
3845
|
+
pageInfo: {
|
|
3846
|
+
endCursor: files.pageInfo.endCursor ?? null,
|
|
3847
|
+
hasNextPage: files.pageInfo.hasNextPage
|
|
3848
|
+
}
|
|
3849
|
+
};
|
|
3850
|
+
}
|
|
3851
|
+
var MAX_PR_REVIEW_THREAD_SCAN_PAGES = 5;
|
|
3852
|
+
function asRecord(value) {
|
|
3853
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
|
|
3854
|
+
}
|
|
3855
|
+
function normalizePrReviewThreadComment(comment) {
|
|
3856
|
+
const commentRecord = asRecord(comment);
|
|
3857
|
+
if (!commentRecord || typeof commentRecord.id !== "string") {
|
|
3858
|
+
return null;
|
|
3859
|
+
}
|
|
3860
|
+
const author = asRecord(commentRecord.author);
|
|
3861
|
+
const url = commentRecord.url;
|
|
3862
|
+
return {
|
|
3863
|
+
id: commentRecord.id,
|
|
3864
|
+
authorLogin: typeof author?.login === "string" ? author.login : null,
|
|
3865
|
+
body: typeof commentRecord.body === "string" ? commentRecord.body : "",
|
|
3866
|
+
createdAt: typeof commentRecord.createdAt === "string" ? commentRecord.createdAt : "",
|
|
3867
|
+
url: typeof url === "string" ? url : String(url ?? "")
|
|
3868
|
+
};
|
|
3869
|
+
}
|
|
3870
|
+
function normalizePrReviewThread(thread) {
|
|
3871
|
+
const threadRecord = asRecord(thread);
|
|
3872
|
+
if (!threadRecord || typeof threadRecord.id !== "string") {
|
|
3873
|
+
return null;
|
|
3874
|
+
}
|
|
3875
|
+
const comments = asRecord(threadRecord.comments);
|
|
3876
|
+
const commentNodes = Array.isArray(comments?.nodes) ? comments.nodes : [];
|
|
3877
|
+
const resolvedBy = asRecord(threadRecord.resolvedBy);
|
|
3878
|
+
return {
|
|
3879
|
+
id: threadRecord.id,
|
|
3880
|
+
path: typeof threadRecord.path === "string" ? threadRecord.path : null,
|
|
3881
|
+
line: typeof threadRecord.line === "number" ? threadRecord.line : null,
|
|
3882
|
+
startLine: typeof threadRecord.startLine === "number" ? threadRecord.startLine : null,
|
|
3883
|
+
diffSide: typeof threadRecord.diffSide === "string" ? threadRecord.diffSide : null,
|
|
3884
|
+
subjectType: typeof threadRecord.subjectType === "string" ? threadRecord.subjectType : null,
|
|
3885
|
+
isResolved: Boolean(threadRecord.isResolved),
|
|
3886
|
+
isOutdated: Boolean(threadRecord.isOutdated),
|
|
3887
|
+
viewerCanReply: Boolean(threadRecord.viewerCanReply),
|
|
3888
|
+
viewerCanResolve: Boolean(threadRecord.viewerCanResolve),
|
|
3889
|
+
viewerCanUnresolve: Boolean(threadRecord.viewerCanUnresolve),
|
|
3890
|
+
resolvedByLogin: typeof resolvedBy?.login === "string" ? resolvedBy.login : null,
|
|
3891
|
+
comments: commentNodes.map((comment) => normalizePrReviewThreadComment(comment)).flatMap((comment) => comment ? [comment] : [])
|
|
3892
|
+
};
|
|
3893
|
+
}
|
|
3894
|
+
async function runPrCommentsList(graphqlClient, input) {
|
|
3895
|
+
assertPrCommentsListInput(input);
|
|
3896
|
+
const unresolvedOnly = input.unresolvedOnly ?? false;
|
|
3897
|
+
const includeOutdated = input.includeOutdated ?? true;
|
|
3898
|
+
const filteredThreads = [];
|
|
3899
|
+
let sourceEndCursor = input.after ?? null;
|
|
3900
|
+
let sourceHasNextPage = false;
|
|
3901
|
+
let pagesScanned = 0;
|
|
3902
|
+
let sourceItemsScanned = 0;
|
|
3903
|
+
while (pagesScanned < MAX_PR_REVIEW_THREAD_SCAN_PAGES && filteredThreads.length < input.first) {
|
|
3904
|
+
const result = await graphqlClient.query(PR_COMMENTS_LIST_QUERY, {
|
|
3905
|
+
owner: input.owner,
|
|
3906
|
+
name: input.name,
|
|
3907
|
+
prNumber: input.prNumber,
|
|
3908
|
+
first: input.first,
|
|
3909
|
+
after: sourceEndCursor
|
|
3910
|
+
});
|
|
3911
|
+
const repository = asRecord(asRecord(result)?.repository);
|
|
3912
|
+
const pullRequest = asRecord(repository?.pullRequest);
|
|
3913
|
+
const reviewThreads = asRecord(pullRequest?.reviewThreads);
|
|
3914
|
+
if (!reviewThreads) {
|
|
3915
|
+
throw new Error("Pull request review threads not found");
|
|
3916
|
+
}
|
|
3917
|
+
const pageInfo = asRecord(reviewThreads.pageInfo);
|
|
3918
|
+
const threadEdges = Array.isArray(reviewThreads.edges) ? reviewThreads.edges.map((edge) => {
|
|
3919
|
+
const edgeRecord = asRecord(edge);
|
|
3920
|
+
if (!edgeRecord) {
|
|
3921
|
+
return null;
|
|
3922
|
+
}
|
|
3923
|
+
return {
|
|
3924
|
+
cursor: typeof edgeRecord.cursor === "string" ? edgeRecord.cursor : null,
|
|
3925
|
+
node: edgeRecord.node
|
|
3926
|
+
};
|
|
3927
|
+
}).flatMap((edge) => edge ? [edge] : []) : [];
|
|
3928
|
+
const threadNodes = threadEdges.length > 0 ? threadEdges : Array.isArray(reviewThreads.nodes) ? reviewThreads.nodes.map((node) => ({ cursor: null, node })) : [];
|
|
3929
|
+
pagesScanned += 1;
|
|
3930
|
+
sourceItemsScanned += threadNodes.length;
|
|
3931
|
+
for (const threadNode of threadNodes) {
|
|
3932
|
+
const normalized = normalizePrReviewThread(threadNode.node);
|
|
3933
|
+
if (!normalized) {
|
|
3934
|
+
continue;
|
|
3935
|
+
}
|
|
3936
|
+
if (unresolvedOnly && normalized.isResolved) {
|
|
3937
|
+
continue;
|
|
3938
|
+
}
|
|
3939
|
+
if (unresolvedOnly && !includeOutdated && normalized.isOutdated) {
|
|
3940
|
+
continue;
|
|
3941
|
+
}
|
|
3942
|
+
filteredThreads.push({ thread: normalized, cursor: threadNode.cursor });
|
|
3943
|
+
}
|
|
3944
|
+
sourceHasNextPage = Boolean(pageInfo?.hasNextPage);
|
|
3945
|
+
sourceEndCursor = typeof pageInfo?.endCursor === "string" ? pageInfo.endCursor : null;
|
|
3946
|
+
if (!sourceHasNextPage) {
|
|
3947
|
+
break;
|
|
3948
|
+
}
|
|
3949
|
+
}
|
|
3950
|
+
const hasBufferedFilteredItems = filteredThreads.length > input.first;
|
|
3951
|
+
const returnedThreads = filteredThreads.slice(0, input.first);
|
|
3952
|
+
const endCursor = returnedThreads.length > 0 ? returnedThreads[returnedThreads.length - 1]?.cursor ?? sourceEndCursor : sourceEndCursor;
|
|
3953
|
+
const scanTruncated = sourceHasNextPage && pagesScanned >= MAX_PR_REVIEW_THREAD_SCAN_PAGES;
|
|
3954
|
+
return {
|
|
3955
|
+
items: returnedThreads.map((entry) => entry.thread),
|
|
3956
|
+
pageInfo: {
|
|
3957
|
+
hasNextPage: hasBufferedFilteredItems || sourceHasNextPage,
|
|
3958
|
+
endCursor: hasBufferedFilteredItems || sourceHasNextPage ? endCursor : null
|
|
3959
|
+
},
|
|
3960
|
+
filterApplied: {
|
|
3961
|
+
unresolvedOnly,
|
|
3962
|
+
includeOutdated
|
|
3963
|
+
},
|
|
3964
|
+
scan: {
|
|
3965
|
+
pagesScanned,
|
|
3966
|
+
sourceItemsScanned,
|
|
3967
|
+
scanTruncated
|
|
3968
|
+
}
|
|
3969
|
+
};
|
|
3970
|
+
}
|
|
3971
|
+
function assertReviewThreadInput(input) {
|
|
3972
|
+
if (typeof input.threadId !== "string" || input.threadId.trim().length === 0) {
|
|
3973
|
+
throw new Error("Review thread id is required");
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
function assertReplyToReviewThreadInput(input) {
|
|
3977
|
+
assertReviewThreadInput(input);
|
|
3978
|
+
if (typeof input.body !== "string" || input.body.trim().length === 0) {
|
|
3979
|
+
throw new Error("Reply body is required");
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3982
|
+
function parseReviewThreadMutationResult(result, mutationKey) {
|
|
3983
|
+
const root = asRecord(result);
|
|
3984
|
+
const mutation = asRecord(root?.[mutationKey]);
|
|
3985
|
+
const thread = asRecord(mutation?.thread);
|
|
3986
|
+
if (!thread || typeof thread.id !== "string") {
|
|
3987
|
+
throw new Error("Review thread mutation failed");
|
|
3988
|
+
}
|
|
3989
|
+
return {
|
|
3990
|
+
id: thread.id,
|
|
3991
|
+
isResolved: Boolean(thread.isResolved)
|
|
3992
|
+
};
|
|
3993
|
+
}
|
|
3994
|
+
async function runReplyToReviewThread(graphqlClient, input) {
|
|
3995
|
+
assertReplyToReviewThreadInput(input);
|
|
3996
|
+
const result = await graphqlClient.query(PR_COMMENT_REPLY_MUTATION, {
|
|
3997
|
+
threadId: input.threadId,
|
|
3998
|
+
body: input.body
|
|
3999
|
+
});
|
|
4000
|
+
const root = asRecord(result);
|
|
4001
|
+
const mutation = asRecord(root?.addPullRequestReviewThreadReply);
|
|
4002
|
+
const comment = asRecord(mutation?.comment);
|
|
4003
|
+
if (!comment || typeof comment.id !== "string") {
|
|
4004
|
+
throw new Error("Review thread mutation failed");
|
|
4005
|
+
}
|
|
4006
|
+
const threadStateResult = await graphqlClient.query(
|
|
4007
|
+
REVIEW_THREAD_STATE_QUERY,
|
|
4008
|
+
{
|
|
4009
|
+
threadId: input.threadId
|
|
4010
|
+
}
|
|
4011
|
+
);
|
|
4012
|
+
const threadNode = asRecord(asRecord(threadStateResult)?.node);
|
|
4013
|
+
if (!threadNode || typeof threadNode.id !== "string") {
|
|
4014
|
+
throw new Error("Review thread state lookup failed");
|
|
4015
|
+
}
|
|
4016
|
+
return {
|
|
4017
|
+
id: input.threadId,
|
|
4018
|
+
isResolved: Boolean(threadNode.isResolved)
|
|
4019
|
+
};
|
|
4020
|
+
}
|
|
4021
|
+
async function runResolveReviewThread(graphqlClient, input) {
|
|
4022
|
+
assertReviewThreadInput(input);
|
|
4023
|
+
const result = await graphqlClient.query(PR_COMMENT_RESOLVE_MUTATION, {
|
|
4024
|
+
threadId: input.threadId
|
|
4025
|
+
});
|
|
4026
|
+
return parseReviewThreadMutationResult(result, "resolveReviewThread");
|
|
4027
|
+
}
|
|
4028
|
+
async function runUnresolveReviewThread(graphqlClient, input) {
|
|
4029
|
+
assertReviewThreadInput(input);
|
|
4030
|
+
const result = await graphqlClient.query(
|
|
4031
|
+
PR_COMMENT_UNRESOLVE_MUTATION,
|
|
4032
|
+
{
|
|
4033
|
+
threadId: input.threadId
|
|
4034
|
+
}
|
|
4035
|
+
);
|
|
4036
|
+
return parseReviewThreadMutationResult(result, "unresolveReviewThread");
|
|
4037
|
+
}
|
|
4038
|
+
function queryToString(query) {
|
|
4039
|
+
if (typeof query === "string") {
|
|
4040
|
+
return query;
|
|
4041
|
+
}
|
|
4042
|
+
if (typeof query === "object" && query !== null && "kind" in query) {
|
|
4043
|
+
return print(query);
|
|
4044
|
+
}
|
|
4045
|
+
return String(query);
|
|
4046
|
+
}
|
|
4047
|
+
function assertQuery(query) {
|
|
4048
|
+
if (query.trim().length === 0) {
|
|
4049
|
+
throw new Error("GraphQL query must be non-empty");
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
function createGraphqlClient(transport) {
|
|
4053
|
+
return {
|
|
4054
|
+
async query(query, variables) {
|
|
4055
|
+
const queryText = queryToString(query);
|
|
4056
|
+
assertQuery(queryText);
|
|
4057
|
+
return transport.execute(queryText, variables);
|
|
4058
|
+
}
|
|
4059
|
+
};
|
|
4060
|
+
}
|
|
4061
|
+
var DEFAULT_GRAPHQL_URL = "https://api.github.com/graphql";
|
|
4062
|
+
function resolveGraphqlUrl() {
|
|
4063
|
+
if (process.env.GITHUB_GRAPHQL_URL) {
|
|
4064
|
+
return process.env.GITHUB_GRAPHQL_URL;
|
|
4065
|
+
}
|
|
4066
|
+
if (process.env.GH_HOST) {
|
|
4067
|
+
return `https://${process.env.GH_HOST}/api/graphql`;
|
|
4068
|
+
}
|
|
4069
|
+
return DEFAULT_GRAPHQL_URL;
|
|
4070
|
+
}
|
|
4071
|
+
function createTokenTransport(token, graphqlUrl) {
|
|
4072
|
+
const url = graphqlUrl ?? resolveGraphqlUrl();
|
|
4073
|
+
return {
|
|
4074
|
+
async execute(query, variables) {
|
|
4075
|
+
const response = await fetch(url, {
|
|
4076
|
+
method: "POST",
|
|
4077
|
+
headers: {
|
|
4078
|
+
"content-type": "application/json",
|
|
4079
|
+
authorization: `Bearer ${token}`
|
|
4080
|
+
},
|
|
4081
|
+
body: JSON.stringify({ query, variables: variables ?? {} })
|
|
4082
|
+
});
|
|
4083
|
+
const payload = await response.json();
|
|
4084
|
+
if (!response.ok) {
|
|
4085
|
+
throw new Error(payload.message ?? `GraphQL request failed (${response.status})`);
|
|
4086
|
+
}
|
|
4087
|
+
if (payload.errors?.length) {
|
|
4088
|
+
throw new Error(payload.errors[0]?.message ?? "GraphQL returned errors");
|
|
4089
|
+
}
|
|
4090
|
+
if (payload.data === void 0) {
|
|
4091
|
+
throw new Error("GraphQL response missing data");
|
|
4092
|
+
}
|
|
4093
|
+
return payload.data;
|
|
4094
|
+
}
|
|
4095
|
+
};
|
|
4096
|
+
}
|
|
4097
|
+
function createGithubClientFromToken(tokenOrOptions) {
|
|
4098
|
+
const token = typeof tokenOrOptions === "string" ? tokenOrOptions : tokenOrOptions.token;
|
|
4099
|
+
const graphqlUrl = typeof tokenOrOptions === "string" ? void 0 : tokenOrOptions.graphqlUrl;
|
|
4100
|
+
if (!token || token.trim().length === 0) {
|
|
4101
|
+
throw new Error("GitHub token is required");
|
|
4102
|
+
}
|
|
4103
|
+
return createGithubClient(createTokenTransport(token, graphqlUrl));
|
|
4104
|
+
}
|
|
4105
|
+
function createGithubClient(transport) {
|
|
4106
|
+
const graphqlClient = createGraphqlClient(transport);
|
|
4107
|
+
const sdk = createSdkClients(transport);
|
|
4108
|
+
return {
|
|
4109
|
+
query: (query, variables) => graphqlClient.query(query, variables),
|
|
4110
|
+
fetchRepoView: (input) => runRepoView(sdk.repo, input),
|
|
4111
|
+
fetchIssueCommentsList: (input) => runIssueCommentsList(sdk.issueCommentsList, input),
|
|
4112
|
+
createIssue: (input) => runIssueCreate(graphqlClient, input),
|
|
4113
|
+
updateIssue: (input) => runIssueUpdate(graphqlClient, input),
|
|
4114
|
+
closeIssue: (input) => runIssueClose(graphqlClient, input),
|
|
4115
|
+
reopenIssue: (input) => runIssueReopen(graphqlClient, input),
|
|
4116
|
+
deleteIssue: (input) => runIssueDelete(graphqlClient, input),
|
|
4117
|
+
updateIssueLabels: (input) => runIssueLabelsUpdate(graphqlClient, input),
|
|
4118
|
+
updateIssueAssignees: (input) => runIssueAssigneesUpdate(graphqlClient, input),
|
|
4119
|
+
setIssueMilestone: (input) => runIssueMilestoneSet(graphqlClient, input),
|
|
4120
|
+
createIssueComment: (input) => runIssueCommentCreate(graphqlClient, input),
|
|
4121
|
+
fetchIssueLinkedPrs: (input) => runIssueLinkedPrsList(graphqlClient, input),
|
|
4122
|
+
fetchIssueRelations: (input) => runIssueRelationsGet(graphqlClient, input),
|
|
4123
|
+
setIssueParent: (input) => runIssueParentSet(graphqlClient, input),
|
|
4124
|
+
removeIssueParent: (input) => runIssueParentRemove(graphqlClient, input),
|
|
4125
|
+
addIssueBlockedBy: (input) => runIssueBlockedByAdd(graphqlClient, input),
|
|
4126
|
+
removeIssueBlockedBy: (input) => runIssueBlockedByRemove(graphqlClient, input),
|
|
4127
|
+
fetchIssueList: (input) => runIssueList(sdk.issueList, input),
|
|
4128
|
+
fetchIssueView: (input) => runIssueView(sdk.issue, input),
|
|
4129
|
+
fetchPrList: (input) => runPrList(sdk.prList, input),
|
|
4130
|
+
fetchPrView: (input) => runPrView(sdk.pr, input),
|
|
4131
|
+
fetchPrCommentsList: (input) => runPrCommentsList(graphqlClient, input),
|
|
4132
|
+
fetchPrReviewsList: (input) => runPrReviewsList(sdk.prReviewsList, input),
|
|
4133
|
+
fetchPrDiffListFiles: (input) => runPrDiffListFiles(sdk.prDiffListFiles, input),
|
|
4134
|
+
replyToReviewThread: (input) => runReplyToReviewThread(graphqlClient, input),
|
|
4135
|
+
resolveReviewThread: (input) => runResolveReviewThread(graphqlClient, input),
|
|
4136
|
+
unresolveReviewThread: (input) => runUnresolveReviewThread(graphqlClient, input)
|
|
4137
|
+
};
|
|
4138
|
+
}
|
|
4139
|
+
|
|
4140
|
+
export {
|
|
4141
|
+
createSafeCliCommandRunner,
|
|
4142
|
+
errorCodes,
|
|
4143
|
+
executeTask,
|
|
4144
|
+
createGraphqlClient,
|
|
4145
|
+
createGithubClientFromToken,
|
|
4146
|
+
createGithubClient
|
|
4147
|
+
};
|
|
4148
|
+
//# sourceMappingURL=chunk-PJ2JKKQE.js.map
|