Skip to content

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

@rtsao

Description

@rtsao

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:

  • Adding/removing labels creates noise in the PR
  • Because checks apply to a specific commit, it avoids the current potential race conditions where a user pushes new commits right before a label is added
  • Having an explicit status check and associated action button is more intuitive than a convention regarding adding/removing labels

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions