Send GitHub pull requests to Slack messages
Overview
This workflow serves as a seamless bridge between GitHub and Slack, facilitating efficient communication and collaboration among development teams. Specifically, it automatically sends notifications to designated Slack channels whenever new pull requests are created in GitHub repositories.
By integrating these two platforms, teams can stay updated on the progress of code changes and foster timely discussions and reviews.
How the template works
-
GitHub webhook integration: Upon receiving a
created
orreopened
GitHub pull request event, it retrieves relevant details such as the title, author, and repository name to prepare for notification. -
Slack notification preparation: Using the retrieved pull request details, the workflow formats the information into a concise and informative message suitable for Slack. This ensures that the Slack notifications provide essential context and facilitate quick understanding and action by team members.
-
Slack message dispatch: Once the Slack notification is prepared, the workflow dispatches it to the designated Slack channel(s). Team members subscribed to these channels receive real-time updates on new pull requests, enabling them to stay informed and collaborate effectively.
How to use the template
Step 1: Create GitHub OAuth 2.0 credentials
-
Ensure you have set up GitHub OAuth 2.0 and have access to client ID and client secret.
-
Log in to the SimWorkflow.
-
Navigate to Credentials.
-
Click Create credentials button.
-
Select OAuth 2.0 tab.
-
Select GitHub from the Provider dropdown.
-
Enter GitHub in the Name field.
-
Enter the Client ID in the Client ID field.
-
Enter the Client secret in the Client secret field.
-
Enter repo to the Scopes field.
-
Click Create credentials button.
Step 2: Create Slack OAuth 2.0 credentials
-
Ensure you have set up Slack OAuth 2.0 and have access to client ID and client secret.
-
Navigate to Credentials.
-
Click Create credentials button.
-
Select OAuth 2.0 tab.
-
Select Slack from the Provider dropdown.
-
Enter Slack to the Name field.
-
Enter the Client ID in the Client ID field.
-
Enter the Client Secret in the Client secret field.
-
Enter chat:write to the Scopes field.
-
Click Create credentials button.
Step 3: Use this workflow template
-
Click Use this template button on the top right of this page.
-
Click Get pull request task and select Configuration tab.
-
Select GitHub (OAuth 2.0) for Credentials field.
-
Click Slack task and select Configuration tab.
-
Select Slack (OAuth 2.0) for Credentials field.
-
Click Save button.
-
Toggle the Enable checkbox to enable the workflow definition.
Step 4: Define variables
-
Navigate to Workflow definitions.
-
Click Variables menu item from the three dots (more options) menu of the Send GitHub pull requests to Slack messages workflow definition.
-
Enter githubWebhookSecret to the Variable key field.
-
Enter the GitHub webhook secret token to the Variable value field.
-
Click Save variable button.
-
Enter slackChannelId to the Variable key field.
-
Enter the Slack channel ID in the Variable value field.
-
Click Save variable button.
Step 5: Define Webhook settings
-
Navigate to Workflow definitions.
-
Click Webhook settings menu item from the three dots (more options) menu of the Send GitHub pull requests to Slack messages workflow definition.
-
Turn on Webhook on field.
-
Copy the Webhook endpoint URL, we'll paste it later.
-
Select a user for User to start the workflow as field.
-
Enter the following JavaScript in the Validate the payload field:
'sha256=' + Swf.hmacSha256Hex($['swf:variables'].githubWebhookSecret, $.body) === $.headers['x-hub-signature-256']
The system will use the workflow definition variable
githubWebhookSecret
to verify that a webhook delivery is from GitHub. -
Click Save webhook settings button.