From 66d374b1289e6dd33008dc931e9fb642051724d0 Mon Sep 17 00:00:00 2001 From: Cédric Couralet Date: Mon, 30 Jul 2018 13:47:09 +0000 Subject: Add possibility to choose between version v3 or v4 for the gitlab api. Apart from the uri versioning, one big change is the snippet visibility post data (visibility_level -> visibility) Default gitlab api version to v4 Signed-off-by: Cédric Couralet --- lib/config/index.js | 6 ++++++ lib/response.js | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/config/index.js b/lib/config/index.js index ac03fcd4..e66c513d 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -103,6 +103,12 @@ config.isSAMLEnable = config.saml.idpSsoUrl config.isOAuth2Enable = config.oauth2.clientID && config.oauth2.clientSecret config.isPDFExportEnable = config.allowPDFExport +// Check gitlab api version +if (config.gitlab.version !== 'v4' || config.gitlab.version !== 'v3') { + logger.warn('config.js contains wrong version (' + config.gitlab.version + ') for gitlab api; it should be \'v3\' or \'v4\'. Defaulting to v3') + config.gitlab.version = 'v4' +} + // Only update i18n files in development setups config.updateI18nFiles = (env === Environment.development) diff --git a/lib/response.js b/lib/response.js index 3a31c511..37211998 100644 --- a/lib/response.js +++ b/lib/response.js @@ -573,11 +573,11 @@ function gitlabActionProjects (req, res, note) { } }).then(function (user) { if (!user) { return response.errorNotFound(res) } - var ret = { baseURL: config.gitlab.baseURL } + var ret = { baseURL: config.gitlab.baseURL, version: config.gitlab.version } ret.accesstoken = user.accessToken ret.profileid = user.profileid request( - config.gitlab.baseURL + '/api/v3/projects?access_token=' + user.accessToken, + config.gitlab.baseURL + '/api/' + config.gitlab.version + '/projects?access_token=' + user.accessToken, function (error, httpResponse, body) { if (!error && httpResponse.statusCode === 200) { ret.projects = JSON.parse(body) -- cgit v1.2.3