mvines / ci-gate

Buildkite ergonomics for Github pull requests
https://ci-gate.herokuapp.com/
The Unlicense
12 stars 10 forks source link

Use GitHub checks API rather than labels to trigger CI #84

Open rtsao opened 5 years ago

rtsao commented 5 years ago

With the GitHub Checks API, it is possible to add a neutral/failing commit status that includes a button to trigger an arbitrary action.

For example, this might look something like:

screen shot 2019-01-30 at 10 54 44 am

Clicking "details" will take you to the checks tab of the PR, which might show something like:

screen shot 2019-01-30 at 10 55 58 am

Clicking the button will trigger a check_run.requested_action event. Then this app can respond to the action_requested webhook and trigger a CI run.

I think this is preferable than the label-based approach for a few reasons:

If this app used probot, the code might look something like this:

context.github.checks.create(
  context.repo({
    name: "CI Gate",
    head_branch,
    head_sha,
    status: "completed",
    conclusion: "action_required",
    completed_at: new Date(),
    output: {
      title: "CI run not yet authorized",
      summary:
        "Click the above <kbd>Trigger CI run</kbd> button to trigger a CI run."
    },
    actions: [
      {
        label: "Trigger CI run",
        description: "Trigger a CI run",
        identifier: "trigger_ci"
      }
    ]
  })
);

If that sounds good to you, I could probably help implement this.

mvines commented 5 years ago

Yeah this sounds amazing. Moving to the checks API has been on my wishlist for a while, I just haven’t made the time to do it.