【问题标题】:Github v4 GraphQL API - access Marketplace App results (Travis CI)Github v4 GraphQL API - 访问 Marketplace 应用结果 (Travis CI)
【发布时间】:2020-06-30 19:23:54
【问题描述】:

我们正在使用 Travis CI 为我们在 Github 上的一个存储库运行测试。
查看提交列表时,我们会看到绿色复选标记或红色叉号,表示我们的测试状态。

现在我正在试验 Github v4 GraphQL API。
我可以浏览 API(使用 GraphiQL 和 GraphiQL-explorer),但我无法在任何地方找到 Travis 测试的结果。

我可以使用 Github GraphQL API 来获取 Travis 结果吗?

【问题讨论】:

    标签: graphql automated-tests travis-ci github-api


    【解决方案1】:

    当请求最后一次提交或提交列表(带有history)时,您可以访问带有state propertystatus object

    {
      repository(owner: "bertrandmartel", name: "metec-braille-driver") {
        refs(first: 100, refPrefix: "refs/heads/") {
          nodes {
            target {
              ... on Commit {
                status {
                  state
                  contexts {
                    description
                    createdAt
                    state
                  }
                }
                history(first: 100) {
                  nodes {
                    message
                    status {
                      state
                      contexts {
                        description
                        createdAt
                        state
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    结果如下:

    ....
    "status": {
      "state": "FAILURE",
      "contexts": [
        {
          "description": "AppVeyor build failed",
          "createdAt": "2020-03-09T02:31:19Z",
          "state": "FAILURE"
        },
        {
          "description": "The Travis CI build passed",
          "createdAt": "2020-03-09T02:31:42Z",
          "state": "SUCCESS"
        }
      ]
    },
    ....
    

    同样来自v3 doc

    状态的状态。可以是错误、失败、未决或 成功

    【讨论】:

    • 我尝试使用相同的查询,但在我们的例子中,结果是status: null,即使 github 网页上有绿色复选标记,如图所示(我刚刚添加)。知道这是为什么吗?
    • @HendrikJan 也许您使用的令牌没有repo:status 范围?
    猜你喜欢
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 2018-08-25
    • 2020-01-12
    • 2018-08-21
    • 2023-03-08
    • 2015-03-28
    • 2018-03-14
    相关资源
    最近更新 更多