Tars my first bot

In one of my earlier posts I had written about greenkeeper the app that automates dependency updates. I will start with a brief explanation about it, it will send you a pull request(PR) everytime there is a newer version of your depenedencies available, that are specified in package.json. Then you can decide to merge the PR or not. That’s basically what it does. This is just one half of the automation right. You have to manually merge those PR’s.

I thought I could automate that part too. This is were tars comes into picture. Yes, the name was inspired from Interstellar. We all love tars right!. I wrote this bot to help me with my devlog project.

It follows a 3 step process. Check, merge and delete. First step, fetch all open PR’s and see which one’s are opened by GREENKEEPER_BOT. We only care about the one’s opened by it. Then we check the CI status of the PR, whether the tests are passing or failing. In the next step, if the tests are passing, tars merge’s the PR. If PR cannot be merged automatically, it creates a comment with a message saying This pull request cannot be merged by me

After successful merging of PR, it deletes the corresponding branch. Greenkeeper opens a branch with the PR. So after merging, the branch is no longer needed. Tars removes the branch once the PR is merged succesfully into master branch.

The next part is to, set up the program to run as a job. You can schedule a cron job to make the process completely automatic. You can use crontab.guru which is a simple editor for cron schedule expressions.

Bots are fascinating right, it’s an opportunity for us to just sit back, and watch things happen. Why not write your own bot ? I am sure it will be fun.