Socket
Socket
Sign inDemoInstall

gh-got

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gh-got - npm Package Compare versions

Comparing version 9.0.0 to 10.0.0

68

index.js

@@ -1,8 +0,8 @@

'use strict';
const got = require('got');
import process from 'node:process';
import got from 'got';
const getRateLimit = headers => ({
limit: parseInt(headers['x-ratelimit-limit'], 10),
remaining: parseInt(headers['x-ratelimit-remaining'], 10),
reset: new Date(parseInt(headers['x-ratelimit-reset'], 10) * 1000)
limit: Number.parseInt(headers['x-ratelimit-limit'], 10),
remaining: Number.parseInt(headers['x-ratelimit-remaining'], 10),
reset: new Date(Number.parseInt(headers['x-ratelimit-reset'], 10) * 1000),
});

@@ -14,17 +14,38 @@

accept: 'application/vnd.github.v3+json',
'user-agent': 'https://github.com/sindresorhus/gh-got'
'user-agent': 'https://github.com/sindresorhus/gh-got',
},
responseType: 'json',
token: process.env.GITHUB_TOKEN,
context: {
token: process.env.GITHUB_TOKEN,
},
hooks: {
init: [
(raw, options) => {
// TODO: This should be fixed in Got.
// TODO: This doesn't seem to have any effect.
if (typeof options.url === 'string' && options.url.startsWith('/')) {
options.url = options.url.slice(1);
}
if ('token' in raw) {
options.context.token = raw.token;
delete raw.token;
}
},
],
},
handlers: [
(options, next) => {
// TODO: This should be fixed in Got
// TODO: This doesn't seem to have any effect.
if (typeof options.url === 'string' && options.url.startsWith('/')) {
options.url = options.url.slice(1);
}
// Authorization
if (options.token && !options.headers.authorization) {
options.headers.authorization = `token ${options.token}`;
const {token} = options.context;
if (token && !options.headers.authorization) {
options.headers.authorization = `token ${token}`;
}
// `options.body` -> `options.json`
options.json = options.body;
delete options.body;
// Don't touch streams

@@ -50,3 +71,3 @@ if (options.isStream) {

error.name = 'GitHubError';
error.message = `${response.body.message} (${error.response.statusCode})`;
error.message = `${response.body.message} (${response.statusCode})`;
}

@@ -62,21 +83,12 @@

})();
}
},
],
hooks: {
init: [
options => {
// TODO: This should be fixed in Got
// Remove leading slashes
if (typeof options.url === 'string' && options.url.startsWith('/')) {
options.url = options.url.slice(1);
}
}
]
}
});
module.exports = create();
const ghGot = create();
export default ghGot;
if (process.env.NODE_ENV === 'test') {
module.exports.recreate = create;
ghGot.recreate = create;
}
{
"name": "gh-got",
"version": "9.0.0",
"version": "10.0.0",
"description": "Convenience wrapper for Got to interact with the GitHub API",

@@ -13,4 +13,6 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": ">=14.16"
},

@@ -36,10 +38,10 @@ "scripts": {

"dependencies": {
"got": "^10.5.7"
"got": "^12.5.2"
},
"devDependencies": {
"ava": "^3.0.2",
"get-stream": "^5.1.0",
"nock": "^12.0.0",
"xo": "^0.26.1"
"ava": "^4.3.3",
"get-stream": "^6.0.1",
"nock": "^13.2.9",
"xo": "^0.52.4"
}
}

@@ -1,10 +0,12 @@

# gh-got [![Build Status](https://travis-ci.org/sindresorhus/gh-got.svg?branch=master)](https://travis-ci.org/sindresorhus/gh-got)
# gh-got
> Convenience wrapper for [Got](https://github.com/sindresorhus/got) to interact with the [GitHub API](https://developer.github.com/v3/)
Unless you're already using Got, you should probably use GitHub's own [@octokit/rest.js](https://github.com/octokit/rest.js) or [@octokit/graphql.js](https://github.com/octokit/graphql.js) packages instead.
## Install
```sh
npm install gh-got
```
$ npm install gh-got
```

@@ -16,17 +18,16 @@ ## Usage

```js
const got = require('got');
import got from 'got';
const token = 'foo';
(async () => {
const {body} = await got('https://api.github.com/users/sindresorhus', {
json: true,
headers: {
'accept': 'application/vnd.github.v3+json',
'authorization': `token ${token}`
}
});
const {body} = await got('https://api.github.com/users/sindresorhus', {
json: true,
headers: {
'accept': 'application/vnd.github.v3+json',
'authorization': `token ${token}`
}
});
console.log(body.login);
//=> 'sindresorhus'
})();
console.log(body.login);
//=> 'sindresorhus'
```

@@ -37,10 +38,12 @@

```js
const ghGot = require('gh-got');
import ghGot from 'gh-got';
(async () => {
const {body} = await ghGot('users/sindresorhus', {token: 'foo'});
const {body} = await ghGot('users/sindresorhus', {
context: {
token: 'foo'
}
});
console.log(body.login);
//=> 'sindresorhus'
})();
console.log(body.login);
//=> 'sindresorhus'
```

@@ -51,10 +54,12 @@

```js
const ghGot = require('gh-got');
import ghGot from 'gh-got';
(async () => {
const {body} = await ghGot('https://api.github.com/users/sindresorhus', {token: 'foo'});
const {body} = await ghGot('https://api.github.com/users/sindresorhus', {
context: {
token: 'foo'
}
});
console.log(body.login);
//=> 'sindresorhus'
})();
console.log(body.login);
//=> 'sindresorhus'
```

@@ -98,10 +103,8 @@

```js
const ghGot = require('gh-got');
import ghGot from 'gh-got';
(async () => {
const {rateLimit} = await ghGot('users/sindresorhus');
const {rateLimit} = await ghGot('users/sindresorhus');
console.log(rateLimit);
//=> {limit: 5000, remaining: 4899, reset: [Date 2018-12-31T20:45:20.000Z]}
})();
console.log(rateLimit);
//=> {limit: 5000, remaining: 4899, reset: [Date 2018-12-31T20:45:20.000Z]}
```

@@ -120,15 +123,13 @@

```js
const ghGot = require(`gh-got`);
import ghGot from 'gh-got';
(async () => {
const options = {
headers: {
authorization: `Bearer ${jwt}`
}
};
const {body} = await ghGot('app', options);
const options = {
headers: {
authorization: `Bearer ${jwt}`
}
};
const {body} = await ghGot('app', options);
console.log(body.name);
//=> 'MyApp'
})();
console.log(body.name);
//=> 'MyApp'
```

@@ -138,2 +139,2 @@

See the [Got docs](https://github.com/sindresorhus/got#pagination).
See the [Got docs](https://github.com/sindresorhus/got/blob/main/documentation/4-pagination.md).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc