cirruslabs / cirrus-ci-docs

Documentation for Cirrus CI 📚
https://cirrus-ci.org
MIT License
351 stars 109 forks source link

Repository hooks / custom event injection #1023

Open fkorotkov opened 2 years ago

fkorotkov commented 2 years ago

Description

819 introduced a very powerful mechanism to control things within a build. Let's build on top of it even more powerful mechanism like repository hooks.

The idea here is to create builds for a given repository based on arbitrary events.

Context

Here is a rough idea:

For example, we can automate re-triggering/re-creating of a build when a base branch for a PR is changed:

def on_github_event(ctx):
  pr_base_change_event = ctx.event == "pull_request" && ctx.payload.action == "edited" && ctx.payload.changes.base is not None
  if not pr_base_change_event:
    return
  # this will create a new build for the PR
  return {
    "status": "CREATED", # can be TRIGGERED but then should have non empty `tasks` field with the tasks.
    "branch": "pull/{}".format(payload.number),
    "changeIdInRepo": payload.head.sha, # optional, by default can be the latest of `branch`
    "message": "PR base was changed",
  }

Additionally we can allow injesting custom events. For example, posting to https://api.cirrus-ci.com/github/my-org/my-repo/events/SOURCE will trigger on_SOURCE_event function from .cirrus.star which can create a build.

fkorotkov commented 2 years ago

One thing we need to think as well how to generate per-repository tokens for the injestion.