pull_requests_to_slack icon indicating copy to clipboard operation
pull_requests_to_slack copied to clipboard

Send Github pull request notifications to Slack

Rootstrap Pull request to Slack

Build Status Maintainability Test Coverage

Send Github pull request notifications to Slack.

  • Each time a PR is created in your organization it will send a message to a specific Slack channel with a link to the PR and its technology emoji assigned.

  • When the PR is merged it will add a merged reaction emoji. Screen Shot 2019-08-02 at 11 06 30 AM

  • You can add \slack `This is a small pr @slack_user` at the end of the PR's description to add a message to the notification and to notify specific Slack users. Screen Shot 2019-08-02 at 11 11 30 AM

Make sure to use ` ` in the message in case the Slack user name is the same as someone's GitHub name, so the github user is not notified. Screen Shot 2019-08-02 at 11 54 58 AM

  • It will not send a notification if the PR is a draft.
  • It will remove the notification if the PR has an ON HOLD label and resend the notification when the label is removed.

Installation

  1. Clone this repo
  2. Install PostgreSQL in case you don't have it
  3. Create your database.yml and application.yml files. There are sample files in /config
  4. bundle install
  5. Generate a secret key with rake secret and paste this value into the application.yml.
  6. Fill the SLACK_API_TOKEN and SLACK_BOT_TOKEN in application.yml. To get the credentials: log in to https://api.slack.com/apps, select your application and then click OAuth Tokens & Redirect URLs. SLACK_API_TOKEN is the OAuth Access Token and SLACK_BOT_TOKEN is Bot User OAuth Access Token
  7. rails db:create
  8. rails db:migrate
  9. rails db:seed # this will create an admin with [email protected]:password
  10. npm install -g ngrok Install Ngrok
  11. rspec and make sure all tests pass
  12. rails s
  13. You are ready!

How to test the webhook locally?

  • Create a dummy repository in github with a couple branches.
  • Run server: rails s -p 3001
  • In another terminal run ngrok: ngrok http 3001
  • Copy ngrok url to github configuration page (settings->webhooks) http://xxxxxxx.ngrok.io/api/v1/notifications_filter
  • Change CHANNEL in SlackNotificationService to your @name or #some_test_channel
  • Create/edit pull request adding or removing labels. This will execute the webhook.

ActiveAdmin page

You can access the admin page at http://localhost:3001/admin/users and add users that you want to ignore

Deploy to Heroku

Install heroku cli https://devcenter.heroku.com/articles/heroku-cli#download-and-install

  • Setup:
heroku login
enter credentials
heroku git:remote -a rootstrap-pull-request-to-slack
  • Push:
git push heroku master

Docs

Ngrok

Public URLs for exposing your local web server https://ngrok.com/

Github Hooks

Info about github hooks and Pull request payload

https://developer.github.com/webhooks/configuring/ https://developer.github.com/v3/activity/events/types/#pullrequestevent

Slack methods

https://api.slack.com/methods

Contributing

Bug reports (please use Issues) and pull requests are welcome on GitHub at https://github.com/rootstrap/pull_requests_to_slack/issues. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The library is available as open source under the terms of the MIT License.

Credits

Github for Slack is maintained by Rootstrap with the help of our contributors.