NOTE: This chatbot essentially mimics PullPanda's Pull Reminders which has now been aqcuired by GitHub. I assume at some point, Pull Reminder's functionality will be implemented natively into the GitHub slack application, but at the time of writing, PullPanda has disabled new signups, and functionality for pull reminders and requests does not exist in the existing slack app.
This chatbot will enable you to receive comment/body mentions of your GitHub username, PR review requests, and reminders for potentially forgotten review requests in your Slack DMs.
The current feature set includes the following:
- Subscribing and unsubscribing to mentions of your GitHub username.
- Enabling and disabling individual events that you may not want slack notifications for.
- Black-listing repositories that you never want notifications about (useful for those who work a lot in the Open Source repos).
- Setting the time at which you want your PR reminders to notify you.
This chatbot lives entirely in AWS utilizing serverless services such as API Gateway, Lambda Functions, and DynamoDB and utilizes the Serverless Framework for deployments.
Issuing /github-notify
in slack without any arguments will present you with a help dialog on how to use or configure the chatbot.
Along with the python requirements listed in requirements.txt, the following npm packages are required as well:
- serverless-python-requirements
- serverless-domain-manager <- optional, if you want to configure a custom api gateway DNS record.
These packages assume that you are configuring webhooks for a GitHub organization, but the mentions portion will work for organizations or individual repositories. The reminders functionality expects to search through an organization and it's repositories.
From an organization or repository's home page, navigate to:
- Settings -> Webhooks -> Add webhook
- Payload URL: The URL and path of your API gateway endpoint. Example: https://lfe20212ya.execute-api.us-west-2.amazonaws.com/prod/github-webhook/mentions.
- Content Type: application/json
- Secret: Enter a random string of characters. The string of characters must also be placed in the serverless.yml file for the
GITHUB_SECRET
environment variable. - "Let me select individual events" radio button. Select the events "Issue comments", "Issues", "Pull Requests", "Pull request reviews", and "Pull request review comments"
- Create webhook
In order to get reminders for PRs, the lambda function must be able to query the GitHub API. To do this, you must enter a GitHub username and password (or Personal Access Token) for a user that can query the desired repositories.
Without this configuration, the reminders function will probably not work.
From your Slack Workspace's settings, create a new App. This app will use both the "Bots" feature, and the "Slash Commands" feature.
Once you've created your slack App and installed it into your workspace, take note of the "Signing Secret" and the "Bot User OAuth Access Token" (under the OAuth & Permissions settings), you will need to place these into your serverless.yml environment variable configuration.
The slash command "Request URL" is the same end point as the GitHub webhook endpoint.
This table describes the envrionment variables that are used by these lambda functions and their helpers.
Env Var | Description | Notes |
---|---|---|
SLACK_BOT_TOKEN | Used to send notifications to slack users | |
SLACK_APP_SIGNING_SECRET | Used to verify incoming slack webhooks | |
GITHUB_SECRET | Used to verify incoming github webhooks | |
GH_USERNAME | Used to query the GitHub API | |
GH_PAT | Used to query the GitHub API | |
GH_ORG | Used to obtain repositories to check for PR reminders | |
DYNAMODB_TABLE | DynamoDB Connection string | Automatically generated by serverless.yml at run time |
The truth is, this project is not terribly complex and could be modified to easily support different backends. You could easily put a flask pr django front-end in front of the route_request.py function.
As for replacing the DynamoDB backend, you could modify the functions in user_management.py to support any number of database backends.