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

Commit 0e0cd94

Browse files
committed
Exported some helper functions.
1 parent 93a5d70 commit 0e0cd94

File tree

7 files changed

+36
-15
lines changed

7 files changed

+36
-15
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ when it breaks.
8080

8181
## Changelog
8282

83+
**2.0.0** (2018-06-25):
84+
* Exported some helper functions.
85+
8386
**1.0.0** (2018-06-11):
8487
* Support for passing a GitHub API key.
8588

cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ optional arguments:
5151
}
5252

5353
const user = cli.input[0];
54-
const repos = await githubContribs(user, cli.flags.since, cli.flags.until,
55-
!cli.flags.quiet && ora, cli.flags.verbose && console);
54+
const repos = await githubContribs.fetch(user, cli.flags.since, cli.flags.until,
55+
!cli.flags.quiet && ora, cli.flags.verbose && console);
5656
if (!cli.flags.quiet) {
5757
console.log(`${repos.size} repo(s) found:`);
5858
}

docs/advanced.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dracula/gitk
3030
const githubContribs = require('@ghuser/github-contribs');
3131
const ora = require('ora');
3232

33-
const repos = await githubContribs(
33+
const repos = await githubContribs.fetch(
3434
'AurelienLourot', // username
3535
'2018-06-25', // --since
3636
null, // --until
@@ -42,3 +42,14 @@ dracula/gitk
4242

4343
})();
4444
```
45+
46+
### Helper functions
47+
48+
```js
49+
const githubContribs = require('@ghuser/github-contribs');
50+
const date = githubContribs.stringToDate('2018-05-11T12:26:47Z'); // Date() object
51+
console.log(date); // 2018-05-11T00:00:00.000Z
52+
53+
const dateString = githubContribs.dateToString(date);
54+
console.log(dateString); // 2018-05-11
55+
```

docs/maintain.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ $ rm ghuser-github-contribs-7.8.9.tgz
2929
## Install the package locally
3030

3131
```bash
32+
$ sudo npm uninstall -g @ghuser/github-contribs
3233
$ sudo npm install . -g
3334
```
3435

3536
and test it briefly, e.g.
3637

3738
```bash
3839
$ github-contribs --version
39-
$ github-contribs --since 2018-05-29 AurelienLourot
40+
$ github-contribs --since 2018-06-20 AurelienLourot
4041
```
4142

4243
## Commit your changes, create a git tag and push

index.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const htmlparser = require('htmlparser');
88
const moment = require('moment');
99

10-
module.exports = async (user, since, until, ora, console) => {
10+
const fetchContribs = async (user, since, until, ora, console) => {
1111
ora = ora || (() => {
1212
return {
1313
start() { return this; },
@@ -25,6 +25,20 @@
2525
return result;
2626
};
2727

28+
// See https://stackoverflow.com/a/28431880/1855917
29+
const stringToDate = string => {
30+
return new Date(`${string.substring(0, 10)}T00:00:00Z`);
31+
};
32+
const dateToString = date => {
33+
return date.toISOString().substring(0, 10);
34+
};
35+
36+
module.exports = {
37+
fetch: fetchContribs,
38+
stringToDate,
39+
dateToString
40+
};
41+
2842
const fetchRetry = url => {
2943
const tooManyRequests = 429;
3044
return fetch(url, {
@@ -191,14 +205,6 @@
191205
return result;
192206
};
193207

194-
// See https://stackoverflow.com/a/28431880/1855917
195-
const stringToDate = string => {
196-
return new Date(`${string.substring(0, 10)}T00:00:00Z`);
197-
};
198-
const dateToString = date => {
199-
return date.toISOString().substring(0, 10);
200-
};
201-
202208
// See https://stackoverflow.com/a/25114400/1855917
203209
const prevDay = date => {
204210
return new Date(date.getTime() - (24 * 60 * 60 * 1000));

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ghuser/github-contribs",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "List all GitHub repos a user has contributed to since the beginning of time.",
55
"license": "Unlicense",
66
"repository": {

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('fetches commits and PRs', async t => {
2828
};
2929
};
3030

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

0 commit comments

Comments
 (0)