Closed
feat(actions): 支持 获取仓库所有的流水线的运行记录 API #445
aflyingtoAdd on  Jul 9Closed at  Jul 9
aflyingtoCollaborators
Jul 9 Create

背景

GitCode API 文档 2.0.0 已提供 Actions API。该 Issue 用于跟踪 gitcode-cli 对此接口的支持设计与实现。

API 摘要

  • 标题: 获取仓库所有的流水线的运行记录
  • Method: GET
  • Path: /api/v8/repos/{owner}/{repo}/actions/runs
  • Operation ID: get_api_v8_repos_{owner}_{repo}_actions_runs
  • Tags: pipeline-v8
  • Deprecated: false
  • Description: 无

Request Parameters

Name In Required Type Description
owner path yes string 仓库所属空间地址(组织或个人的地址path)
repo path yes string 仓库路径(path)
access_token query no string 用户授权码
event query no string 触发事件类型,MR(mr事件),Push(推送事件),Manual(手动触发)
status query no string 运行状态,COMPLETED(已完成),RUNNING(运行中),FAILED(失败),CANCELED(取消),IGNORED(忽略),PAUSED(暂停),SUSPEND(挂起)
branch query no string 分支过滤
executor query no string 触发人用户名
pull_request_id query no string PR的编号
workflow_id query no string 流水线id
workflow_name query no string 流水线名称
per_page query no string 每页的数量,最大为 100,默认 20
page query no string 当前的页码:默认为 1
startTime query no number 开始时间,格式时间戳
endTime query no number 结束时间,格式时间戳

Request Body

无。

Responses

200

  • Description: (empty)
  • Headers: 无
  • Content-Types: application/json

application/json schema

{
  "type": "object",
  "properties": {
    "total_count": {
      "type": "integer",
      "description": "总数量"
    },
    "workflow_runs": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "workflow_run_id": {
            "type": "string",
            "description": "流水线运行id"
          },
          "workflow_id": {
            "type": "string",
            "description": "流水线id"
          },
          "workflow_name": {
            "type": "string"
          },
          "file_path": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "description": "运行状态,COMPLETED(已完成),RUNNING(运行中),FAILED(失败),CANCELED(取消),IGNORED(忽略),PAUSED(暂停),SUSPEND(挂起)"
          },
          "event": {
            "type": "string",
            "description": "触发事件类型,MR(mr事件),Push(推送事件),Manual(手动触发)"
          },
          "run_number": {
            "type": "integer"
          },
          "head_branch": {
            "type": "string"
          },
          "head_sha": {
            "type": "string"
          },
          "actor": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "object_id": {
                "type": "string"
              },
              "login": {
                "type": "string"
              },
              "name": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "object_id",
              "login",
              "name"
            ],
            "description": "触发人"
          },
          "start_time": {
            "type": "integer",
            "description": "开始时间戳"
          },
          "end_time": {
            "type": "integer",
            "description": "结束时间戳"
          },
          "pause_time": {
            "type": "integer",
            "description": "暂停时间"
          }
        },
        "required": [
          "workflow_run_id",
          "workflow_id",
          "workflow_name",
          "file_path",
          "title",
          "status",
          "event",
          "run_number",
          "head_branch",
          "head_sha",
          "actor",
          "start_time",
          "end_time",
          "pause_time"
        ]
      },
      "description": "流水线运行记录"
    }
  },
  "required": [
    "total_count",
    "workflow_runs"
  ]
}

原始 OpenAPI Operation

