Github -> Discord Webhook
The Project
We’ve been developing a lot of random tools during this time of uncertainty. Between quaranteenies, we’ve managed to hook up Monday to Discord, Github to Slack, MongoDb to excel, sheets to Reaper…
Gosh the list really does go on and on.
Part of being a development firm for random pieces of software that helps working professionals is finding unique solutions to particularly niche problems. Here in Melbourne, Australia, we’ve been in lockdown since, well, about March, depending on where you’re located. This has, of course, seen an increasing reliance on tools like Zoom, Monday, Trello, Notion, Discord…you name it! Personally, I’ve found a ton of these services somewhat tiresome, as you constantly sign in and out of different workspaces to work for several companies. Currently, we’re working with 7 different teams who each have their own methods of communication. A bit of a nightmare.
Getting Lost
It happens. We miss pushes, commits, and so forth, or get stuck with merge conflicts because we aren’t sure who’s currently in the scene. To ameliorate this, we put together a simple Github->Discord connection that would help by posting meaningful messages in the discord when commits and pushes happened.
In talking with some colleagues, they mentioned it would certainly help workflow to get these messages, so we’ll detail the process of doing so here. Hopefully, you can use the following project to meaningfully trace work completed by your team, and have a little fun while doing it.
The Process
First up, you’ll need a Github Project.
We’ve set up a repo for the project, which you’ll find here. Feel free to copy it out, comment, pull, etc.
We’ll also be using the project itself to sort out a webhook.
First up, find the discord channel you want the messages posted in. It’s important to keep this safe, (obviously), as people CAN access the information if they have the webhook.
Open up the server settings (you may need server priveledges) and click the integrations tab. After that, click Create Webhook (and ensure you give it a snazzy name that’s definitely witty and funny).
You can also give it an image, and specify which channel you’ll want to post in. It can be annoying to have these updates spamming regular chat, so I’d set up a different channel to have the Github updates posted in. On the discord side, that’s essentially it! There are a number of ways that you can do this, but Discord’s native API sure is easy. You could, of course, use node and write your own webhook too, maybe we’ll deal with that next time!
The Github Side
Moving onto our Github page, open up Settings -> Webhooks -> Add Webhook.
Change the content type to json (to allow for easy formatting (again, you can use this in your node/fancy database software if you do this, a good idea). Go back to your discord and hit “Copy Webhook URL”, and paste it into your Github page under PAYLOAD URL.
It’s important to note that this webhook URL should not be shared around, for the reason of the earlier access stuff. Also, you’ll want to append /github to the end of whatever long ass name comes out of it. So it should be sxdghksdahgkahsdflgjkhlasdlfg/github (an example, don’t go here) ((Or do?!))
If you don’t pop the /github in, you’ll likely get connection issues as Github fights with its inner demons.
A little further down the page, you’ll see the MEAT OF THE SANDWICH. I’m making it a little more exciting than it is, but I’m just that kinda guy. You can specify whether you’d like every commit, rebase, pull request and reversion under the sun. For my uses, I generally like just the push event, but if you’re a project manager, you might want to select individual events. You might be branch master in charge of cherry-picking or whatever, use this stuff to your heart’s content (but beware of cholesterol problems in the future.
And that’s it! Hit confirm and push something to your repo.
For me, I’m just going to add a screenshot to the repo, to show that it’s working.
Hot tip!
FOr those of you that want to be fancy, and maybe haven’t used a ton of command line git, something to get your feet wet. In terminal, move the file you’d like to commit to the folder, and type;
git add screenshot.png
Where screenshot.png is whatever the file+file extension you’re adding is. After that, type
git commit
Enter a description of the push. It’s a good idea to be somewhat descriptive here, in a way the team can understand what you’re talking about, and you can remember what you’re talking about. When you’re finished, press ESCAPE, and then type :wq to quit.
git push
Upon doing so, you’ll need to provide your login details.
After pushing, you should see this message!
That’s it!
I hope you enjoyed the process of learning about this, and hopefully you can contribute to your team with a nifty webhook integration. Maybe next time we can call some custom Discord API behaviour to add reactions, emotes, send messages, etc. Let us know if that’s something you’d be interested in!