githubgithub-apistatustravis-ci-api

Getting the Travis CI build status of a GitHub commit


Question

How would one get the build status of Travis CI of a particular GitHub commit from the of any arbitrary open source project?

Example

For example, how would an arbitrary GitHub user (with a Travis account) query the passing/failed build status of this build based on the following information:

Attempts

To get the status of that commit I tried:

  1. A get command:
GET /repos/a-t-0/Code-LatexReportTemplate/commits/2758dc700dfaa9726f0e1755753347b4d450acda/status

Which returns nothing.

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

Which returns a lot of information, but an empty statuses information as shown in the selected output below:

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

  ],

This empty statuses information seems to be contradictory to the green checkflag on that commit, which shows the build on that commit is passed.


Solution

  • You can use the check-run api using Github API rest v3 like this

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

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

    and for check-suites :

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

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

    Using graphql API, you can use statusCheckRollup field :

    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
                  }
                }
              }
            }
          }
        }
      }
    }
    

    which 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"
                  }
                ]
              }
            }
          }
        }
      }
    }
    

    Checkout statuscheckrollupcontext and checkrun