{
  "deprecated": false,
  "description": "",
  "operationId": "get_api_v8_repos_{owner}_{repo}_actions_runs",
  "tags": [
    "pipeline-v8"
  ],
  "parameters": [
    {
      "name": "owner",
      "in": "path",
      "description": "仓库所属空间地址(组织或个人的地址path)",
      "required": true,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "repo",
      "in": "path",
      "description": "仓库路径(path)",
      "required": true,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "access_token",
      "in": "query",
      "description": "用户授权码",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "event",
      "in": "query",
      "description": "触发事件类型,MR(mr事件),Push(推送事件),Manual(手动触发)",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "status",
      "in": "query",
      "description": "运行状态,COMPLETED(已完成),RUNNING(运行中),FAILED(失败),CANCELED(取消),IGNORED(忽略),PAUSED(暂停),SUSPEND(挂起)",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "branch",
      "in": "query",
      "description": "分支过滤",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "executor",
      "in": "query",
      "description": "触发人用户名",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "pull_request_id",
      "in": "query",
      "description": "PR的编号",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "workflow_id",
      "in": "query",
      "description": "流水线id",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "workflow_name",
      "in": "query",
      "description": "流水线名称",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "per_page",
      "in": "query",
      "description": "每页的数量,最大为 100,默认 20",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "page",
      "in": "query",
      "description": "当前的页码:默认为 1",
      "required": false,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "startTime",
      "in": "query",
      "description": "开始时间,格式时间戳",
      "required": false,
      "schema": {
        "type": "number"
      }
    },
    {
      "name": "endTime",
      "in": "query",
      "description": "结束时间,格式时间戳",
      "required": false,
      "schema": {
        "type": "number"
      }
    }
  ],
  "responses": {
    "200": {
      "description": "",
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "total_count": {
                "type": "integer",
                "description": "总数量"
              },
              "workflow_runs": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "workflow_run_id": {
                      "type": "string",
                      "description": "流水线运行id"
                    },
                    "workflow_id": {
                      "type": "string",
                      "description": "流水线id"
                    },
                    "workflow_name": {
                      "type": "string"
                    },
                    "file_path": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string",
                      "description": "运行状态,COMPLETED(已完成),RUNNING(运行中),FAILED(失败),CANCELED(取消),IGNORED(忽略),PAUSED(暂停),SUSPEND(挂起)"
                    },
                    "event": {
                      "type": "string",
                      "description": "触发事件类型,MR(mr事件),Push(推送事件),Manual(手动触发)"
                    },
                    "run_number": {
                      "type": "integer"
                    },
                    "head_branch": {
                      "type": "string"
                    },
                    "head_sha": {
                      "type": "string"
                    },
                    "actor": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "object_id": {
                          "type": "string"
                        },
                        "login": {
                          "type": "string"
                        },
                        "name": {
                          "type": "string"
                        }
                      },
                      "required": [
                        "id",
                        "object_id",
                        "login",
                        "name"
                      ],
                      "description": "触发人"
                    },
                    "start_time": {
                      "type": "integer",
                      "description": "开始时间戳"
                    },
                    "end_time": {
                      "type": "integer",
                      "description": "结束时间戳"
                    },
                    "pause_time": {
                      "type": "integer",
                      "description": "暂停时间"
                    }
                  },
                  "required": [
                    "workflow_run_id",
                    "workflow_id",
                    "workflow_name",
                    "file_path",
                    "title",
                    "status",
                    "event",
                    "run_number",
                    "head_branch",
                    "head_sha",
                    "actor",
                    "start_time",
                    "end_time",
                    "pause_time"
                  ]
                },
                "description": "流水线运行记录"
              }
            },
            "required": [
              "total_count",
              "workflow_runs"
            ]
          }
        }
      },
      "headers": {}
    }
  },
  "security": [],
  "method": "get",
  "path": "/api/v8/repos/{owner}/{repo}/actions/runs",
  "servers": [
    {
      "url": "https://api.gitcode.com",
      "description": "正式环境"
    }
  ],
  "securitySchemes": {},
  "info": {
    "title": "GicodeOpenAPI",
    "description": "",
    "version": "1.0.0"
  },
  "postman": {
    "name": "获取仓库所有的流水线的运行记录",
    "description": {
      "content": "",
      "type": "text/plain"
    },
    "url": {
      "path": [
        "api",
        "v8",
        "repos",
        ":owner",
        ":repo",
        "actions",
        "runs"
      ],
      "host": [
        "{{baseUrl}}"
      ],
      "query": [
        {
          "disabled": false,
          "description": {
            "content": "用户授权码",
            "type": "text/plain"
          },
          "key": "access_token",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "触发事件类型,MR(mr事件),Push(推送事件),Manual(手动触发)",
            "type": "text/plain"
          },
          "key": "event",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "运行状态,COMPLETED(已完成),RUNNING(运行中),FAILED(失败),CANCELED(取消),IGNORED(忽略),PAUSED(暂停),SUSPEND(挂起)",
            "type": "text/plain"
          },
          "key": "status",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "分支过滤",
            "type": "text/plain"
          },
          "key": "branch",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "触发人用户名",
            "type": "text/plain"
          },
          "key": "executor",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "PR的编号",
            "type": "text/plain"
          },
          "key": "pull_request_id",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "流水线id",
            "type": "text/plain"
          },
          "key": "workflow_id",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "流水线名称",
            "type": "text/plain"
          },
          "key": "workflow_name",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "每页的数量,最大为 100,默认 20",
            "type": "text/plain"
          },
          "key": "per_page",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "当前的页码:默认为 1",
            "type": "text/plain"
          },
          "key": "page",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "开始时间,格式时间戳",
            "type": "text/plain"
          },
          "key": "startTime",
          "value": ""
        },
        {
          "disabled": false,
          "description": {
            "content": "结束时间,格式时间戳",
            "type": "text/plain"
          },
          "key": "endTime",
          "value": ""
        }
      ],
      "variable": [
        {
          "disabled": false,
          "description": {
            "content": "(Required) 仓库所属空间地址(组织或个人的地址path)",
            "type": "text/plain"
          },
          "type": "any",
          "value": "",
          "key": "owner"
        },
        {
          "disabled": false,
          "description": {
            "content": "(Required) 仓库路径(path)",
            "type": "text/plain"
          },
          "type": "any",
          "value": "",
          "key": "repo"
        }
      ]
    },
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "method": "GET"
  }
}

