Home
Examples
Forum
Docs
Home
Examples
Forum
Docs
Examples

Announce in Slack when your GitHub PRs get merged

On a fast-moving dev team, it’s sometimes a challenge keeping up with what’s new! We had this problem, so we built a widget that posts in a Slack channel each time we merge a PR. It uses GitHub webhooks to know when a PR gets merged, and the Slack postMessage API to post the message.

Here’s the code:

And here’s the result:

Setting this up for yourself

To set this up for yourself, you’ll need to create a GitHub webhook pointing at your widget, and a Slack app with the chat:write.public scope.

1. Create a Slack app

Follow the first few steps of the Slack API Quickstart: Create a new app from scratch, and request the chat:write.public scope so it can post in any public channel. Then install it on your workspace.

Next, you’ll need to copy your Slack bot token and use it to fill out the slack_token secret in your widget’s secrets.

Finally, you’ll need to get the Channel ID for the channel you want your bot to post in. You can get this by right-clicking the channel in Slack and choosing View Channel Details. Then update the CHANNEL_ID constant in your widget code.

2. Set up the GitHub webhook

Go to the Settings of your GitHub repository, then choose Webhooks, then create a new webhook. You’ll need to paste the URL of your HTTP route, select JSON delivery, and choose Send me everything to be notified when PRs are merged:

Tip: Once your webhook is created, go back and Edit it – you’ll now see a really useful tab of Recent Deliveries. This is great for debugging – it lets you see what happened when GitHub sent an event to you, and even redeliver events to test them again!

That’s it!

Try merging a PR in GitHub, and watch your app post!

If you’re having trouble and need to debug, look for error messages in your widget output, or check the “Recent Deliveries” tab in your GitHub webhook configuration.

Have fun!

More Examples

See more things you can do with py.space:

More Examples

Code. Run. Share.

Built with love by the creators of Anvil

Site

Get Started Anvil

Resources

Documentation Tutorial Anvil Forum

Company

About Us Contact Brand Resources

Copyright 2024 py.space. py.space, Anvil, and our logos are trademarks of The Tuesday Project Ltd.

Privacy Terms of Service