diff --git a/lib/platform/gitlab/gl-got-wrapper.js b/lib/platform/gitlab/gl-got-wrapper.js index 7f303a5aeec17470f990b97feccfd58d8428c935..b8eb1d24674e418e9f459adc6b72858ff3f93218 100644 --- a/lib/platform/gitlab/gl-got-wrapper.js +++ b/lib/platform/gitlab/gl-got-wrapper.js @@ -1,27 +1,18 @@ -const URL = require('url'); const parseLinkHeader = require('parse-link-header'); -const hostRules = require('../../util/host-rules'); const got = require('../../util/got'); +const hostType = 'gitlab'; let baseUrl = 'https://gitlab.com/api/v4/'; async function get(path, options) { - const url = URL.resolve(baseUrl, path); const opts = { - ...options, - ...hostRules.find({ hostType: 'gitlab', url }), + hostType, + baseUrl, json: true, + ...options, }; - if (opts.token) { - opts.headers = { - ...opts.headers, - 'PRIVATE-TOKEN': opts.token, - }; - delete opts.token; - } - delete opts.endpoint; - const res = await got(url, opts); + const res = await got(path, opts); if (opts.paginate) { // Check if result is paginated try { diff --git a/lib/util/got/auth.js b/lib/util/got/auth.js index f2840e00485160723716ebb075817bd5a5a7640c..ad2b833a3e23c498769efa5ef298b6c55be37583 100644 --- a/lib/util/got/auth.js +++ b/lib/util/got/auth.js @@ -4,7 +4,7 @@ const got = require('got'); module.exports = got.create({ options: {}, handler: (options, next) => { - if (options.headers.authorization || options.auth) { + if (options.auth || options.headers.authorization) { return next(options); } if (options.token) { @@ -12,11 +12,13 @@ module.exports = got.create({ { hostname: options.hostname }, 'Converting token to Bearer auth' ); - let authHeader = `Bearer ${options.token}`; if (options.hostType === 'github') { - authHeader = `token ${options.token}`; // it seems to work with Bearer too, but docs say to use token + options.headers.authorization = `token ${options.token}`; // eslint-disable-line no-param-reassign + } else if (options.hostType === 'gitlab') { + options.headers['Private-token'] = options.token; // eslint-disable-line no-param-reassign + } else { + options.headers.authorization = `Bearer ${options.token}`; // eslint-disable-line no-param-reassign } - options.headers.authorization = authHeader; // eslint-disable-line no-param-reassign delete options.token; // eslint-disable-line no-param-reassign } return next(options);