package monorobot

  1. Overview
  2. Docs
Notification bot for monorepos

Install

Dune Dependency

Authors

Maintainers

Sources

0.1.tar.gz
md5=db7f01d60ca034702787efd0b760a8ad
sha512=9e33bea9aaadff777552d92971c725bf41280102832c29f5501b18f80fa33fa29ed9c0224796b10cc13bcea253b21cc121f76e66bcb349993acf7819b915634b

Description

Notification bot to handle webhook events from monorepos and post notifications to Slack.

Published: 09 Dec 2021

README

Monorobot

A Slackbot for GitHub monorepos. Configure how repo notifications should be routed to specified Slack channels based on file prefixes, issue/PR labels, and CI build statuses.

Setting Up

Install via OPAM:

opam install monorobot

Or install dependencies and build locally:

opam install --deps-only .
make

Running

Run the _build/default/src/monorobot.exe binary. The following commands are supported.

  • run: Launch the HTTP server

  • check_gh <GH_PAYLOAD>: read a Github notification from a file and display the actions that will be taken (used for testing)

  • check_slack <SLACK_PAYLOAD>: read a Slack notification from a file and send it to a channel (used for testing)

Getting Started

  1. Commit a repository configuration file to the root of your target repository.

  2. Place a secrets file locally on the server.

  3. Configure GitHub

    1. If targeting a private repository, set up a personal access token with repo scope and store it in the gh_token field of the secrets file.

    2. Create a webhook for the repository you are targeting. Set the Payload URL to be <server_domain>/github.

    3. You can optionally secure the webhook with a token, and store it in the gh_hook_token field of the secrets file.

  4. Configure Slack

    1. Create a Slack app.

    2. Click "Install to Workspace", and when prompted to grant permissions to your workspace, click "Allow".

    3. Set up notifications with one of the following methods:

      • Web API (recommended): To use Slack's Web API, click on "OAuth & Permissions" in your app dashboard's sidebar. Give your bot a Bot Token Scope of chat:write (for per-channel authorization) or chat:write.public (for authorization to all channels). Copy the generated bot token (xoxb-XXXX) to the slack_access_token field of your secrets file. This token is used by the bot to authenticate to the workspace, and remains valid until the token is revoked or the app is uninstalled. If you use the chat:write scope, add the bot to each channel you want to notify.

      • Incoming Webhooks: To use incoming webhooks, enable them in your app dashboard and create one for each channel you want to notify. Store them in the slack_hooks field of your secrets file. If you decide to notify additional channels later, you will need to update the secrets file with the new webhooks and restart the server.

Link Unfurling

You can configure Monorobot to unfurl GitHub links in Slack messages. Currently, commit, pull request, and issue links are supported.

Note: The slack_access_token must be configured in your secrets file for link unfurling. See previous section for details.

  1. Give your app links:read and links:write permissions.

  2. Configure your app to support the Events API. During the url verification handshake, you should tell Slack to direct event notifications to <server_domain>/slack/events. Ensure the server is running before triggering the handshake.

  3. Register the GitHub domains you want to support.

Documentation

The bot expects two configuration files to be present.

Testing (development)

curl -X POST \
  http://localhost:8080/github \
  -H 'Content-Type: application/json' \
  -H 'User-Agent: {whatever user agent you define}' \
  -H 'X-Github-Event: pull_request' \
  -H 'X-Hub-Signature: {a signature value you define}' \
  -H 'cache-control: no-cache' \
  -d @mock_payloads/pr_notification.json

There are more payloads which will use a different X-Github-Event signature:

pull_request => mock_payloads/pr_notification.json
push => mock_payloads/push_notification.json
check_suite => mock_payloads/ci_notification.json

Dependencies (21)

  1. yojson
  2. omd <= "1.3.1"
  3. uri
  4. stdio
  5. re2
  6. nocrypto
  7. lwt_ppx >= "2.0.0"
  8. lwt >= "5.1.0"
  9. hex
  10. extlib >= "1.7.8"
  11. devkit >= "1.20210120"
  12. cstruct
  13. cmdliner >= "0.9.8"
  14. biniou
  15. base64 >= "3.0.0"
  16. base >= "v0.13.0"
  17. atdgen-runtime >= "2.2.1"
  18. atdgen >= "2.2.1"
  19. atd >= "2.2.1"
  20. dune >= "2.5.0"
  21. ocaml >= "4.08.0"

Dev Dependencies

None

Used by

None

Conflicts

None