prajun7 / github-commit-bot

Bot to add commits to the GitHub's contribution graph

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bot to add commits in GitHub

Idea from Akshay Saini.

This is only for educational purpose. That's why all the commits made from this repo are public in my profile.

687474703a2f2f692e696d6775722e636f6d2f6536446c7a66412e706e67

You can make patterns or write text.

Main Idea

The main idea is that we are making commits in the past date. Whenever we make any commits to any repo, GitHub tracks them by associating those commits with a specific time (i.e. the date and time when we created that commit). So, here we are manipulating that time to some past date so we can make commits in the past. And when we push those commits with modified date and time, GitHub populates the contribution graph based on those past dates.

Does this works for future date as well?
If you are curious do try it out

Coding approach

  • As we need to manipulate the date, we will use a package called Moment. It is a JavaScript library for parsing, validating, manipulating, and formatting dates.
  • Next, we will use a package called simple-git. It helps us to run git commands like push, commit in node.js applications.
  • We will also use a jsonfile package to write those manipulated date into a json file. Once we write those random dates into the json file, then we can commit them in GitHub. We will add that file into the .add() method from simple-git and will make the commit using .commit() method.
  • Last package we will be using is random. We will use this package to generate random integers which will be our random dates.

Check the comments in index.js file for better undestanding.

Installation

Clone and fork the repository to make the changes in your local system.

git clone https://github.com/prajun7/github-commit-bot.git
cd github-commit-bot

Now this command creates a directory named node_modules and installs all the required packages.

npm install

Finally, to run the project.

node index.js

You can see the commit date in terminal.

Make design and text in your graph

subtract(year, "y");

year here represents the year to start the commits. You can go, 1 year back from today or 2 years and so on

add(week, "w");
add(days, "d");

Here you can modify the weeks and days to make commits at the specific point in the graph. Weeks are the x-Axis and days are the y-Axis.

To modify weeks(x-Axis), you need to change this variable 'x' here in line 23

To modify days(y-Axis), you need to change this variable 'y' here in line 24

The top left corner of the contribution graph has the (0,0) coordinate.

So, based on this information you can make commits at a specific point in the contribution graph and can make some beautiful pattern or text.

save

water

Some improvement ideas for this project

  • Moment.js is a big package, and it is slow. Read more here. It is better to use other alternative packages like day.js.
  • Instead of manually making commits in the contribution graph to make those design or text, we can automate this process. We can write a function that takes an array of the design that then generates the dates to draw those designs in the contribution graph. Or there might be other better approaches.

About

Bot to add commits to the GitHub's contribution graph


Languages

Language:JavaScript 100.0%