This website works best with JavaScript enabled.
GitHub Graph

Brightly decorate your GitHub Graph

Impress viewers by sleek profile with just 40 lines of code

  • Back to home
  • Listen this article
  • Print this article
3 min read
Dec 24, 2024

🌟 Motivation

In the past I was searching for good libraries of npm and I stumbled upon a library called simple-git. This is a library that runs git commands on nodejs. And then I immediately thought of the contributions chart on github, is there a way to make this chart green? And so this article was born.

🏗️ Setup

1. Initial Nodejs project and install dependencies

npm
yarn
pnpm
bun
npm init
npm install jsonfile moment random simple-git
yarn init
yarn add jsonfile moment random simple-git
pnpm init
pnpm add jsonfile moment random simple-git
bun init
bun add jsonfile moment random simple-git

2. Fake data

Create a file named data.json at the root of the project to store changes when committing new code.

data.json
add something here

3. Insert script

Create a javascript file name index.js with the following content at the root of the project.

index.js
import jsonfile from 'jsonfile';
import moment from 'moment';
import simpleGit from 'simple-git';
import random from 'random';

const path = './data.json';

function isValidDate(date) {
  const startDate = moment('2019-01-01');
  const endDate = moment('2024-12-13');
  return date.isBetween(startDate, endDate, null, '[]');
}

async function markCommit(date) {
  const data = { date: date.toISOString() };
  await jsonfile.writeFile(path, data);

  const git = simpleGit();
  await git.add([path]);
  await git.commit(date.toISOString(), { '-d': date.toISOString() });
}

async function makeCommits(n) {
  const git = simpleGit();

  for (let i = 0; i < n; i++) {
    const randomDays = random.int(0, 6);
    const randomWeeks = random.int(0, 54 * 4);

    const randomDate = moment('2019-01-01')
      .add(randomDays, 'days')
      .add(randomWeeks, 'weeks');

    if (isValidDate(randomDate)) {
      console.log(`Creating commit: ${randomDate.toISOString()}`);
      await markCommit(randomDate);
    } else {
      console.log(`Invalid date: ${randomDate.toISOString()}, skipping...`);
    }
  }

  console.log('Pushing all commits...');
  await git.push();
}

makeCommits(50000);

4. Action

Initialize the git repo (if empty), skip this step if you already have a git repo.

git init

Run the script to create commit.

node index.js

Finally, push code to remote then enjoy the result.

  • git
  • github
Setup Docker environment on Windows
Download a specific folder on GitHub repository

🍃 Related posts

  • Essential_Git_commands_image

    Essential Git commands every developer should master

  • Syncing_Git_Tags_image

    Syncing Git Tags across to other repositories

  • GitHub_Achievements_image

    Unlocking GitHub Achievement badges

Bookmark

Want to update?

Subscribe to my blog to receive the latest updates from us.

Monthly articles
New articles will be created every month.
No spam
All notifications are notified to you, not spam or advertising.

© Tran Nguyen Thuong Truong, 2024 - PRESENT