Get notified on new pull request in your teams slack channel. This can be very useful if there are multiple repositories across a wide team.
This post details on how to get github pull request notifications on slack channel
AWS account, Slack Channel, Github
We need a slack webhook to post our events. Follow the below document and note down the webhook url
Test the webhook using the command in that document to validate.
We will be using lambda to process the pull request event and send notification to slack.
have posted the starter code in the below github repository
clone / download the repo github.com/uptownaravi/pullRequestSlack
Then install the requirements.txt
pip install --target="give-the-current-directory-path" -r requirements.txt
after that, this should be the folder structure. Then Zip these files.
Then navigate to lambda console in aws.
create function --> author from scratch --> give it a name and runtime as Python 3.7
once created select actions --> upload a .zip file --> select the zip package we created earlier
lambda should be updated as below
scroll down to the environment variables section
add key as slackNotification and value as the slack webhook URL we created in step 1.
make sure that key is slackNotification as this will be used by lambda code.
Then navigate to API gateway and create API
select the HTTP method and click on build
choose add integration and select the lambda we created earlier
then move on to next, select method as POST and resource path as /pull.
next give stage name as dev and let auto deploy be enabled.
once created, note down the api url
select CORS in the left section and configure it to have POST and GET in the Access-Control-Allow-Methods section
We need github to send the pull request events to aws lambda through api gateway.
Navigate to your repository in github for which you need to get pull request notifications.
Go to settings in that repository
add the url in the payload url which we got from api gateway as below example
note: use the api gateway url from step 2 and make sure to add /pull to the end of that url. The above one is an example.
We need to keep the events to pull request to trigger the webhook.
choose let me select individual events and scroll down
and select pull request and un-check the Pushes --> Add webhook
That's it once you create a pull request in that repository, there will be a notification on the slack channel
if required modify the lambda code to handle different type of pull request events.
This is my first post in dev.to, looking forward to your comments.