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

Commit

Permalink
Exported some helper functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
lourot committed Jun 25, 2018
1 parent 93a5d70 commit 0e0cd94
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ when it breaks.

## Changelog

**2.0.0** (2018-06-25):
* Exported some helper functions.

**1.0.0** (2018-06-11):
* Support for passing a GitHub API key.

Expand Down
4 changes: 2 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ optional arguments:
}

const user = cli.input[0];
const repos = await githubContribs(user, cli.flags.since, cli.flags.until,
!cli.flags.quiet && ora, cli.flags.verbose && console);
const repos = await githubContribs.fetch(user, cli.flags.since, cli.flags.until,
!cli.flags.quiet && ora, cli.flags.verbose && console);
if (!cli.flags.quiet) {
console.log(`${repos.size} repo(s) found:`);
}
Expand Down
13 changes: 12 additions & 1 deletion docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dracula/gitk
const githubContribs = require('@ghuser/github-contribs');
const ora = require('ora');

const repos = await githubContribs(
const repos = await githubContribs.fetch(
'AurelienLourot', // username
'2018-06-25', // --since
null, // --until
Expand All @@ -42,3 +42,14 @@ dracula/gitk

})();
```

### Helper functions

```js
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
```
3 changes: 2 additions & 1 deletion docs/maintain.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ $ rm ghuser-github-contribs-7.8.9.tgz
## Install the package locally

```bash
$ sudo npm uninstall -g @ghuser/github-contribs
$ sudo npm install . -g
```

and test it briefly, e.g.

```bash
$ github-contribs --version
$ github-contribs --since 2018-05-29 AurelienLourot
$ github-contribs --since 2018-06-20 AurelienLourot
```

## Commit your changes, create a git tag and push
Expand Down
24 changes: 15 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
const htmlparser = require('htmlparser');
const moment = require('moment');

module.exports = async (user, since, until, ora, console) => {
const fetchContribs = async (user, since, until, ora, console) => {
ora = ora || (() => {
return {
start() { return this; },
Expand All @@ -25,6 +25,20 @@
return result;
};

// See https://stackoverflow.com/a/28431880/1855917
const stringToDate = string => {
return new Date(`${string.substring(0, 10)}T00:00:00Z`);
};
const dateToString = date => {
return date.toISOString().substring(0, 10);
};

module.exports = {
fetch: fetchContribs,
stringToDate,
dateToString
};

const fetchRetry = url => {
const tooManyRequests = 429;
return fetch(url, {
Expand Down Expand Up @@ -191,14 +205,6 @@
return result;
};

// See https://stackoverflow.com/a/28431880/1855917
const stringToDate = string => {
return new Date(`${string.substring(0, 10)}T00:00:00Z`);
};
const dateToString = date => {
return date.toISOString().substring(0, 10);
};

// See https://stackoverflow.com/a/25114400/1855917
const prevDay = date => {
return new Date(date.getTime() - (24 * 60 * 60 * 1000));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ghuser/github-contribs",
"version": "1.0.0",
"version": "2.0.0",
"description": "List all GitHub repos a user has contributed to since the beginning of time.",
"license": "Unlicense",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('fetches commits and PRs', async t => {
};
};

const result = await m('AurelienLourot', '2017-08-26', '2017-08-28', ora, console);
const result = await m.fetch('AurelienLourot', '2017-08-26', '2017-08-28', ora, console);
t.is(result.size, 2);
t.true(result.has('AurelienLourot/mybeir.ut'));
t.true(result.has('tt-gf/ant-ivy'));
Expand Down

0 comments on commit 0e0cd94

Please sign in to comment.