初步验收建议

  • 增加对应 API client/query 方法,保留 v8 路径。
  • 设计 agent-friendly 的 CLI 命令、帮助文本、JSON 输出和错误处理。
  • 单元测试覆盖参数映射、响应解析和错误路径。
  • 如做真实命令验证,只能使用 infra-test/* 仓库。
  • 不暴露或打印 token;文档中的 access_token 仅作为 API 参数记录,CLI 优先复用现有认证机制。
likedislike
AaflyingtoCollaborators
Jul 9 Added label: risk/mediumscope/api, status/triage,type/feature
AaflyingtoCollaborators
Jul 9 Associated milestone: Actions M1: 流水线与 Workflow Jobs 检视
AaflyingtoCollaborators
Jul 9 Added label: featurescope/actions
AaflyingtoCollaborators
Jul 9 Removed label: feature
aflyingtoCollaborators
Jul 9 Comments:

验证记录

  • 当前版本: main @ d0ff6b3 (gc 0.7.0)
  • 需求确认: GitCode API v8 提供 GET /api/v8/repos/{owner}/{repo}/actions/runs(流水线运行记录列表),OpenAPI 文档已抓取于本 issue body
  • gc 现状:
    • pkg/cmd/ 下无 actions 命令
    • api/ 无 actions / pipeline / workflow runs 查询函数
    • docs/COMMANDS.md 无 actions 段
    • api/client.go REST 硬编码 /api/v5,Actions API 在 /api/v8,需用 RawREST(rawURL 对 /api/ 前缀端点原样保留版本号)走 v8 路径
  • 重复检查: 无 merged PR,origin/main 无对应代码,verify-remote-facts passed
  • 结论: 需求有效且未实现,进入开发

实现计划

  • API 层: api/queries_actions.go — WorkflowRun/WorkflowRunsResponse/ActionsListRunsOptions 类型 + ListActionsRuns 函数(用 RawREST 走 v8,query params 经 url.Values)
  • 命令层: pkg/cmd/actions/actions.go(actions 父命令)+ pkg/cmd/actions/run/run.go(run 父命令)+ pkg/cmd/actions/run/list/list.go(run list 叶子,#445)
  • 测试: api/queries_actions_test.go(roundtrip mock v8 端点)+ pkg/cmd/actions/run/list/list_test.go
  • 输出: 表格 + --json(agent-friendly,只读命令优先支持 JSON)
likedislike
AaflyingtoCollaborators
Jul 9 Removed label: status/triage
AaflyingtoCollaborators
Jul 9 Added label: status/in-progress, status/verified
AaflyingtoCollaborators
Jul 9 Associated pull request
AaflyingtoCollaborators
Jul 9 Close issue
AaflyingtoCollaborators
Jul 9 Removed label: status/in-progress
AaflyingtoCollaborators
Jul 9 Removed label: status/verified
AaflyingtoCollaborators
Jul 9 Added label: status/merged
AaflyingtoCollaborators
Jul 10 Associated pull request
AaflyingtoCollaborators
Jul 10 Associated pull request
AaflyingtoCollaborators
Jul 10 Associated pull request