How To Build Scheduled Task on Github Libraries Releases via Slack Apps

In this Article, We Will build a Slack Application To Send Messages to Slack Channel when Any Library you follow on Github Publish New Release

Yazan Tarifi
5 min readOct 21, 2021
Photo by Aron Visuals on Unsplash

As a Developer, you worked on a lot of projects and inside these projects, you should use Libraries to implement a Feature whatever if the library is a 3rd part library or native library from the Framework itself and this is totally fine, The Problem I faced when I use The Libraries that I should check or Follow Someone on Twitter, Reddit or medium to get notifications on the Libraries that I'm using inside my Project, but if I didn’t open any application from social media apps I will never know if any library pushed new Version on their Repository or maybe I know about this updates after 2 weeks and for this reason I need to get Notifications in the same day of the Release because some libraries are still pushing major release changes and it’s really a big problem if we discover this Updates after 2 Weeks from the Release date

The Simplest Solution to Build Scheduler for This Process

We should Create a Scheduled Task to check on all libraries that we are using inside our projects to get notifications on the same day inside this release and we gonna build it From Scratch with some tools that will help us build this Task

The Components Used inside This Project

  1. Node Js Project
  2. Slack Application
  3. The Source Links of The Libraries

The Full Example will be Available at the End of the Article

First Thing is to Build The Backend Project

We Will Use NodeJs to Build Backend Side of this Project and Especially NestJs Framework and Typescript and We Need to Use one of the Backend Frameworks To Use Cron Jobs and CronJob is a Scheduled Event That Will Trigger Some Actions in Specific Time that You Specify it when Create the instance of the Task Service

You can Use any Backend Framework because most of them has Cron Job implemented inside each one of them but for me, I Prefer to Build these Things in NestJs

Second Thing is to Create a Slack Application

Slack Application is a Ready Api from Slack To Create Application with Id, Name, Logo That will Send Messages To Members, Channels inside your Workspace and for this project, we will configure this application to send messages with the New Versions of the Libraries on specific Channel

The final Part is Configuring The Source of Libraries

This is Really Important is to Know each Library which source is the Best to Fetch it, For Example, when I build Android Applications I have multiple Sources to Fetch Libraries not all of them from one Source like (MavenCentral, GoogleMavenRepository, GithubRepository, GradlePortal) and We Need to Find a way to Fetch The Libraries from Multiple Sources inside the Same Project

But In this Part, I saw Something Common Between all of them is 90% of the Libraries Source code inside Github Repositories and all of them has Releases and Tags Version so We Can Track all of them from a Common Source which is (Github API)

Now Let’s Start with The Implementation of the Project and We Will Start with Creating Slack and Github Configuration

The First Step is To Configure Slack and Github to Get Tokens, Keys that we Need to Use inside our NodeJs Project

First Step Create Slack Application inside Your Workspace and Specify the Logo and Name of the Application Then Add The Following Configuration inside App Manifest

Now You Need to Create a Github Application from OAuth Settings Inside Your Github Account Settings and Take the Client Id and Secret Client Id then Save Them on Text File with Slack Keys (Token, Signing Key) and All of these Keys can be Found inside the Application Settings In General Tab Then Save All Keys and Tokens in One Text File because We Will Need them Later

Now Create Channel inside Your Slack Workplace and Invite the Application you created inside this channel to get access to the Channel

Now Create NestJs Project

Generate New project with NestJs By Executing the Following Commands inside Your Terminal

Now We Want to Add Cron Job to start Scheduled Task

This Task will be started at a specific time like the following example

Now We Will Use Axios To Send API Requests on GitHub to check all Libraries and get Releases Using GitHub API v3

Now the Functionality will be like the Following, We want to Store all libraries that we need to check every day then we will store the latest released tag and on each day the scheduler will send a request to the GitHub repo to check the latest tag if not similar to stored tag then we will send a slack message with this library

In this stage, you have the option to store all of them in the way you like if you want you can use the database to store all of them but I prefer to write all of them inside JSON file in this type of project

This is a Simple Example of how to check all of them in this stage you will need to get Github app clientId, SecreteId from the GitHub app that you created in your GitHub profile settings

Now We Have the Updated Libraries inside Array and we want to loop on them and send messages via slack API using the Signing Key, Secret Key

Use this Method inside your Loop and Create your Own Message on each Library, in my case I have added all libraries and their documentation links, official websites that I need to my JSON file, and on each message, I check all of them and send them with the message

In Slack Application Create a Channel and invite the app to this channel by typing /invite then pick the application and inside the code when you want to send a message on the channel you should write it to be like this (#general)

The Scheduled Task Result

Full Example is Available on Github

--

--

Yazan Tarifi

Software Engineer working on Android applications, KMM apps, backend developer with Spring boot, Nest.js also web developer to build static Websites with React