Socket
Socket
Sign inDemoInstall

gl-got

Package Overview
Dependencies
24
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.0.0 to 9.0.0

92

index.js
'use strict';
const got = require('got');
const isPlainObj = require('is-plain-obj');
function glGot(path, opts) {
if (typeof path !== 'string') {
return Promise.reject(
new TypeError(`Expected \`path\` to be a string, got ${typeof path}`)
);
}
const create = () => got.create({
options: got.mergeOptions(got.defaults.options, {
json: true,
token: process.env.GITLAB_TOKEN,
baseUrl: process.env.GITLAB_ENDPOINT || 'https://gitlab.com/api/v4',
headers: {
'user-agent': 'https://github.com/singapore/gl-got'
}
}),
methods: got.defaults.methods,
handler: (options, next) => {
if (options.token) {
options.headers.authorization = `token ${options.token}`;
}
const env = process.env;
if (options.method && options.method === 'PUT' && !options.body) {
options.headers['content-length'] = 0;
}
opts = Object.assign(
{
json: true,
token: env.GITLAB_TOKEN,
endpoint: env.GITLAB_ENDPOINT
? env.GITLAB_ENDPOINT.replace(/[^/]$/, '$&/')
: 'https://gitlab.com/api/v4/',
},
opts
);
if (options.stream) {
return next(options);
}
opts.headers = Object.assign(
{
'user-agent': 'https://github.com/singapore/gl-got',
},
opts.headers
);
return next(options).catch(err => {
if (err.response && err.response.body) {
err.name = 'GitLabError';
err.message = `${err.response.body.message || err.response.body} (${err.statusCode})`;
}
if (opts.token) {
opts.headers['PRIVATE-TOKEN'] = opts.token;
}
throw err;
});
}
});
const url = /^https?/.test(path) ? path : opts.endpoint + path;
module.exports = create();
if (opts.stream) {
return got.stream(url, opts);
}
return got(url, opts).catch(err => {
if (err.response && isPlainObj(err.response.body)) {
err.name = 'GitLabError';
err.message = `${err.response.body.message} (${err.statusCode})`;
}
throw err;
});
if (process.env.NODE_ENV === 'test') {
module.exports.recreate = create;
}
const helpers = ['get', 'post', 'put', 'patch', 'head', 'delete'];
glGot.stream = (url, opts) =>
glGot(
url,
Object.assign({}, opts, {
json: false,
stream: true,
})
);
for (const x of helpers) {
const method = x.toUpperCase();
glGot[x] = (url, opts) => glGot(url, Object.assign({}, opts, { method }));
glGot.stream[x] = (url, opts) =>
glGot.stream(url, Object.assign({}, opts, { method }));
}
module.exports = glGot;
{
"name": "gl-got",
"version": "8.0.0",
"version": "9.0.0",
"description": "Convenience wrapper for `got` to interact with the GitLab API",

@@ -9,9 +9,13 @@ "license": "MIT",

"name": "Rhys Arkins",
"email": "rhys@keylocation.sg"
"email": "rhys@arkins.net"
},
"contributors": [
"Itai Steinherz <itaisteinherz@gmail.com>",
"Hutson Betts <hutson@hyper-expanse.net>"
],
"engines": {
"node": ">=4"
"node": ">=8"
},
"scripts": {
"test": "xo && nyc ava && nyc report --reporter=html"
"test": "xo && nyc --all --cache --include=index.js --exclude=test.js --reporter=lcov --reporter=text ava"
},

@@ -36,20 +40,11 @@ "files": [

"dependencies": {
"got": "^7.0.0",
"is-plain-obj": "^1.1.0"
"got": "^9.1.0"
},
"devDependencies": {
"ava": "0.20.0",
"get-stream": "3.0.0",
"ava": "^1.0.0-beta.7",
"get-stream": "^4.0.0",
"nock": "9.0.13",
"nyc": "11.0.1",
"prettier": "1.7.4",
"xo": "0.18.2"
"xo": "^0.22.0"
},
"prettier": {
"singleQuote": true,
"trailingComma": "es5"
},
"renovate": {
"automerge": "minor"
},
"xo": {

@@ -56,0 +51,0 @@ "esnext": true

@@ -70,6 +70,6 @@ # gl-got [![Build Status](https://travis-ci.org/singapore/gl-got.svg?branch=master)](https://travis-ci.org/singapore/gl-got)

### endpoint
### baseUrl
Type: `string`<br>
Default: `https://gitlab.com/api/v3/`
Default: `https://gitlab.com/api/v3`

@@ -76,0 +76,0 @@ Can be set globally with the `GITLAB_ENDPOINT` environment variable.

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc