Programmatically Remind Your Teammates on Slack to Review GitHub PRs
In this article, we'll use GitHub, Slack, and Reshuffle to create a workflow that directly messages the reviewers on a pull request.
Join the DZone community and get the full member experience.Join For Free
The GitHub integration for Slack is great for team productivity. Having the ability to give Slack channels full visibility into GitHub projects, for real-time notifications, is an amazing way to keep the development team on the same page. However, this can become a double-edged sword. Developers may decide to ignore these messages because it may be information overload.
I’ve been in a similar situation where pull requests needed approval from reviewers but they wouldn’t check the channels or their emails. The only thing that got their attention were direct messages. This hindered delivery and having to ping the reviewer myself was becoming a pain.
As great as the GitHub app for Slack is, I wanted something more custom that would suit my needs. For example, whenever a pull request is made with reviewers, it should only send direct messages to those who have been requested.
In this article, we will use GitHub, Slack, and Reshuffle to create a workflow to directly message the reviewers on a pull request.
Before getting started with the code, we'll need to get credentials set up with GitHub and Slack.
- Log in and generate a token here.
- Save the token somewhere, as you'll need it soon.
- Create a new Slack App here.
- Enter the App name and select the workspace.
- Click on
- Click on your new App.
- The signing secret is under
- The token is under
OAuth Access Token
- Save the token and signing secret somewhere, as you'll need it soon.
See the below links for full documentation:
With the credentials saved somewhere safe, we can begin by instantiating a Reshuffle app and configuring the connectors.
Note: The GitHub Connector requires a
runTimeBaseUrl. A tool like ngrok can be used to generate a URL that exposes your localhost over SSL.
Reshuffle Connectors provide events and actions that allow developers to easily build custom workflows and integrations. We’re now able to take advantage of what they can do.
We’ll continue by getting a list of the user’s GitHub handles and their Slack IDs. In order to get this data, we use a method on Slack Connector that exposes Slack's web client actions.
Note: In this example,
display_name is assumed to be the same as the GitHub handle. You can definitely add your own profile fields that suit your team.
Next, we’ll write a helper function to handle the event when a pull request is created. This will take in a list of reviewers from GitHub, the user list from Slack, and the link URL to the pull request. If there are no reviewers, we’ll simply post to the general channel, otherwise, we match the reviewers to the Slack members list and send them a direct message.
To tie everything together, we configure the GitHub Connector to trigger an event anytime a pull request is created.
Note: See the full list of available events here.
We can get the list of requested reviewers from the event object, passing onto our helper, which is only called if the event action matches “opened” or “reopened”.
Note: For more information on the parameters of
postMessage check the docs.
With that, we’re finished. Any time a pull request is created with reviewers, they are directly messaged.
As a bonus, if the reviewers forget about the pull request, we can use the Cron Connector as a scheduler to check for any open PRs on the repository and message the reviewers.
This example provides a good starting point so you can easily create a custom workflow for your team's needs using Reshuffle.
As your developers and project management teams experience the ease of working with integrated applications, we encourage you to consider where else integrating workflows would benefit your teams. With so many different tools, the more you can consolidate them into one common interface, the easier people can get work done.
Reshuffle is continually listening to what our customers need and desire. Don’t see a Connector to a service you’d like to integrate? Send a tweet to @ReshuffleHQ to let us know which Connector you’d like us to develop next.
Published at DZone with permission of Alan Lee. See the original article here.
Opinions expressed by DZone contributors are their own.