This document provides a detailed process for fetching GitHub commits using a helper function written in JavaScript.
- Node.js installed on your machine.
- A GitHub personal access token with the necessary permissions.
- The
axios
andmoment
libraries installed.
First, import the necessary libraries: axios
for making HTTP requests and moment
for formatting dates.
import axios from "axios";
import moment from "moment";
Rename .env.sample
to .env
and provide GitHub personal access token.
const { GITHUB_TOKEN } = process.env;
fetchCommits("your-username", "your-repository-name", "results-per-page"(OPTIONAL));
[
{
Commit: '7c22ce7',
Message: 'node_modules added to gitignore',
Date: '10-07-2024 15:08:21 PM',
URL: 'https://github.com/nilanjanhaldar24/sample-repo/commit/7c22ce70f0ebab7624e0c547d27137c651397f98',
Author: 'Nilanjan Haldar',
Username: 'nilanjanhaldar24'
},
{
Commit: '9cb54bd',
Message: 'first commit',
Date: '10-07-2024 15:00:22 PM',
URL: 'https://github.com/nilanjanhaldar24/sample-repo/commit/9cb54bdac63a33da3c1c4e90e156da298819634f',
Author: 'Nilanjan Haldar',
Username: 'nilanjanhaldar24'
}
]