Receive Pull Requests notifications from Bitbucket and send them to Slack.
As for 2014-09-26 we support all BitBucket's action types:
See Bitbucket's official docs: Pull Request POST hook management
Bitbucket does not provide all necessary data in actions responses. For example, for a
comment_* action we don't have the PR number, link nor name.
So all we can do is something like "Comment posted for a PR" and then the snippet of the comment. But currently there's no way to know where did this comment came from.
- Bitbucket repository with admin rights
- Slack Incoming Webhook Url: Get your Slack token from your "integrations" page
- Node.js OR Docker
If you want to automatically notify the PR reviewers, you can set to
true the environment variable
It will assume that the Bitbucket username will be the same in Slack. If not, the user could add a "highlight word" in their preferences for their username used in Bitbucket.
The configuration variables are set with environment variables and/or using
.env file (environment variable takes preference over
.env file if found).
|SLACK_WEBHOOK||Y||The incoming hook url found on your Slack team's integration page||https://hooks.slack.com/services/XX/XXX/XXXX|
|SLACK_USERNAME||N||Username of the Slack bot. If not set, bot will default to integration settings.||BitbucketNotification|
|SLACK_CHANNEL||N||Channel to post notifications on. If not set, bot will default to integration settings.||RepositoryUpdate|
|MENTION_REVIEWERS||N||Set to true if you want to mention reviewers in slack channel||false|
|HEX_INFO||N||Hex color of updated, and created||#3498db|
|HEX_DANGER||N||Hex color of declined||#e74c3c|
|HEX_WARNING||N||Hex color of unapprove, comment: created, comment: deleted, and comment: updated||#f1c40f|
|HEX_SUCCESS||N||Hex color of merge, and approve||#2ecc71|
If you want to use
.env file, copy the
.env and modify it as needed.
Your configuration would look like the example below:
PORT=5000 SLACK_WEBHOOK=https://hooks.slack.com/services/A123ka9/A123910a9d8/mkas929199sad83lmk7h SLACK_USERNAME=AwesomeBot SLACK_CHANNEL=Repository HEX_SUCCESS=#2ecc71 HEX_DANGER=#e74c3c
Note: Setting the
SLACK_CHANNEL will override the settings set on the incoming webhook integration page. If you want your team to edit any of these settings without redeploying, do not add them to your
Important: if you're going to use a
.env file AND using Docker, edit it before building the Dockerfile.
When running the service in Docker container, the config values can be provided as parameters:
# Starts Docker container in daemonized mode docker run -e PORT=5000 -e SLACK_TOKEN=123123 \ -e SLACK_DOMAIN=company -e SLACK_CHANNEL=channel \ -p 5000:5000 -d bitbucket-slack-pr-hook
Local Infrastructure or Cloud Services
- Set up a server address in your local infrastructure that will serve this application (eg:
- Clone/download this repo to your chosen server
- Configure your application according to the "Configuration" section above
- Install NodeJS if you don't have it
npm installin the app's root folder
Important note: make sure you don't have any firewall blocking the incoming TCP port (default is PORT 5000 as defined in the "Configuration" section above)
Service can also be installed & deployed using Docker containers,
which makes it easy to setup the environment without worrying about the requirements.
- Clone/download this repo
- Install Docker (using system packages in Linux, in Windows or Mac OS X you can use Boot2docker)
- Start Docker service (or
Build the Docker image:
Alternatively: npm run build-container
docker build -t bitbucket-slack-pr-hook .
Start container with appropriate
docker run -e PORT=5000 -e SLACK_WEBHOOK=webhookurl \
-p 5000:5000 -d bitbucket-slack-pr-hook
Ensure the container is running (you should also be able to access the service using web browser:
Note: In Linux the
localhost, with Boot2docker use the IP reported by the command:
Setting up the Bitbucket Repository
- In your main Bitbucket repository, go to Settings > Hooks and create a new
Pull Request POSThook
- Set up the URL as
<server>is your host FQDN or its IP address
<port>is either 5000 or any other you defined in the configuration section
<channel>is an optional Slack channel where you want to receive this specific notifications - if it's not defined here it will use the one you defined in Configuration -section.
Via plain node
node server.js) to fire up the application (you can do
node server.js &to run it as a daemon in your Linux box)
npm run build-containerto build the container
npm run start-containerto start the container and the server inside it
- When needed, you can use
npm run stop-containerand
npm run reload-container
This repo was inspired by: https://github.com/kfr2/bitbucket-pull-request-connector