How to determine which checks are required?

When querying the checks API (https://developer.github.com/v3/checks/runs/), it’s straightforward to determine the status of all checks, but how do I determine which are required checks? The GitHub UI displays which are required, so presumably the information is available somewhere, but I don’t see anything like a “required” property on the check run responses. Is there somewhere else I should be looking?

Thanks!

You can easily get this information in the GraphQL API with the following query:

{
  repository(owner: "lee-dohm", name: "atom-style-tweaks") {
    branchProtectionRules(first: 100) {
      nodes {
        pattern
        requiresStatusChecks
        requiredStatusCheckContexts
      }
    }
  }
}

which for one of my repositories returns:

{
  "data": {
    "repository": {
      "branchProtectionRules": {
        "nodes": [
          {
            "pattern": "master",
            "requiresStatusChecks": true,
            "requiredStatusCheckContexts": [
              "continuous-integration/travis-ci",
              "coverage/coveralls",
              "sourcelevel"
            ]
          }
        ]
      }
    }
  }
}

It looks like you can get similar information using the List required status checks contexts of protected branch endpoint in REST.

I hope that helps!