Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composable behaviors: on…when…then #13

Merged
merged 16 commits into from
Oct 10, 2016
Merged

Conversation

bkeepers
Copy link
Contributor

@bkeepers bkeepers commented Oct 10, 2016

While experimenting with implementing some example behaviors, I've been seeing some common features and am starting to wonder if it would be better to compose behaviors of smaller components. I started experimenting with it and really like the direction it's going.

There are a lot of advantages this approach. These composed behaviors can be defined in a file in the repository, or in a organization/probot repository for organization hooks. The components can be combined in interesting ways, requiring fewer custom modules, so fewer people will have to stand up their own server to use the bot and can instead rely on a shared deployment.

This first pass looks for a .probot.yml config file in a repo with behaviors. Behaviors are composed of 3 parts:

  • on - webhook events to listen to
  • when - conditions to determine if the actions should be performed.
  • then - actions to take in response to the event

Here are some examples of what can be accomplished by combining these components:

behaviors:
  # Label and respond to new issues and pull requests
  - on:
      - issue.created
      - pull_request.created
    then:
      label: triage
      comment: "Thanks for your contribution! Expect a reply within 48 hours."
      assign: bkeepers

  # Auto-close new pull requests
  - on: pull_request.created
    then:
      comment: "Sorry @{{ user.login }}, pull requests are not accepted on this repository."
      close: true

  # Merge approved pull requests with passing status
  - on:
     - pull_request
     - status
    when:
     label: approved
     status:
       context: "travis-ci"
       state: "success"
    then:
      merge: true

  # Tweet whenever there is a new release
  - on: release.published
    then:
      tweet: "Get it while it's hot! {{ repository.name }} {{ release.tag_name }} was just released. {{ release.html_url }}"

Check out the aspirational docs on configuration to see some more ideas. Each of the conditions (when) and actions (then) could be provided by plugins.

  • read .probot.yml for repo event
  • on: hook
  • when: comment
  • on: hook.action
  • read .probot.yml from org/probot for org event
  • implement a few other actions
  • clean up docs to show what is and isn't implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant