DEV Community

Cover image for Build a GitHub Stargazer - Get Slack alerts when somebody stars your project in 4 lines of code
Jordi Cabot
Jordi Cabot

Posted on • Edited on • Originally published at xatkit.com

Build a GitHub Stargazer - Get Slack alerts when somebody stars your project in 4 lines of code

All the self-help gurus keep telling you that you should control your instincts and avoid checking your GitHub projects to see if somebody starred any of them in the last 5 minutes. I have the same problem (yes, first world problems). And as usual, changing the system/environment is easier than changing your own behaviour.

That's why I've changed the way to check for stars counting from a pull to a push approach by using the Xatkit bot development platform.

Now, instead of me checking GitHub for new notifications, I have a bot that alerts me automatically every time somebody stars one of my projects, as you can see in the featured image above. By using our (now extended)

GitHub logo xatkit-bot-platform / xatkit-github-platform

Receive events and perform actions on Github from your Xatkit execution model

Xatkit Github Platform

License Badge Build Status Wiki Badge

Receive events and performs action on Github from your Xatkit execution model.

Providers

The Github platform define the following providers:

Provider Type Context Parameters Description
GithubWebhookEventProvider Event - Receive webhook events from the Github API and translate them into Xatkit-compatible events.

GithubWebhookEventProvider Events

Event Context Parameters Description
Issue_Opened issue See the platform file Event sent when a new issue is opened in the repository.
Issue_Edited issue See the platform file Event sent when an issue is edited.
Issue_Closed issue See the platform file Event sent when an issue is closed.
Issue_Reopened issue See the platform file Event sent when an issue is reopened.
Issue_Assigned issue See the platform file Event sent when an issue is assigned.
Issue_Unassigned issue See the platform file Event sent when an issue is unassigned.
Issue_Labeled issue See the platform file Event sent when an issue is labeled. Note: issues that are
creating this bot is as easy as writing the following four lines of code:

Basically, we subscribe to the Star_Event and extract out of the JSON Payload sent by GitHub all the data we want to integrate into our message. The reception of the event, the parsing of the JSON data,... is all done by the GithubPlatform.GithubWebhookEventProvider class. We just take what we need from the processed information. As usual, in this example, we post the result on Slack but this is up to you, just make sure you configure the properties file.

Note that the bot can also be the bearer of bad news. If some lesser person decides to unstar your repo you'll get also the proper notification. In both cases, the alert is immediate since we process the GitHub events as they come.

GitHub alert when somebody unstars your repository

Our Xatkit-GitHub platform is bidirectional. Beyond subscribing to GitHub events we can also call GitHub ourselves to create new issues, add labels, users,... based on a chat conversation taking place on an external platform. We have another example for this: Talk with your repositories – A Slack chatbot for GitHub. See this and other examples in our dedicated xatkit examples repo.

I hope these examples show you how powerful this integration between Xatkit and GitHub can be. Surprise me with your own examples!.

And of course, if you liked it, don't forget to star our repo. You'll made my day if I start getting plenty of star alerts from you!

GitHub logo xatkit-bot-platform / xatkit

Simplest way to build all types of smart chatbots and digital assistants

Xatkit - The easiest way to build advanced bots and chatbots

Wiki Badge Twitter

Get your own smart chatbot. Design your bot once, deploy it everywhere

Xatkit has been created to reduce boilerplate code, complex API understanding, and technical details to facilitate the definition and deployment of your bots. Xatkit helps you focus on what really matters: the conversation logic you want to embed in your chatbot.

To do so, we have baked a chatbot-specific definition language to specify user intentions, receive events (your bots can also be proactive!), and bind them to computable actions following powerful state machine semantics. Our chatbot language is implemented as a Java Fluent Interface combining the low-code benefits of using a dedicated chatbot Internal DSL with the full power of Java when you need to write complex bot behaviours.

This chatbot specification is then handled by the Xatkit Runtime Engine, which automatically manages its…

Top comments (0)