@deepseek-ai/dsh-experimental-forge-github 0.2.2-alpha.2 → 0.2.2-alpha.3
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.i18n.yaml +8 -8
- package/README.md +9 -5
- package/README.zh.md +9 -5
- package/lib/index.js +301 -31
- package/lib/types/gh.d.ts +1 -1
- package/lib/types/graphql.d.ts +33 -3
- package/lib/types/index.d.ts +1 -1
- package/lib/types/provider.d.ts +6 -2
- package/lib/types/review.d.ts +13 -0
- package/package.json +10 -9
package/README.i18n.yaml
CHANGED
|
@@ -9,17 +9,17 @@
|
|
|
9
9
|
en: 1c2533aa62dd459c
|
|
10
10
|
zh: 3d26837df2bbf525
|
|
11
11
|
/deepseek-ai-dsh-experimental-forge-github/summary:
|
|
12
|
-
en:
|
|
13
|
-
zh:
|
|
12
|
+
en: c64194798b228b23
|
|
13
|
+
zh: 5b1a145621f0c90a
|
|
14
14
|
/deepseek-ai-dsh-experimental-forge-github/table-of-contents:
|
|
15
15
|
en: d152484eb41ac6b4
|
|
16
16
|
zh: 2f8a621b991260a1
|
|
17
17
|
/deepseek-ai-dsh-experimental-forge-github/use-this-package:
|
|
18
|
-
en:
|
|
19
|
-
zh:
|
|
18
|
+
en: f2bd06d91b744305
|
|
19
|
+
zh: ad956b539a43b880
|
|
20
20
|
/deepseek-ai-dsh-experimental-forge-github/understand-the-implementation:
|
|
21
|
-
en:
|
|
22
|
-
zh:
|
|
21
|
+
en: 90f3c10096be642a
|
|
22
|
+
zh: 4e1b663c52019ac2
|
|
23
23
|
/deepseek-ai-dsh-experimental-forge-github/further-exploration:
|
|
24
24
|
en: d377d5fd9d9f190e
|
|
25
25
|
zh: 920bcbfdb8c993f2
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
en: 26b946af4b742e17
|
|
31
31
|
zh: 00b34f0721ac72f6
|
|
32
32
|
/deepseek-ai-dsh-experimental-forge-github/known-limitations-and-deferred-work:
|
|
33
|
-
en:
|
|
34
|
-
zh:
|
|
33
|
+
en: 37308d9458bb9316
|
|
34
|
+
zh: 3d4188f3e94af282
|
|
35
35
|
/deepseek-ai-dsh-experimental-forge-github/known-limitations-and-deferred-work/dev-note:
|
|
36
36
|
en: e67f633dc6fe7773
|
|
37
37
|
zh: 3bb0c20c93f16f98
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ English | [中文](README.zh.md)
|
|
|
9
9
|
|
|
10
10
|
## Summary
|
|
11
11
|
|
|
12
|
-
Read GitHub and GitHub Enterprise pull requests for `ctx.forge` with the GitHub CLI that is already signed in on the host.
|
|
12
|
+
Read GitHub and GitHub Enterprise pull requests for `ctx.forge` with the GitHub CLI that is already signed in on the host. Each poll batches pull requests by host to read state, changed lines, checks, review decision, mergeability, and unresolved review threads for every due pull request.
|
|
13
13
|
|
|
14
14
|
## Table of Contents
|
|
15
15
|
|
|
@@ -38,12 +38,16 @@ The provider runs `gh` as a host process, even when Sessions execute commands in
|
|
|
38
38
|
|
|
39
39
|
The provider serves a remote URL in `https`, `http`, `ssh`, or `git` form, or in scp form such as `git@github.com:owner/name.git`, when its host is configured. HTTP(S) remotes retain custom ports in the host identity; SSH and Git transport ports are excluded. It serves pull request URLs of the form `https://<host>/<owner>/<name>/pull/<number>` with any trailing path, query, or fragment, and builds that form without the suffix as the canonical URL. A readiness probe runs `gh auth status --hostname <host>`: exit status 0 is `ready`, another exit status is `unauthenticated` with the first diagnostic line, and a `gh` that cannot start is `unavailable`. A head lookup returns up to 20 open pull requests whose head is the branch, newest first, excluding pull requests from forks; a lookup of the default branch returns none.
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Polling returns the first 100 head-commit check contexts without following pages. An incomplete preview sets `checksTruncated` and keeps GitHub’s aggregate state; its counts do not describe the full list. `fetchChecks(ref, signal)` reads complete details only for the requested PR, pinning continuation pages to the first response’s rollup. The combined UTF-8 JSON responses must fit `maxOutputBytes`; excess returns `too-large`. Failed or non-advancing pages fail only this detail read and leave polling results intact. Runs with the same application, workflow, event, and check name keep only the newest run id; a queued replacement supersedes an older completed run. Runs without a numeric database id are retained by node id because their relative age is unknown. Commit status contexts keep the newest result per context name. Complete lists derive their indicator from these results; unknown context kinds retain GitHub’s aggregate state.
|
|
42
|
+
|
|
43
|
+
Unfinished check runs and completed runs with stale, missing, or unrecognized conclusions map to `pending`. Other completed checks map to `success`, `failure` (failure, timed out, startup failure, or action required), `cancelled`, `skipped`, or `neutral`. Cancelled checks keep the rollup non-passing. Check runs keep their start and completion times. Commit status contexts map `SUCCESS` to `success`, `FAILURE` and `ERROR` to `failure`, and every other state to `pending`, and carry no times. A GraphQL `NOT_FOUND` error becomes a `not-found` failure. A response without GraphQL data or errors, including an HTTP error JSON body, uses the first stderr diagnostic or the body's message. Authentication diagnostics become `unauthenticated`; oversized check pages become `too-large`; rate limits and other failures become `unavailable`. Head lookups preserve the same diagnostic in their rejection.
|
|
42
44
|
|
|
43
45
|
A pull request is `mergeReady` when it is open, not a draft, GitHub reports its merge state as `CLEAN`, `HAS_HOOKS`, or `UNSTABLE`, and the signed-in user has write, maintain, or admin permission. `mergeMethods` lists the squash, merge-commit, and rebase methods the repository allows, the user's default merge method first. Marking ready runs `gh pr ready <number> --repo <host>/<owner>/<name>`. Merging calls `PUT repos/<owner>/<name>/pulls/<number>/merge` through `gh api` with the method and the expected head SHA, so GitHub refuses once new commits arrived, which is reported as `stale`. Unlike `gh pr merge`, it never enables auto-merge, never joins a merge queue, and never deletes the head branch. A refused action reports GitHub's message, and a diagnostic that mentions authentication becomes `unauthenticated`.
|
|
44
46
|
|
|
45
47
|
`diff` runs `gh pr diff <number> --repo <host>/<owner>/<name> --color never`. `fileText` reads `repos/<owner>/<name>/contents/<path>?ref=<commit>` through `gh api` with the raw media type and accepts only a full 40- or 64-digit hexadecimal commit. `fileUrl` returns `https://<host>/<owner>/<name>/blob/<commit>/<path>`. Both paths percent-encode each segment. A refused read becomes `not-found` for HTTP 404, `unauthenticated` for a diagnostic that mentions authentication, `too-large` for GitHub's `too_large` error, which a diff over its own size limit draws, and `unavailable` otherwise, with GitHub's message. A read whose output exceeds `maxOutputBytes` becomes `too-large`, and one that outlives `timeoutMs` becomes `unavailable`.
|
|
46
48
|
|
|
49
|
+
Review submission checks the current pull request head, then posts a single inline comment or one completed review through the REST API with an explicit `commit_id`. Multiline comments carry their side and inclusive start and end lines. Review decisions are Comment, Approve, and Request changes. JSON request bodies travel on stdin. The provider never retries a mutation: a timeout, unexpected response, or server error after dispatch returns an unknown outcome that the caller must reconcile on GitHub. A commit arriving between the check and the write can make the explicitly addressed review outdated; GitHub does not offer an atomic head precondition on these endpoints.
|
|
50
|
+
|
|
47
51
|
-----
|
|
48
52
|
|
|
49
53
|
<a id="understand-the-implementation"></a>
|
|
@@ -52,7 +56,7 @@ A pull request is `mergeReady` when it is open, not a draft, GitHub reports its
|
|
|
52
56
|
<details>
|
|
53
57
|
<summary>Implementation internals — click to expand</summary>
|
|
54
58
|
|
|
55
|
-
A fetch groups references by host and sends one `gh api graphql` query per host. The query inlines validated owner, name, and number values and gives each pull request an alias, so partial GraphQL errors fail only their own aliases. `gh` exits nonzero on partial errors but still prints the complete response, which the provider parses before it inspects the exit code.
|
|
59
|
+
A fetch groups references by host and sends one initial `gh api graphql` query per host. Continuation queries use the original rollup node id, so a changed pull request head cannot mix commits within one check list. The query inlines validated owner, name, and number values and gives each pull request an alias, so partial GraphQL errors fail only their own aliases. `gh` exits nonzero on partial errors but still prints the complete response, which the provider parses before it inspects the exit code.
|
|
56
60
|
|
|
57
61
|
| Source | Responsibility |
|
|
58
62
|
|---|---|
|
|
@@ -89,9 +93,9 @@ None. Provider output reaches only host-side watchers.
|
|
|
89
93
|
<a id="known-limitations-and-deferred-work"></a>
|
|
90
94
|
|
|
91
95
|
- **GitHub CLI on the host** — `gh` must be installed and signed in for each configured host; tokens in environment variables are not forwarded. Hosts missing from `hosts` are never read, including references retained across configuration changes. A status fetch returns `unavailable` for those references; a head lookup rejects before starting `gh`.
|
|
92
|
-
- **First 100
|
|
96
|
+
- **First 100 review threads** — unresolved threads after the first 100 are not counted.
|
|
93
97
|
- **No fork discovery** — head lookups exclude pull requests whose head is in another repository.
|
|
94
|
-
- **Rate limits** — every poll costs one GraphQL query per host against the signed-in account
|
|
98
|
+
- **Rate limits** — every poll costs one GraphQL query per host, plus one query per additional page of 100 check records, against the signed-in account’s rate limit.
|
|
95
99
|
- **No merge queue** — a base branch that requires a merge queue refuses a direct merge, and the provider never queues one.
|
|
96
100
|
|
|
97
101
|
<a id="dev-note"></a>
|
package/README.zh.md
CHANGED
|
@@ -9,7 +9,7 @@ kind: "package-reference"
|
|
|
9
9
|
|
|
10
10
|
## 概述
|
|
11
11
|
|
|
12
|
-
借助宿主上已登录的 GitHub CLI,为 `ctx.forge` 读取 GitHub 与 GitHub Enterprise 的 pull request
|
|
12
|
+
借助宿主上已登录的 GitHub CLI,为 `ctx.forge` 读取 GitHub 与 GitHub Enterprise 的 pull request。每次轮询按主机批量查询,读取所有到期 pull request 的状态、改动行数、检查、评审结论、可合并性与未解决的评审讨论。
|
|
13
13
|
|
|
14
14
|
## 目录
|
|
15
15
|
|
|
@@ -38,12 +38,16 @@ kind: "package-reference"
|
|
|
38
38
|
|
|
39
39
|
当主机在配置中时,提供方服务 `https`、`http`、`ssh`、`git` 形式的远端 URL,以及 `git@github.com:owner/name.git` 这类 scp 形式。HTTP(S) 远端在主机标识中保留自定义端口;SSH 和 Git 传输端口不计入主机标识。它服务 `https://<host>/<owner>/<name>/pull/<number>` 形式的 pull request URL,允许其后附带任意路径、查询或片段,并以去掉这些后缀的形式作为规范 URL。就绪探测运行 `gh auth status --hostname <host>`:退出码为 0 时为 `ready`,其他退出码为 `unauthenticated` 并带第一行诊断,`gh` 无法启动时为 `unavailable`。按 head 分支查找时,最多返回 20 个以该分支为 head 的打开状态 pull request,按创建时间从新到旧排列,不包含来自 fork 的 pull request;查找默认分支时返回空结果。
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
轮询只返回 head 提交的前 100 条检查上下文,不追读后续页。预览不完整时设置 `checksTruncated` 并保留 GitHub 的汇总状态,局部计数不代表完整列表。`fetchChecks(ref, signal)` 仅按需读取指定 PR 的完整详情,后续页固定使用首次响应的 rollup。所有 JSON 响应的 UTF-8 字节总量受 `maxOutputBytes` 限制,超出时返回 `too-large`。分页失败或游标不前进只使此次详情读取失败,保留轮询结果。同一应用、工作流、触发事件与检查名称的运行只保留运行 id 最新的一条;新的排队运行会替代旧的已完成运行。缺少数字数据库 id 的运行无法确定先后,因此按节点 id 保留。提交状态上下文按名称保留最新结果。完整列表从这些结果计算总体指示;未知上下文类型保留 GitHub 的汇总状态。
|
|
42
|
+
|
|
43
|
+
未完成的检查运行(check run),以及结论已过期、缺失或无法识别的已完成运行,均映射为 `pending`。其他已完成的检查映射为 `success`、`failure`(失败、超时、启动失败或需要操作)、`cancelled`、`skipped` 或 `neutral`。已取消的检查使汇总保持未通过状态。检查运行保留其开始与完成时间。提交状态上下文把 `SUCCESS` 映射为 `success`,把 `FAILURE` 与 `ERROR` 映射为 `failure`,其余状态均映射为 `pending`,且不带时间。GraphQL 的 `NOT_FOUND` 错误转为 `not-found` 失败。响应不含 GraphQL data 或 errors 时(包括 HTTP 错误 JSON),使用 stderr 的首条诊断或响应体的 message。认证诊断转为 `unauthenticated`;超出输出大小上限的检查分页转为 `too-large`;限流与其他失败转为 `unavailable`。head 查找在拒绝时保留相同诊断。
|
|
42
44
|
|
|
43
45
|
pull request 处于打开状态、不是草稿、GitHub 报告其合并状态为 `CLEAN`、`HAS_HOOKS` 或 `UNSTABLE`,且已登录用户具有 write、maintain 或 admin 权限时,`mergeReady` 为真。`mergeMethods` 列出仓库允许的压缩合并、合并提交与变基合并方式,用户默认的合并方式排在最前。标记为可评审运行 `gh pr ready <number> --repo <host>/<owner>/<name>`。合并经 `gh api` 调用 `PUT repos/<owner>/<name>/pulls/<number>/merge`,带上合并方式与预期的 head SHA,因此有新提交到达后 GitHub 会拒绝,报告为 `stale`。与 `gh pr merge` 不同,它从不启用自动合并、从不加入合并队列,也从不删除 head 分支。被拒绝的操作报告 GitHub 的原因,提到身份验证的诊断转为 `unauthenticated`。
|
|
44
46
|
|
|
45
47
|
`diff` 运行 `gh pr diff <number> --repo <host>/<owner>/<name> --color never`。`fileText` 经 `gh api` 以 raw 媒体类型读取 `repos/<owner>/<name>/contents/<path>?ref=<commit>`,只接受完整的 40 位或 64 位十六进制提交。`fileUrl` 返回 `https://<host>/<owner>/<name>/blob/<commit>/<path>`。两者的路径都逐段做百分号编码。被拒绝的读取在 HTTP 404 时为 `not-found`,诊断提到身份验证时为 `unauthenticated`,GitHub 报告 `too_large` 错误时(diff 超过其自身大小上限即会如此)为 `too-large`,其余为 `unavailable`,并带有 GitHub 的原因。输出超过 `maxOutputBytes` 的读取为 `too-large`,超过 `timeoutMs` 的为 `unavailable`。
|
|
46
48
|
|
|
49
|
+
提交评审时先检查 PR 当前的 head,再通过 REST API 发布单条行内评论或一次完整评审,并显式指定 `commit_id`。多行评论携带所属侧及包含端点的起止行号。评审结论为“评论”“批准”或“请求更改”。JSON 请求正文通过标准输入传递。provider 不会重试写操作;发送后的超时、异常响应或服务端错误会返回结果不明,由调用方到 GitHub 核对。检查与写入之间到来的新提交可能让已明确定位到旧提交的评审过时;GitHub 的这些接口不提供原子的 head 前置条件。
|
|
50
|
+
|
|
47
51
|
-----
|
|
48
52
|
|
|
49
53
|
<a id="understand-the-implementation"></a>
|
|
@@ -52,7 +56,7 @@ pull request 处于打开状态、不是草稿、GitHub 报告其合并状态为
|
|
|
52
56
|
<details>
|
|
53
57
|
<summary>实现细节——点击展开</summary>
|
|
54
58
|
|
|
55
|
-
|
|
59
|
+
一次读取按主机对引用分组,每个主机先发送一个 `gh api graphql` 查询。后续分页使用原汇总节点 id,因此 PR 的 head 变化不会让同一检查列表混入其他提交。查询内联经过校验的 owner、name 与编号,并为每个 pull request 设置别名,因此局部 GraphQL 错误只影响对应的别名。出现局部错误时 `gh` 以非零状态退出,但仍会输出完整响应;提供方先解析该响应,再检查退出码。
|
|
56
60
|
|
|
57
61
|
| 源码 | 职责 |
|
|
58
62
|
|---|---|
|
|
@@ -89,9 +93,9 @@ pull request 处于打开状态、不是草稿、GitHub 报告其合并状态为
|
|
|
89
93
|
<a id="known-limitations-and-deferred-work"></a>
|
|
90
94
|
|
|
91
95
|
- **宿主需要 GitHub CLI**——必须安装 `gh` 并为每个已配置主机登录;环境变量中的令牌不会被转发。不在 `hosts` 中的主机永远不会被读取,包括配置变更后保留的引用。状态读取为这些引用返回 `unavailable`;head 查找会在启动 `gh` 前拒绝。
|
|
92
|
-
- **前 100
|
|
96
|
+
- **前 100 个评审讨论**——前 100 个之后的未解决讨论不计入。
|
|
93
97
|
- **不发现 fork**——按 head 分支查找时,不包含 head 位于其他仓库的 pull request。
|
|
94
|
-
-
|
|
98
|
+
- **速率限制**——每次轮询以已登录账号的速率配额为每个主机消耗一次 GraphQL 查询;检查记录每多一页(100 条),再消耗一次查询。
|
|
95
99
|
- **不支持合并队列**——要求合并队列的基准分支会拒绝直接合并,提供方也不会把变更请求加入队列。
|
|
96
100
|
|
|
97
101
|
<a id="dev-note"></a>
|
package/lib/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var GhOutputLimitError = class extends Error {
|
|
|
27
27
|
* @returns the runner.
|
|
28
28
|
*/
|
|
29
29
|
function ghRunner(config) {
|
|
30
|
-
return async (args, signal) => {
|
|
30
|
+
return async (args, signal, input) => {
|
|
31
31
|
const result = await execa(config.ghCommand, args, {
|
|
32
32
|
env: {
|
|
33
33
|
...scrubbedParentEnv(),
|
|
@@ -38,7 +38,7 @@ function ghRunner(config) {
|
|
|
38
38
|
CLICOLOR: "0"
|
|
39
39
|
},
|
|
40
40
|
extendEnv: false,
|
|
41
|
-
stdin: "ignore",
|
|
41
|
+
...input === void 0 ? { stdin: "ignore" } : { input },
|
|
42
42
|
reject: false,
|
|
43
43
|
timeout: config.timeoutMs,
|
|
44
44
|
cancelSignal: signal,
|
|
@@ -129,18 +129,26 @@ function parsePullRequestUrl(url) {
|
|
|
129
129
|
//#endregion
|
|
130
130
|
//#region lib/types/graphql.js
|
|
131
131
|
/** GitHub GraphQL documents and their mapping into provider-neutral results. */
|
|
132
|
+
const CHECK_FIELDS = `pageInfo { hasNextPage endCursor }
|
|
133
|
+
nodes {
|
|
134
|
+
__typename
|
|
135
|
+
... on CheckRun {
|
|
136
|
+
id databaseId name status conclusion detailsUrl startedAt completedAt
|
|
137
|
+
checkSuite { app { id } workflowRun { event workflow { id name } } }
|
|
138
|
+
}
|
|
139
|
+
... on StatusContext { context state targetUrl createdAt }
|
|
140
|
+
}`;
|
|
132
141
|
const PULL_REQUEST_FIELDS = `number url title state isDraft updatedAt closedAt
|
|
133
142
|
author { login }
|
|
134
143
|
headRefName headRefOid baseRefName additions deletions mergeable mergeStateStatus reviewDecision
|
|
135
144
|
reviewThreads(first: 100) { nodes { isResolved } }
|
|
136
|
-
commits(last: 1) { nodes { commit { statusCheckRollup { state contexts(first: 100) {
|
|
137
|
-
|
|
138
|
-
nodes {
|
|
139
|
-
__typename
|
|
140
|
-
... on CheckRun { name status conclusion detailsUrl startedAt completedAt checkSuite { workflowRun { workflow { name } } } }
|
|
141
|
-
... on StatusContext { context state targetUrl }
|
|
142
|
-
}
|
|
145
|
+
commits(last: 1) { nodes { commit { statusCheckRollup { id state contexts(first: 100) {
|
|
146
|
+
${CHECK_FIELDS}
|
|
143
147
|
} } } } }`;
|
|
148
|
+
/** Continue reading the same commit's rollup even if the pull request head moves. */
|
|
149
|
+
const CHECKS_QUERY = `query($id: ID!, $cursor: String!) {
|
|
150
|
+
node(id: $id) { ... on StatusCheckRollup { contexts(first: 100, after: $cursor) { ${CHECK_FIELDS} } } }
|
|
151
|
+
}`;
|
|
144
152
|
const REPOSITORY_FIELDS = "squashMergeAllowed mergeCommitAllowed rebaseMergeAllowed viewerPermission viewerDefaultMergeMethod";
|
|
145
153
|
/** Head-branch lookup; variables `owner`, `name`, and `branch` are passed as strings. */
|
|
146
154
|
const HEAD_QUERY = `query($owner: String!, $name: String!, $branch: String!) {
|
|
@@ -151,20 +159,39 @@ const HEAD_QUERY = `query($owner: String!, $name: String!, $branch: String!) {
|
|
|
151
159
|
}`;
|
|
152
160
|
const checkRunSchema = z$1.object({
|
|
153
161
|
__typename: z$1.literal("CheckRun"),
|
|
162
|
+
id: z$1.string(),
|
|
163
|
+
databaseId: z$1.number().int().nonnegative().nullable(),
|
|
154
164
|
name: z$1.string(),
|
|
155
165
|
status: z$1.string(),
|
|
156
166
|
conclusion: z$1.string().nullable(),
|
|
157
167
|
detailsUrl: z$1.string().nullable(),
|
|
158
168
|
startedAt: z$1.string().nullable(),
|
|
159
169
|
completedAt: z$1.string().nullable(),
|
|
160
|
-
checkSuite: z$1.object({
|
|
170
|
+
checkSuite: z$1.object({
|
|
171
|
+
app: z$1.object({ id: z$1.string() }).nullable(),
|
|
172
|
+
workflowRun: z$1.object({
|
|
173
|
+
event: z$1.string(),
|
|
174
|
+
workflow: z$1.object({
|
|
175
|
+
id: z$1.string(),
|
|
176
|
+
name: z$1.string()
|
|
177
|
+
})
|
|
178
|
+
}).nullable()
|
|
179
|
+
}).nullable()
|
|
161
180
|
});
|
|
162
181
|
const statusContextSchema = z$1.object({
|
|
163
182
|
__typename: z$1.literal("StatusContext"),
|
|
164
183
|
context: z$1.string(),
|
|
184
|
+
createdAt: z$1.iso.datetime(),
|
|
165
185
|
state: z$1.string(),
|
|
166
186
|
targetUrl: z$1.string().nullable()
|
|
167
187
|
});
|
|
188
|
+
const checkPageSchema = z$1.object({
|
|
189
|
+
pageInfo: z$1.object({
|
|
190
|
+
hasNextPage: z$1.boolean(),
|
|
191
|
+
endCursor: z$1.string().nullable()
|
|
192
|
+
}),
|
|
193
|
+
nodes: z$1.array(z$1.unknown())
|
|
194
|
+
});
|
|
168
195
|
const pullRequestSchema = z$1.object({
|
|
169
196
|
url: z$1.string(),
|
|
170
197
|
title: z$1.string(),
|
|
@@ -187,11 +214,9 @@ const pullRequestSchema = z$1.object({
|
|
|
187
214
|
reviewDecision: z$1.string().nullable(),
|
|
188
215
|
reviewThreads: z$1.object({ nodes: z$1.array(z$1.object({ isResolved: z$1.boolean() })) }),
|
|
189
216
|
commits: z$1.object({ nodes: z$1.array(z$1.object({ commit: z$1.object({ statusCheckRollup: z$1.object({
|
|
217
|
+
id: z$1.string().transform((value) => value),
|
|
190
218
|
state: z$1.string(),
|
|
191
|
-
contexts:
|
|
192
|
-
pageInfo: z$1.object({ hasNextPage: z$1.boolean() }),
|
|
193
|
-
nodes: z$1.array(z$1.unknown())
|
|
194
|
-
})
|
|
219
|
+
contexts: checkPageSchema
|
|
195
220
|
}).nullable() }) })) })
|
|
196
221
|
});
|
|
197
222
|
const repositorySchema = z$1.object({
|
|
@@ -296,14 +321,17 @@ function snapshotQuery(refs) {
|
|
|
296
321
|
* Map a snapshot response, including GitHub's partial-error form, into one
|
|
297
322
|
* result per alias target. Path-scoped errors apply to their repository or
|
|
298
323
|
* pull request; errors without a path apply to every unresolved target. A
|
|
299
|
-
* repository without readable merge settings offers no merge.
|
|
324
|
+
* repository without readable merge settings offers no merge. Polling returns
|
|
325
|
+
* the first check page; an explicit detail read can complete its pagination.
|
|
300
326
|
* @param body - parsed JSON printed by `gh api graphql`.
|
|
301
327
|
* @param query - the query that produced the response.
|
|
302
|
-
* @
|
|
328
|
+
* @param readChecks - optional detail reader for the same commit; omission returns the first page with its truncation flag.
|
|
329
|
+
* @returns a snapshot with its check truncation flag, or a failure, for every target.
|
|
303
330
|
*/
|
|
304
|
-
function mapSnapshotResponse(body, query) {
|
|
331
|
+
async function mapSnapshotResponse(body, query, readChecks) {
|
|
305
332
|
const results = /* @__PURE__ */ new Map();
|
|
306
333
|
const parsed = responseSchema.safeParse(body);
|
|
334
|
+
const repositories = new Set([...query.targets.keys()].map((alias) => alias.split(".")[0]));
|
|
307
335
|
for (const [alias, ref] of query.targets) {
|
|
308
336
|
const key = changeRequestKey(ref);
|
|
309
337
|
if (!parsed.success) {
|
|
@@ -315,12 +343,35 @@ function mapSnapshotResponse(body, query) {
|
|
|
315
343
|
}
|
|
316
344
|
const [repositoryAlias = "", pullAlias = ""] = alias.split(".");
|
|
317
345
|
const errors = parsed.data.errors ?? [];
|
|
318
|
-
const error = errors.find((entry) => entry.path?.[0] === repositoryAlias && (entry.path.length === 1 || entry.path[1] === pullAlias)) ?? errors.find((entry) => entry.path === void 0);
|
|
346
|
+
const error = errors.find((entry) => entry.path?.[0] === repositoryAlias && (entry.path.length === 1 || entry.path[1] === pullAlias)) ?? errors.find((entry) => entry.path === void 0 || !repositories.has(String(entry.path[0])));
|
|
319
347
|
const raw = parsed.data.data?.[repositoryAlias]?.[pullAlias];
|
|
320
348
|
const node = pullRequestSchema.safeParse(raw);
|
|
321
349
|
const settings = repositorySchema.safeParse(parsed.data.data?.[repositoryAlias]);
|
|
322
|
-
if (node.success)
|
|
323
|
-
|
|
350
|
+
if (node.success) {
|
|
351
|
+
const rollup = node.data.commits.nodes[0]?.commit.statusCheckRollup;
|
|
352
|
+
if (rollup !== void 0 && rollup !== null) {
|
|
353
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
354
|
+
while (readChecks !== void 0 && rollup.contexts.pageInfo.hasNextPage) {
|
|
355
|
+
const cursor = rollup.contexts.pageInfo.endCursor;
|
|
356
|
+
if (cursor === null || cursors.has(cursor)) {
|
|
357
|
+
results.set(key, {
|
|
358
|
+
code: "unavailable",
|
|
359
|
+
message: "GitHub check pagination did not advance"
|
|
360
|
+
});
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
cursors.add(cursor);
|
|
364
|
+
const next = await readChecks(rollup.id, cursor);
|
|
365
|
+
if (!next.ok) {
|
|
366
|
+
results.set(key, next.failure);
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
rollup.contexts.nodes.push(...next.page.nodes);
|
|
370
|
+
rollup.contexts.pageInfo = next.page.pageInfo;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (!results.has(key)) results.set(key, toSnapshot(ref, node.data, settings.success ? settings.data : void 0));
|
|
374
|
+
} else if (error !== void 0) results.set(key, {
|
|
324
375
|
code: error.type === "NOT_FOUND" ? "not-found" : "unavailable",
|
|
325
376
|
message: error.message
|
|
326
377
|
});
|
|
@@ -336,6 +387,28 @@ function mapSnapshotResponse(body, query) {
|
|
|
336
387
|
return results;
|
|
337
388
|
}
|
|
338
389
|
/**
|
|
390
|
+
* Validate a continuation response before adding its checks to the snapshot.
|
|
391
|
+
* @param body - parsed GraphQL response for a rollup node.
|
|
392
|
+
* @returns the complete page or a failure; partial-error pages are not accepted.
|
|
393
|
+
*/
|
|
394
|
+
function mapCheckPageResponse(body) {
|
|
395
|
+
const parsed = z$1.object({
|
|
396
|
+
data: z$1.object({ node: z$1.object({ contexts: checkPageSchema }).nullable() }).nullable().optional(),
|
|
397
|
+
errors: z$1.array(z$1.object({ message: z$1.string() })).optional()
|
|
398
|
+
}).safeParse(body);
|
|
399
|
+
if (parsed.success && !parsed.data.errors?.length && parsed.data.data?.node != null) return {
|
|
400
|
+
ok: true,
|
|
401
|
+
page: parsed.data.data.node.contexts
|
|
402
|
+
};
|
|
403
|
+
return {
|
|
404
|
+
ok: false,
|
|
405
|
+
failure: {
|
|
406
|
+
code: "unavailable",
|
|
407
|
+
message: parsed.success ? parsed.data.errors?.[0]?.message ?? "GitHub check page is unavailable" : "unexpected GitHub check page"
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
339
412
|
* Map a head-branch lookup of {@link HEAD_QUERY}, which selects open pull requests, into change requests.
|
|
340
413
|
* @param body - parsed JSON printed by `gh api graphql`.
|
|
341
414
|
* @param repository - repository that was queried.
|
|
@@ -356,11 +429,27 @@ function mapHeadResponse(body, repository, branch) {
|
|
|
356
429
|
}
|
|
357
430
|
function toSnapshot(ref, node, settings) {
|
|
358
431
|
const rollup = node.commits.nodes[0]?.commit.statusCheckRollup ?? null;
|
|
359
|
-
const
|
|
432
|
+
const latest = /* @__PURE__ */ new Map();
|
|
433
|
+
let unknownContext = false;
|
|
434
|
+
const retain = (key, order, check) => {
|
|
435
|
+
const previous = latest.get(key);
|
|
436
|
+
if (previous === void 0 || order > previous.order) latest.set(key, {
|
|
437
|
+
order,
|
|
438
|
+
check
|
|
439
|
+
});
|
|
440
|
+
};
|
|
360
441
|
for (const context of rollup?.contexts.nodes ?? []) {
|
|
361
442
|
const run = checkRunSchema.safeParse(context);
|
|
362
443
|
if (run.success) {
|
|
363
|
-
|
|
444
|
+
const suite = run.data.checkSuite;
|
|
445
|
+
const workflow = suite?.workflowRun;
|
|
446
|
+
retain(run.data.databaseId === null ? JSON.stringify(["unranked-run", run.data.id]) : JSON.stringify([
|
|
447
|
+
"run",
|
|
448
|
+
run.data.name,
|
|
449
|
+
suite?.app?.id,
|
|
450
|
+
workflow?.workflow.id,
|
|
451
|
+
workflow?.event
|
|
452
|
+
]), run.data.databaseId ?? 0, {
|
|
364
453
|
name: run.data.name,
|
|
365
454
|
state: checkRunState(run.data.status, run.data.conclusion),
|
|
366
455
|
url: run.data.detailsUrl,
|
|
@@ -371,7 +460,7 @@ function toSnapshot(ref, node, settings) {
|
|
|
371
460
|
continue;
|
|
372
461
|
}
|
|
373
462
|
const status = statusContextSchema.safeParse(context);
|
|
374
|
-
if (status.success)
|
|
463
|
+
if (status.success) retain(JSON.stringify(["status", status.data.context]), Date.parse(status.data.createdAt), {
|
|
375
464
|
name: status.data.context,
|
|
376
465
|
state: statusContextState(status.data.state),
|
|
377
466
|
url: status.data.targetUrl,
|
|
@@ -379,7 +468,14 @@ function toSnapshot(ref, node, settings) {
|
|
|
379
468
|
startedAt: null,
|
|
380
469
|
completedAt: null
|
|
381
470
|
});
|
|
471
|
+
else if (typeof context === "object" && context !== null && "__typename" in context && (context.__typename === "CheckRun" || context.__typename === "StatusContext")) return {
|
|
472
|
+
code: "unavailable",
|
|
473
|
+
message: "unexpected GitHub check fields"
|
|
474
|
+
};
|
|
475
|
+
else unknownContext = true;
|
|
382
476
|
}
|
|
477
|
+
const checks = [...latest.values()].map((value) => value.check);
|
|
478
|
+
const summary = rollup?.contexts.pageInfo.hasNextPage || unknownContext || checks.length === 0 ? checksRollup(rollup?.state) : checks.some((check) => check.state === "failure" || check.state === "cancelled") ? "failure" : checks.some((check) => check.state === "pending") ? "pending" : "success";
|
|
383
479
|
return {
|
|
384
480
|
ref,
|
|
385
481
|
url: node.url,
|
|
@@ -397,7 +493,7 @@ function toSnapshot(ref, node, settings) {
|
|
|
397
493
|
mergeMethods: settings === void 0 ? [] : mergeMethods(settings),
|
|
398
494
|
reviewDecision: reviewDecision(node.reviewDecision),
|
|
399
495
|
checks,
|
|
400
|
-
checksRollup:
|
|
496
|
+
checksRollup: summary,
|
|
401
497
|
checksTruncated: rollup?.contexts.pageInfo.hasNextPage ?? false,
|
|
402
498
|
unresolvedThreads: node.reviewThreads.nodes.filter((thread) => !thread.isResolved).length,
|
|
403
499
|
updatedAt: node.updatedAt,
|
|
@@ -422,13 +518,14 @@ function checkRunState(status, conclusion) {
|
|
|
422
518
|
if (status !== "COMPLETED") return "pending";
|
|
423
519
|
switch (conclusion) {
|
|
424
520
|
case "SUCCESS": return "success";
|
|
521
|
+
case "ACTION_REQUIRED":
|
|
425
522
|
case "FAILURE":
|
|
426
523
|
case "TIMED_OUT":
|
|
427
|
-
case "STARTUP_FAILURE":
|
|
428
|
-
case "ACTION_REQUIRED": return "failure";
|
|
524
|
+
case "STARTUP_FAILURE": return "failure";
|
|
429
525
|
case "CANCELLED": return "cancelled";
|
|
430
526
|
case "SKIPPED": return "skipped";
|
|
431
|
-
|
|
527
|
+
case "NEUTRAL": return "neutral";
|
|
528
|
+
default: return "pending";
|
|
432
529
|
}
|
|
433
530
|
}
|
|
434
531
|
function statusContextState(state) {
|
|
@@ -464,6 +561,109 @@ function reviewDecision(value) {
|
|
|
464
561
|
}
|
|
465
562
|
}
|
|
466
563
|
//#endregion
|
|
564
|
+
//#region lib/types/review.js
|
|
565
|
+
/** GitHub review writes with commit checks and explicit treatment of uncertain outcomes. */
|
|
566
|
+
const pull = z$1.object({
|
|
567
|
+
head: z$1.object({ sha: z$1.string() }),
|
|
568
|
+
state: z$1.string()
|
|
569
|
+
});
|
|
570
|
+
const receipt = z$1.object({ html_url: z$1.url() });
|
|
571
|
+
const EVENTS = {
|
|
572
|
+
comment: "COMMENT",
|
|
573
|
+
approve: "APPROVE",
|
|
574
|
+
"request-changes": "REQUEST_CHANGES"
|
|
575
|
+
};
|
|
576
|
+
function inline(comment) {
|
|
577
|
+
const side = comment.side === "L" ? "LEFT" : "RIGHT";
|
|
578
|
+
return {
|
|
579
|
+
path: comment.path,
|
|
580
|
+
side,
|
|
581
|
+
line: comment.endLine,
|
|
582
|
+
body: comment.body,
|
|
583
|
+
...comment.startLine === comment.endLine ? {} : {
|
|
584
|
+
start_line: comment.startLine,
|
|
585
|
+
start_side: side
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
function failed(output, write) {
|
|
590
|
+
const known = /\(HTTP (?:400|401|403|404|409|422)\)/.test(output.stderr);
|
|
591
|
+
return {
|
|
592
|
+
ok: false,
|
|
593
|
+
code: write && !known ? "unknown" : "failed",
|
|
594
|
+
message: output.stderr.trim() || output.stdout.trim() || "GitHub request failed"
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Send one review mutation using JSON on stdin, never shell or argument interpolation.
|
|
599
|
+
* @param gh - bounded, cancellable GitHub CLI runner.
|
|
600
|
+
* @param ref - validated pull request address.
|
|
601
|
+
* @param request - frozen commit and comment ranges.
|
|
602
|
+
* @param signal - cancellation of preflight and mutation.
|
|
603
|
+
* @returns a confirmed receipt, refusal, stale commit, or uncertain outcome; never retries a write.
|
|
604
|
+
*/
|
|
605
|
+
async function submitGitHubReview(gh, ref, request, signal) {
|
|
606
|
+
const { host, owner, name } = checkedRepository(ref);
|
|
607
|
+
const endpoint = `repos/${owner}/${name}/pulls/${ref.number}`;
|
|
608
|
+
let writing = false;
|
|
609
|
+
try {
|
|
610
|
+
const read = await gh([
|
|
611
|
+
"api",
|
|
612
|
+
"--hostname",
|
|
613
|
+
host,
|
|
614
|
+
endpoint
|
|
615
|
+
], signal);
|
|
616
|
+
if (read.exitCode !== 0) return failed(read, false);
|
|
617
|
+
const current = pull.parse(JSON.parse(read.stdout));
|
|
618
|
+
if (current.head.sha !== request.headSha) return {
|
|
619
|
+
ok: false,
|
|
620
|
+
code: "stale",
|
|
621
|
+
message: "The pull request head has changed"
|
|
622
|
+
};
|
|
623
|
+
if (current.state !== "open") return {
|
|
624
|
+
ok: false,
|
|
625
|
+
code: "failed",
|
|
626
|
+
message: "The pull request is not open"
|
|
627
|
+
};
|
|
628
|
+
signal.throwIfAborted();
|
|
629
|
+
const body = request.kind === "comment" ? {
|
|
630
|
+
commit_id: request.headSha,
|
|
631
|
+
...inline(request.comment)
|
|
632
|
+
} : {
|
|
633
|
+
commit_id: request.headSha,
|
|
634
|
+
event: EVENTS[request.event],
|
|
635
|
+
body: request.body,
|
|
636
|
+
comments: request.comments.map(inline)
|
|
637
|
+
};
|
|
638
|
+
writing = true;
|
|
639
|
+
const output = await gh([
|
|
640
|
+
"api",
|
|
641
|
+
"--hostname",
|
|
642
|
+
host,
|
|
643
|
+
"--method",
|
|
644
|
+
"POST",
|
|
645
|
+
`${endpoint}/${request.kind === "comment" ? "comments" : "reviews"}`,
|
|
646
|
+
"--input",
|
|
647
|
+
"-"
|
|
648
|
+
], signal, JSON.stringify(body));
|
|
649
|
+
if (output.exitCode !== 0) return failed(output, true);
|
|
650
|
+
const result = receipt.parse(JSON.parse(output.stdout));
|
|
651
|
+
const url = new URL(result.html_url);
|
|
652
|
+
if (url.protocol !== "https:" || url.host !== host) throw new Error("GitHub returned an invalid review URL");
|
|
653
|
+
return {
|
|
654
|
+
ok: true,
|
|
655
|
+
url: result.html_url
|
|
656
|
+
};
|
|
657
|
+
} catch (error) {
|
|
658
|
+
if (!writing && signal.aborted) throw signal.reason;
|
|
659
|
+
return {
|
|
660
|
+
ok: false,
|
|
661
|
+
code: writing && !(error instanceof GhUnavailableError) ? "unknown" : "failed",
|
|
662
|
+
message: error instanceof Error ? error.message : String(error)
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
//#endregion
|
|
467
667
|
//#region lib/types/provider.js
|
|
468
668
|
/** GitHub implementation of the forge provider contract. */
|
|
469
669
|
const AUTHENTICATION = /gh auth login|authentication|bad credentials|HTTP 401/i;
|
|
@@ -479,14 +679,26 @@ const COMMIT = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;
|
|
|
479
679
|
/** Reads GitHub and GitHub Enterprise pull requests through a `gh` runner. */
|
|
480
680
|
var GitHubProvider = class {
|
|
481
681
|
gh;
|
|
682
|
+
maxOutputBytes;
|
|
482
683
|
forge = "github";
|
|
483
684
|
hosts;
|
|
685
|
+
async submitReview(ref, request, signal) {
|
|
686
|
+
const failure = this.hostFailure(ref.repository.host);
|
|
687
|
+
if (failure !== void 0) return {
|
|
688
|
+
ok: false,
|
|
689
|
+
code: "failed",
|
|
690
|
+
message: failure.message
|
|
691
|
+
};
|
|
692
|
+
return await submitGitHubReview(this.gh, ref, request, signal);
|
|
693
|
+
}
|
|
484
694
|
/**
|
|
485
695
|
* @param gh - runner that executes `gh` on the host.
|
|
486
696
|
* @param hosts - host names this provider serves, such as `github.com` and Enterprise hosts.
|
|
697
|
+
* @param maxOutputBytes - maximum combined JSON bytes retained by an explicit check read.
|
|
487
698
|
*/
|
|
488
|
-
constructor(gh, hosts) {
|
|
699
|
+
constructor(gh, hosts, maxOutputBytes) {
|
|
489
700
|
this.gh = gh;
|
|
701
|
+
this.maxOutputBytes = maxOutputBytes;
|
|
490
702
|
this.hosts = new Set(hosts.map((host) => host.toLowerCase()));
|
|
491
703
|
}
|
|
492
704
|
repositoryFromRemote(url) {
|
|
@@ -530,6 +742,20 @@ var GitHubProvider = class {
|
|
|
530
742
|
for (const [host, group] of byHost) for (const [key, result] of await this.fetchHost(host, group, signal)) results.set(key, result);
|
|
531
743
|
return results;
|
|
532
744
|
}
|
|
745
|
+
async fetchChecks(ref, signal) {
|
|
746
|
+
const failure = this.hostFailure(ref.repository.host);
|
|
747
|
+
if (failure !== void 0) return failure;
|
|
748
|
+
try {
|
|
749
|
+
return (await this.fetchHost(ref.repository.host, [ref], signal, true)).get(changeRequestKey(ref));
|
|
750
|
+
} catch (error) {
|
|
751
|
+
if (signal.aborted) throw signal.reason;
|
|
752
|
+
if (error instanceof GhUnavailableError || error instanceof GhTimeoutError || error instanceof GhOutputLimitError) return {
|
|
753
|
+
code: error instanceof GhOutputLimitError ? "too-large" : "unavailable",
|
|
754
|
+
message: error.message
|
|
755
|
+
};
|
|
756
|
+
throw error;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
533
759
|
async findByHead(repository, branch, signal) {
|
|
534
760
|
const failure = this.hostFailure(repository.host);
|
|
535
761
|
if (failure !== void 0) throw new Error(failure.message);
|
|
@@ -735,7 +961,7 @@ var GitHubProvider = class {
|
|
|
735
961
|
message: `forge-github: host ${JSON.stringify(host)} is not configured`
|
|
736
962
|
};
|
|
737
963
|
}
|
|
738
|
-
async fetchHost(host, refs, signal) {
|
|
964
|
+
async fetchHost(host, refs, signal, completeChecks = false) {
|
|
739
965
|
const query = snapshotQuery(refs);
|
|
740
966
|
const output = await this.gh([
|
|
741
967
|
"api",
|
|
@@ -746,7 +972,51 @@ var GitHubProvider = class {
|
|
|
746
972
|
`query=${query.document}`
|
|
747
973
|
], signal);
|
|
748
974
|
const body = parseJson(output.stdout);
|
|
749
|
-
if (hasGraphqlFields(body)) return mapSnapshotResponse(body, query);
|
|
975
|
+
if (!completeChecks && hasGraphqlFields(body)) return await mapSnapshotResponse(body, query);
|
|
976
|
+
let bytes = Buffer.byteLength(output.stdout);
|
|
977
|
+
const tooLarge = {
|
|
978
|
+
code: "too-large",
|
|
979
|
+
message: "GitHub check details exceed the output size limit"
|
|
980
|
+
};
|
|
981
|
+
if (bytes > this.maxOutputBytes) return new Map([...query.targets.values()].map((ref) => [changeRequestKey(ref), tooLarge]));
|
|
982
|
+
if (hasGraphqlFields(body)) return await mapSnapshotResponse(body, query, async (id, cursor) => {
|
|
983
|
+
signal.throwIfAborted();
|
|
984
|
+
let page;
|
|
985
|
+
try {
|
|
986
|
+
page = await this.gh([
|
|
987
|
+
"api",
|
|
988
|
+
"graphql",
|
|
989
|
+
"--hostname",
|
|
990
|
+
host,
|
|
991
|
+
"-f",
|
|
992
|
+
`query=${CHECKS_QUERY}`,
|
|
993
|
+
"-f",
|
|
994
|
+
`id=${id}`,
|
|
995
|
+
"-f",
|
|
996
|
+
`cursor=${cursor}`
|
|
997
|
+
], signal);
|
|
998
|
+
} catch (error) {
|
|
999
|
+
if (signal.aborted) throw signal.reason;
|
|
1000
|
+
if (error instanceof GhUnavailableError || error instanceof GhTimeoutError || error instanceof GhOutputLimitError) return {
|
|
1001
|
+
ok: false,
|
|
1002
|
+
failure: {
|
|
1003
|
+
code: error instanceof GhOutputLimitError ? "too-large" : "unavailable",
|
|
1004
|
+
message: error.message
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
1007
|
+
throw error;
|
|
1008
|
+
}
|
|
1009
|
+
bytes += Buffer.byteLength(page.stdout);
|
|
1010
|
+
if (bytes > this.maxOutputBytes) return {
|
|
1011
|
+
ok: false,
|
|
1012
|
+
failure: tooLarge
|
|
1013
|
+
};
|
|
1014
|
+
const value = parseJson(page.stdout);
|
|
1015
|
+
return hasGraphqlFields(value) ? mapCheckPageResponse(value) : {
|
|
1016
|
+
ok: false,
|
|
1017
|
+
failure: responseFailure(page, value)
|
|
1018
|
+
};
|
|
1019
|
+
});
|
|
750
1020
|
const failure = responseFailure(output, body);
|
|
751
1021
|
return new Map([...query.targets.values()].map((ref) => [changeRequestKey(ref), failure]));
|
|
752
1022
|
}
|
|
@@ -807,7 +1077,7 @@ function apply(ctx, config) {
|
|
|
807
1077
|
for (const host of resolved.hosts) if (!HOST.test(host)) throw new Error(`forge-github: invalid host ${JSON.stringify(host)}`);
|
|
808
1078
|
if (!Number.isSafeInteger(resolved.timeoutMs) || resolved.timeoutMs <= 0 || resolved.timeoutMs > MAX_TIMER_DELAY_MS) throw new Error(`forge-github: timeoutMs must be a positive integer no greater than ${MAX_TIMER_DELAY_MS}`);
|
|
809
1079
|
if (!Number.isSafeInteger(resolved.maxOutputBytes) || resolved.maxOutputBytes <= 0) throw new Error("forge-github: maxOutputBytes must be a positive safe integer");
|
|
810
|
-
ctx.forge.register(new GitHubProvider(ghRunner(resolved), resolved.hosts));
|
|
1080
|
+
ctx.forge.register(new GitHubProvider(ghRunner(resolved), resolved.hosts, resolved.maxOutputBytes));
|
|
811
1081
|
}
|
|
812
1082
|
//#endregion
|
|
813
1083
|
export { Config, apply, inject, name };
|
package/lib/types/gh.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface GhOutput {
|
|
|
9
9
|
readonly stderr: string;
|
|
10
10
|
}
|
|
11
11
|
/** Runs `gh` with literal arguments; rejects when the process cannot run to an exit code. */
|
|
12
|
-
export type GhRunner = (args: readonly string[], signal: AbortSignal) => Promise<GhOutput>;
|
|
12
|
+
export type GhRunner = (args: readonly string[], signal: AbortSignal, input?: string) => Promise<GhOutput>;
|
|
13
13
|
/** Resolved executable and limits for `gh`. */
|
|
14
14
|
export interface GhConfig {
|
|
15
15
|
/** Executable name or absolute host path. */
|
package/lib/types/graphql.d.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
/** GitHub GraphQL documents and their mapping into provider-neutral results. */
|
|
2
|
+
import type { Branded } from '@deepseek-ai/dsh-brand';
|
|
2
3
|
import type { ChangeRequestKey, ChangeRequestRef, ChangeRequestSnapshot, ForgeFailure, ForgeRepository } from '@deepseek-ai/dsh-experimental-forge';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
/** Continue reading the same commit's rollup even if the pull request head moves. */
|
|
6
|
+
export declare const CHECKS_QUERY = "query($id: ID!, $cursor: String!) {\n node(id: $id) { ... on StatusCheckRollup { contexts(first: 100, after: $cursor) { pageInfo { hasNextPage endCursor }\n nodes {\n __typename\n ... on CheckRun {\n id databaseId name status conclusion detailsUrl startedAt completedAt\n checkSuite { app { id } workflowRun { event workflow { id name } } }\n }\n ... on StatusContext { context state targetUrl createdAt }\n } } } }\n}";
|
|
3
7
|
/** Head-branch lookup; variables `owner`, `name`, and `branch` are passed as strings. */
|
|
4
8
|
export declare const HEAD_QUERY = "query($owner: String!, $name: String!, $branch: String!) {\n repository(owner: $owner, name: $name) {\n defaultBranchRef { name }\n pullRequests(headRefName: $branch, states: OPEN, first: 20, orderBy: { field: CREATED_AT, direction: DESC }) { nodes { number isCrossRepository } }\n }\n}";
|
|
9
|
+
declare const checkPageSchema: z.ZodObject<{
|
|
10
|
+
pageInfo: z.ZodObject<{
|
|
11
|
+
hasNextPage: z.ZodBoolean;
|
|
12
|
+
endCursor: z.ZodNullable<z.ZodString>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
nodes: z.ZodArray<z.ZodUnknown>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
/** One validated page of check contexts or a failure that prevents publishing a partial count. */
|
|
17
|
+
export type CheckPageResult = {
|
|
18
|
+
readonly ok: true;
|
|
19
|
+
readonly page: z.infer<typeof checkPageSchema>;
|
|
20
|
+
} | {
|
|
21
|
+
readonly ok: false;
|
|
22
|
+
readonly failure: ForgeFailure;
|
|
23
|
+
};
|
|
24
|
+
/** Opaque GitHub node id that pins check pagination to one commit's rollup. */
|
|
25
|
+
type RollupId = Branded<'GitHubStatusCheckRollupId'>;
|
|
5
26
|
/**
|
|
6
27
|
* Distinguish GraphQL response fields from HTTP error bodies.
|
|
7
28
|
* @param body - parsed JSON returned by GitHub.
|
|
@@ -27,12 +48,20 @@ export declare function snapshotQuery(refs: readonly ChangeRequestRef[]): Snapsh
|
|
|
27
48
|
* Map a snapshot response, including GitHub's partial-error form, into one
|
|
28
49
|
* result per alias target. Path-scoped errors apply to their repository or
|
|
29
50
|
* pull request; errors without a path apply to every unresolved target. A
|
|
30
|
-
* repository without readable merge settings offers no merge.
|
|
51
|
+
* repository without readable merge settings offers no merge. Polling returns
|
|
52
|
+
* the first check page; an explicit detail read can complete its pagination.
|
|
31
53
|
* @param body - parsed JSON printed by `gh api graphql`.
|
|
32
54
|
* @param query - the query that produced the response.
|
|
33
|
-
* @
|
|
55
|
+
* @param readChecks - optional detail reader for the same commit; omission returns the first page with its truncation flag.
|
|
56
|
+
* @returns a snapshot with its check truncation flag, or a failure, for every target.
|
|
34
57
|
*/
|
|
35
|
-
export declare function mapSnapshotResponse(body: unknown, query: SnapshotQuery): Map<ChangeRequestKey, ChangeRequestSnapshot | ForgeFailure
|
|
58
|
+
export declare function mapSnapshotResponse(body: unknown, query: SnapshotQuery, readChecks?: (id: RollupId, cursor: string) => Promise<CheckPageResult>): Promise<Map<ChangeRequestKey, ChangeRequestSnapshot | ForgeFailure>>;
|
|
59
|
+
/**
|
|
60
|
+
* Validate a continuation response before adding its checks to the snapshot.
|
|
61
|
+
* @param body - parsed GraphQL response for a rollup node.
|
|
62
|
+
* @returns the complete page or a failure; partial-error pages are not accepted.
|
|
63
|
+
*/
|
|
64
|
+
export declare function mapCheckPageResponse(body: unknown): CheckPageResult;
|
|
36
65
|
/**
|
|
37
66
|
* Map a head-branch lookup of {@link HEAD_QUERY}, which selects open pull requests, into change requests.
|
|
38
67
|
* @param body - parsed JSON printed by `gh api graphql`.
|
|
@@ -42,4 +71,5 @@ export declare function mapSnapshotResponse(body: unknown, query: SnapshotQuery)
|
|
|
42
71
|
* @throws when the response is malformed or the repository is not visible.
|
|
43
72
|
*/
|
|
44
73
|
export declare function mapHeadResponse(body: unknown, repository: ForgeRepository, branch: string): ChangeRequestRef[];
|
|
74
|
+
export {};
|
|
45
75
|
//# sourceMappingURL=graphql.d.ts.map
|
package/lib/types/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface Config {
|
|
|
11
11
|
hosts?: string[];
|
|
12
12
|
/** Deadline in milliseconds for one `gh` invocation. */
|
|
13
13
|
timeoutMs?: number;
|
|
14
|
-
/** Maximum captured bytes per `gh` output stream. */
|
|
14
|
+
/** Maximum captured bytes per `gh` output stream and combined JSON bytes of one complete check read. */
|
|
15
15
|
maxOutputBytes?: number;
|
|
16
16
|
}
|
|
17
17
|
export declare const Config: z<Config>;
|
package/lib/types/provider.d.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
/** GitHub implementation of the forge provider contract. */
|
|
2
|
-
import type { ChangeRequestKey, ChangeRequestRef, ChangeRequestSnapshot, ForgeActionFailure, ForgeFailure, ForgeProvider, ForgeReadiness, ForgeRepository, MergeRequest } from '@deepseek-ai/dsh-experimental-forge';
|
|
2
|
+
import type { ChangeRequestKey, ChangeRequestRef, ChangeRequestSnapshot, ForgeActionFailure, ForgeFailure, ForgeProvider, ForgeReadiness, ForgeRepository, ForgeReviewRequest, ForgeReviewResult, MergeRequest } from '@deepseek-ai/dsh-experimental-forge';
|
|
3
3
|
import type { GhRunner } from './gh.ts';
|
|
4
4
|
/** Reads GitHub and GitHub Enterprise pull requests through a `gh` runner. */
|
|
5
5
|
export declare class GitHubProvider implements ForgeProvider {
|
|
6
6
|
private readonly gh;
|
|
7
|
+
private readonly maxOutputBytes;
|
|
7
8
|
readonly forge = "github";
|
|
8
9
|
private readonly hosts;
|
|
10
|
+
submitReview(ref: ChangeRequestRef, request: ForgeReviewRequest, signal: AbortSignal): Promise<ForgeReviewResult>;
|
|
9
11
|
/**
|
|
10
12
|
* @param gh - runner that executes `gh` on the host.
|
|
11
13
|
* @param hosts - host names this provider serves, such as `github.com` and Enterprise hosts.
|
|
14
|
+
* @param maxOutputBytes - maximum combined JSON bytes retained by an explicit check read.
|
|
12
15
|
*/
|
|
13
|
-
constructor(gh: GhRunner, hosts: readonly string[]);
|
|
16
|
+
constructor(gh: GhRunner, hosts: readonly string[], maxOutputBytes: number);
|
|
14
17
|
repositoryFromRemote(url: string): ForgeRepository | undefined;
|
|
15
18
|
changeRequestFromUrl(url: string): ChangeRequestRef | undefined;
|
|
16
19
|
changeRequestUrl(ref: ChangeRequestRef): string;
|
|
17
20
|
fetch(refs: readonly ChangeRequestRef[], signal: AbortSignal): Promise<ReadonlyMap<ChangeRequestKey, ChangeRequestSnapshot | ForgeFailure>>;
|
|
21
|
+
fetchChecks(ref: ChangeRequestRef, signal: AbortSignal): Promise<ChangeRequestSnapshot | ForgeFailure>;
|
|
18
22
|
findByHead(repository: ForgeRepository, branch: string, signal: AbortSignal): Promise<readonly ChangeRequestRef[]>;
|
|
19
23
|
/**
|
|
20
24
|
* Mark a draft pull request ready for review with `gh pr ready`; one that
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** GitHub review writes with commit checks and explicit treatment of uncertain outcomes. */
|
|
2
|
+
import type { ChangeRequestRef, ForgeReviewRequest, ForgeReviewResult } from '@deepseek-ai/dsh-experimental-forge';
|
|
3
|
+
import { type GhRunner } from './gh.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Send one review mutation using JSON on stdin, never shell or argument interpolation.
|
|
6
|
+
* @param gh - bounded, cancellable GitHub CLI runner.
|
|
7
|
+
* @param ref - validated pull request address.
|
|
8
|
+
* @param request - frozen commit and comment ranges.
|
|
9
|
+
* @param signal - cancellation of preflight and mutation.
|
|
10
|
+
* @returns a confirmed receipt, refusal, stale commit, or uncertain outcome; never retries a write.
|
|
11
|
+
*/
|
|
12
|
+
export declare function submitGitHubReview(gh: GhRunner, ref: ChangeRequestRef, request: ForgeReviewRequest, signal: AbortSignal): Promise<ForgeReviewResult>;
|
|
13
|
+
//# sourceMappingURL=review.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-experimental-forge-github",
|
|
3
3
|
"description": "GitHub provider for the experimental forge registry, read through the GitHub CLI on the host",
|
|
4
|
-
"version": "0.2.2-alpha.
|
|
4
|
+
"version": "0.2.2-alpha.3",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -29,19 +29,20 @@
|
|
|
29
29
|
"directory": "packages/experimental/forge-github"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@deepseek-ai/schemastery": "~3.18.6-alpha.
|
|
33
|
-
"@deepseek-ai/dsh-timeout": "0.2.2-alpha.
|
|
32
|
+
"@deepseek-ai/schemastery": "~3.18.6-alpha.2",
|
|
33
|
+
"@deepseek-ai/dsh-timeout": "0.2.2-alpha.3",
|
|
34
34
|
"execa": "^10.0.1",
|
|
35
35
|
"zod": "^4.4.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@deepseek-ai/cordis": "~4.0.6-alpha.
|
|
39
|
-
"@deepseek-ai/dsh-experimental-forge": "0.2.2-alpha.
|
|
40
|
-
"@deepseek-ai/dsh-subprocess": "0.2.2-alpha.
|
|
38
|
+
"@deepseek-ai/cordis": "~4.0.6-alpha.2",
|
|
39
|
+
"@deepseek-ai/dsh-experimental-forge": "0.2.2-alpha.3",
|
|
40
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-alpha.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@deepseek-ai/cordis": "~4.0.6-alpha.
|
|
44
|
-
"@deepseek-ai/dsh-
|
|
45
|
-
"@deepseek-ai/dsh-
|
|
43
|
+
"@deepseek-ai/cordis": "~4.0.6-alpha.2",
|
|
44
|
+
"@deepseek-ai/dsh-brand": "0.2.2-alpha.3",
|
|
45
|
+
"@deepseek-ai/dsh-experimental-forge": "0.2.2-alpha.3",
|
|
46
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-alpha.3"
|
|
46
47
|
}
|
|
47
48
|
}
|