如何使用 Github 操作 API 获取 Github 工作流 yaml 文件

How to fetch Github workflows yaml files using Github Actions API

我正在关注此文档: https://docs.github.com/en/rest/reference/actions#list-repository-workflows

/repos/{owner}/{repo}/actions/workflows

我的示例输出如下所示:

{
"total_count": 1,
"workflows": [
   {
     "id": 161335,
     "node_id": "MDg6V29ya2Zsb3cxNjEzMzU=",
     "name": "CI",
     "path": ".github/workflows/blank.yaml",
     "state": "active",
     "created_at": "2020-01-08T23:48:37.000-08:00",
     "updated_at": "2020-01-08T23:50:21.000-08:00",
     "url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/161335",
     "html_url": "https://github.com/octo-org/octo-repo/blob/master/.github/workflows/161335",
     "badge_url": "https://github.com/octo-org/octo-repo/workflows/CI/badge.svg"
   }
 ]
}

如何从此输出中获取工作流 yaml 文件

给定文件名,使用Get repository content API获取文件。

对于您的文件,应该是:

 curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/octo-org/octo-repo/contents/.github/workflows/blank.yaml

响应 JSON 将包含一个字段 content,其中包含该工作流的编码内容。