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

问题描述 投票:0回答:2

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

/repos/{所有者}/{repo}/操作/工作流程

我的示例输出如下所示:

{
"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 文件

github github-actions github-api
2个回答
4
投票

给定文件名,使用 获取存储库内容 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
,其中包含该工作流程的编码内容。


0
投票

纯文本工作流 yaml 文件:

curl \
    -H "Accept: application/vnd.github.v3+json" \  
    https://raw.githubusercontent.com/octo-org/octo-repo/master/.github/workflows/blank.yaml
© www.soinside.com 2019 - 2024. All rights reserved.