Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

【架构优化】从 githubPullsList 中拆出 PR 返回体类型 githubPullItem 与字段映射 out (#698) (#699)

fx-kurumi27bde9e7d3f4
diff --git a/internal/httpapi/agent_tool_github.go b/internal/httpapi/agent_tool_github.go
index 9aad5cac..a06ea895 100644
--- a/internal/httpapi/agent_tool_github.go
+++ b/internal/httpapi/agent_tool_github.go
@@ -502,6 +502,30 @@ type githubPullOut struct {
Updated string `json:"updatedAt"`
}
+type githubPullItem struct {
+ Number int64 `json:"number"`
+ Title string `json:"title"`
+ State string `json:"state"`
+ Draft bool `json:"draft"`
+ HTMLURL string `json:"html_url"`
+ User struct {
+ Login string `json:"login"`
+ } `json:"user"`
+ Head struct {
+ Ref string `json:"ref"`
+ } `json:"head"`
+ Base struct {
+ Ref string `json:"ref"`
+ } `json:"base"`
+ CreatedAt string `json:"created_at"`
+ UpdatedAt string `json:"updated_at"`
+}
+
+// out 把 /pulls 返回的一项转成工具输出的 githubPullOut。
+func (it githubPullItem) out() githubPullOut {
+ return githubPullOut{Number: it.Number, Title: it.Title, State: it.State, Draft: it.Draft, URL: it.HTMLURL, Author: it.User.Login, Head: it.Head.Ref, Base: it.Base.Ref, Created: it.CreatedAt, Updated: it.UpdatedAt}
+}
+
// githubPullsList 列 PR。不按作者过滤时多取一条即可判断 hasMore;按作者
// 过滤发生在取回之后(/pulls 不支持 author 参数),像 issues_list 一样按满页
// 翻页,最多 githubIssuesMaxPages 页。
@@ -532,24 +556,7 @@ func githubPullsList(ctx context.Context, token, path string, args map[string]an
if resp.StatusCode != http.StatusOK {
return "", githubToolError("读取 PR 列表", "Pull requests 读取", resp.StatusCode, raw)
}
- var items []struct {
- Number int64 `json:"number"`
- Title string `json:"title"`
- State string `json:"state"`
- Draft bool `json:"draft"`
- HTMLURL string `json:"html_url"`
- User struct {
- Login string `json:"login"`
- } `json:"user"`
- Head struct {
- Ref string `json:"ref"`
- } `json:"head"`
- Base struct {
- Ref string `json:"ref"`
- } `json:"base"`
- CreatedAt string `json:"created_at"`
- UpdatedAt string `json:"updated_at"`
- }
+ var items []githubPullItem
if json.Unmarshal(raw, &items) != nil {
return "", fmt.Errorf("GitHub 返回的 PR 列表无法解析")
}
@@ -561,7 +568,7 @@ func githubPullsList(ctx context.Context, token, path string, args map[string]an
hasMore = true
break
}
- out = append(out, githubPullOut{Number: it.Number, Title: it.Title, State: it.State, Draft: it.Draft, URL: it.HTMLURL, Author: it.User.Login, Head: it.Head.Ref, Base: it.Base.Ref, Created: it.CreatedAt, Updated: it.UpdatedAt})
+ out = append(out, it.out())
}
if hasMore || len(items) < perPage {
break
diff --git a/internal/httpapi/agent_tool_github_pull_item_test.go b/internal/httpapi/agent_tool_github_pull_item_test.go
new file mode 100644
index 00000000..9d2630de
--- /dev/null
+++ b/internal/httpapi/agent_tool_github_pull_item_test.go
@@ -0,0 +1,18 @@
+package httpapi
+
+import (
+ "encoding/json"
+ "testing"
+)
+
+func TestGitHubPullItemOut(t *testing.T) {
+ var it githubPullItem
+ raw := `{"number":7,"title":"Feature","state":"open","draft":true,"html_url":"https://github.com/octo/app/pull/7","user":{"login":"bob"},"head":{"ref":"topic"},"base":{"ref":"main"},"created_at":"2026-01-01T00:00:00Z","updated_at":"2026-01-02T00:00:00Z"}`
+ if err := json.Unmarshal([]byte(raw), &it); err != nil {
+ t.Fatal(err)
+ }
+ want := githubPullOut{Number: 7, Title: "Feature", State: "open", Draft: true, URL: "https://github.com/octo/app/pull/7", Author: "bob", Head: "topic", Base: "main", Created: "2026-01-01T00:00:00Z", Updated: "2026-01-02T00:00:00Z"}
+ if got := it.out(); got != want {
+ t.Fatalf("out() = %+v, want %+v", got, want)
+ }
+}