Skip to content
This repository was archived by the owner on Nov 8, 2020. It is now read-only.

Latest commit

 

History

History
59 lines (47 loc) · 1.69 KB

File metadata and controls

59 lines (47 loc) · 1.69 KB

Advanced usage

Passing a GitHub API key

Although we're not using GitHub's public API for most operations (see FAQ), we are still using it a bit, e.g. for fetching the day at which the user has joined GitHub. So it's still worth creating an API key and passing it:

$ export GITHUB_CLIENT_ID=0123456789abcdef0123
$ export GITHUB_CLIENT_SECRET=0123456789abcdef0123456789abcdef01234567
$ github-contribs AurelienLourot
GitHub API key found.
✔ Fetched first day at GitHub: 2015-04-04.
⚠ Be patient. The whole process might take up to an hour... Consider using --since and/or --until
✔ Fetched all commits and PRs. Consider using --issues to fetch issues as well.
35 repo(s) found:
AurelienLourot/lsankidb
reframejs/reframe
dracula/gitk
...

Using in a JavaScript project

(async () => {

  const githubContribs = require('@ghuser/github-contribs');
  const ora = require('ora');

  const repos = await githubContribs.fetch(
    'AurelienLourot', // username
    '2018-06-25',     // --since
    null,             // --until
    ora
  );
  for (const repo of repos) {
    console.log(repo);
  }

})();

Helper functions

const githubContribs = require('@ghuser/github-contribs');
const date = githubContribs.stringToDate('2018-05-11T12:26:47Z'); // Date() object
console.log(date); // 2018-05-11T00:00:00.000Z

const dateString = githubContribs.dateToString(date);
console.log(dateString); // 2018-05-11

const dayBefore = githubContribs.prevDay(date); // Date() object
const dayBeforeString = githubContribs.dateToString(dayBefore);
console.log(dayBeforeString); // 2018-05-10