获取 GitHub 提交的 Travis CI 构建状态

Getting the Travis CI build status of a GitHub commit

问题

如何从任意开源项目中获取特定 GitHub 提交的 Travis CI 的构建状态?

例子

例如,任意 GitHub 用户(使用 Travis 帐户)如何根据以下信息查询 this build 的 passing/failed 构建状态:

尝试次数

为了获取该提交的状态,我尝试了:

  1. 获取命令:
GET /repos/a-t-0/Code-LatexReportTemplate/commits/2758dc700dfaa9726f0e1755753347b4d450acda/status

哪个returns什么都没有。

  1. 一个 curl 命令:
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/a-t-0/Code-LatexReportTemplate/commits/2758dc700dfaa9726f0e1755753347b4d450acda/status

其中returns很多信息,但是一个empty statuses信息如下图所示:

 "state": "pending",
  "statuses": [

  ],

此空状态信息似乎与 the green checkflag on that commit, which shows the build on that commit is passed 相矛盾。

您可以像这样使用 check-run api 使用 Github API rest v3

GET https://api.github.com/repos/[owner]/[repo]/commits/[hash]/check-runs

示例:https://api.github.com/repos/a-t-0/Code-LatexReportTemplate/commits/2758dc700dfaa9726f0e1755753347b4d450acda/check-runs

对于check-suites

GET https://api.github.com/repos/[owner]/[repo]/commits/[hash]/check-suites

示例:https://api.github.com/repos/a-t-0/Code-LatexReportTemplate/commits/2758dc700dfaa9726f0e1755753347b4d450acda/check-suites

使用graphql API,可以使用statusCheckRollup字段:

query {
  repository(name: "Code-LatexReportTemplate", owner:"a-t-0"){
    object(oid: "2758dc700dfaa9726f0e1755753347b4d450acda") {
      ... on Commit {
        message
        statusCheckRollup {
          state
          contexts(first: 100) {
            nodes {
              __typename
              ... on CheckRun {
                name
                detailsUrl
                completedAt
                status
              }
            }
          }
        }
      }
    }
  }
}

其中 returns :

{
  "data": {
    "repository": {
      "object": {
        "message": "Removed another unneeded file.",
        "statusCheckRollup": {
          "state": "SUCCESS",
          "contexts": {
            "nodes": [
              {
                "__typename": "CheckRun",
                "name": "Travis CI - Branch",
                "detailsUrl": "https://travis-ci.com/github/a-t-0/Code-LatexReportTemplate/builds/211162054",
                "completedAt": "2020-12-29T13:12:26Z",
                "status": "COMPLETED"
              }
            ]
          }
        }
      }
    }
  }
}

结帐statuscheckrollupcontext and checkrun