Skip to content

Commit 11e621b

Browse files
committedDec 31, 2018
Meta tweaks
1 parent a66fa03 commit 11e621b

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed
 

‎.gitattributes

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

‎index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const create = () => got.create({
1111
'user-agent': 'https://github.com/sindresorhus/gh-got'
1212
}
1313
}),
14+
1415
methods: got.defaults.methods,
16+
1517
handler: (options, next) => {
1618
if (options.token) {
1719
options.headers.authorization = options.headers.authorization || `token ${options.token}`;
@@ -21,13 +23,13 @@ const create = () => got.create({
2123
return next(options);
2224
}
2325

24-
return next(options).catch(err => {
25-
if (err.response && err.response.body) {
26-
err.name = 'GitHubError';
27-
err.message = `${err.response.body.message} (${err.statusCode})`;
26+
return next(options).catch(error => {
27+
if (error.response && error.response.body) {
28+
error.name = 'GitHubError';
29+
error.message = `${error.response.body.message} (${error.statusCode})`;
2830
}
2931

30-
throw err;
32+
throw error;
3133
});
3234
}
3335
});

‎package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
"utility"
3434
],
3535
"dependencies": {
36-
"got": "^9.2.0"
36+
"got": "^9.5.0"
3737
},
3838
"devDependencies": {
39-
"ava": "^1.0.0-beta.7",
40-
"get-stream": "^4.0.0",
41-
"nock": "^9.1.0",
42-
"xo": "*"
39+
"ava": "^1.0.1",
40+
"get-stream": "^4.1.0",
41+
"nock": "^10.0.5",
42+
"xo": "^0.23.0"
4343
}
4444
}

‎readme.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,21 @@ const ghGot = require('gh-got');
6161

6262
## API
6363

64-
Same as [`got`](https://github.com/sindresorhus/got) (including the stream API and aliases), but with some additional options below.
64+
Same API as [`got`](https://github.com/sindresorhus/got), including the stream API and aliases, but with some additional options below.
6565

6666
Errors are improved by using the custom GitHub error messages. Doesn't apply to the stream API.
6767

68-
### token
68+
### `gh-got` specific options
69+
70+
#### token
6971

7072
Type: `string`
7173

7274
GitHub [access token](https://github.com/settings/tokens/new).
7375

7476
Can be set globally with the `GITHUB_TOKEN` environment variable.
7577

76-
### baseUrl
78+
#### baseUrl
7779

7880
Type: `string`<br>
7981
Default: `https://api.github.com/`
@@ -82,7 +84,7 @@ To support [GitHub Enterprise](https://enterprise.github.com).
8284

8385
Can be set globally with the `GITHUB_ENDPOINT` environment variable.
8486

85-
### body
87+
#### body
8688

8789
Type: `Object`
8890

‎test.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
import test from 'ava';
22
import nock from 'nock';
33
import getStream from 'get-stream';
4-
import m from '.';
4+
import ghGot from '.';
55

66
const token = process.env.GITHUB_TOKEN;
77

88
test('default', async t => {
9-
t.is((await m('users/sindresorhus')).body.login, 'sindresorhus');
9+
t.is((await ghGot('users/sindresorhus')).body.login, 'sindresorhus');
1010
});
1111

1212
test('full path', async t => {
13-
t.is((await m('https://api.github.com/users/sindresorhus')).body.login, 'sindresorhus');
13+
t.is((await ghGot('https://api.github.com/users/sindresorhus')).body.login, 'sindresorhus');
1414
});
1515

1616
test('accepts options', async t => {
17-
t.is((await m('users/sindresorhus', {})).body.login, 'sindresorhus');
17+
t.is((await ghGot('users/sindresorhus', {})).body.login, 'sindresorhus');
1818
});
1919

2020
test('accepts options.endpoint without trailing slash', async t => {
21-
t.is((await m('users/sindresorhus', {endpoint: 'https://api.github.com'})).body.login, 'sindresorhus');
21+
t.is((await ghGot('users/sindresorhus', {endpoint: 'https://api.github.com'})).body.login, 'sindresorhus');
2222
});
2323

2424
test('dedupes slashes', async t => {
25-
t.is((await m('/users/sindresorhus', {endpoint: 'https://api.github.com/'})).body.login, 'sindresorhus');
25+
t.is((await ghGot('/users/sindresorhus', {endpoint: 'https://api.github.com/'})).body.login, 'sindresorhus');
2626
});
2727

2828
test.serial('global token option', async t => {
2929
process.env.GITHUB_TOKEN = 'fail';
30-
await t.throwsAsync(m.recreate()('users/sindresorhus'), 'Bad credentials (401)');
30+
await t.throwsAsync(ghGot.recreate()('users/sindresorhus'), 'Bad credentials (401)');
3131
process.env.GITHUB_TOKEN = token;
3232
});
3333

3434
test('token option', async t => {
35-
await t.throwsAsync(m('users/sindresorhus', {token: 'fail'}), 'Bad credentials (401)');
35+
await t.throwsAsync(ghGot('users/sindresorhus', {token: 'fail'}), 'Bad credentials (401)');
3636
});
3737

3838
test.serial('global endpoint option', async t => {
3939
process.env.GITHUB_ENDPOINT = 'fail';
40-
await t.throwsAsync(m.recreate()('users/sindresorhus', {retries: 1}), 'Invalid URL: fail/');
40+
await t.throwsAsync(ghGot.recreate()('users/sindresorhus', {retries: 1}), 'Invalid URL: fail/');
4141
delete process.env.GITHUB_ENDPOINT;
4242
});
4343

4444
test.serial('endpoint option', async t => {
4545
process.env.GITHUB_ENDPOINT = 'https://api.github.com/';
46-
await t.throwsAsync(m.recreate()('users/sindresorhus', {
46+
await t.throwsAsync(ghGot.recreate()('users/sindresorhus', {
4747
baseUrl: 'fail',
4848
retries: 1
4949
}), 'Invalid URL: fail/');
5050
delete process.env.GITHUB_ENDPOINT;
5151
});
5252

5353
test('stream interface', async t => {
54-
t.is(JSON.parse(await getStream(m.stream('users/sindresorhus'))).login, 'sindresorhus');
55-
t.is(JSON.parse(await getStream(m.stream.get('users/sindresorhus'))).login, 'sindresorhus');
54+
t.is(JSON.parse(await getStream(ghGot.stream('users/sindresorhus'))).login, 'sindresorhus');
55+
t.is(JSON.parse(await getStream(ghGot.stream.get('users/sindresorhus'))).login, 'sindresorhus');
5656
});
5757

5858
test('json body', async t => {
@@ -62,12 +62,13 @@ test('json body', async t => {
6262

6363
const scope = nock(baseUrl).post('/test', body).reply(200, reply);
6464

65-
t.deepEqual((await m('/test', {baseUrl, body})).body, reply);
65+
t.deepEqual((await ghGot('/test', {baseUrl, body})).body, reply);
6666
t.truthy(scope.isDone());
6767
});
6868

6969
test('custom error', async t => {
70-
const err = await t.throwsAsync(m('users/sindresorhus', {token: 'fail'}));
71-
t.is(err.name, 'GitHubError');
72-
t.is(err.message, 'Bad credentials (401)');
70+
await t.throwsAsync(ghGot('users/sindresorhus', {token: 'fail'}), {
71+
name: 'GitHubError',
72+
message: 'Bad credentials (401)'
73+
});
7374
});

0 commit comments

Comments
 (0)
Please sign in to comment.