Merge pull request #908 from micedre/gitlabV4

Add possibility to choose between version v3 or v4 for the gitlab api.
This commit is contained in:
Christoph (Sheogorath) Kern 2018-07-31 10:55:08 +02:00 committed by GitHub
commit 881ca88c51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 9 deletions

View file

@ -194,6 +194,7 @@ There are some config settings you need to change in the files below.
| `CMD_GITLAB_BASEURL` | no example | GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional) | | `CMD_GITLAB_BASEURL` | no example | GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional) |
| `CMD_GITLAB_CLIENTID` | no example | GitLab API client id | | `CMD_GITLAB_CLIENTID` | no example | GitLab API client id |
| `CMD_GITLAB_CLIENTSECRET` | no example | GitLab API client secret | | `CMD_GITLAB_CLIENTSECRET` | no example | GitLab API client secret |
| `CMD_GITLAB_VERSION` | no example | GitLab API version (v3 or v4) |
| `CMD_MATTERMOST_BASEURL` | no example | Mattermost authentication endpoint | | `CMD_MATTERMOST_BASEURL` | no example | Mattermost authentication endpoint |
| `CMD_MATTERMOST_CLIENTID` | no example | Mattermost API client id | | `CMD_MATTERMOST_CLIENTID` | no example | Mattermost API client id |
| `CMD_MATTERMOST_CLIENTSECRET` | no example | Mattermost API client secret | | `CMD_MATTERMOST_CLIENTSECRET` | no example | Mattermost API client secret |

View file

@ -55,7 +55,8 @@
"baseURL": "change this", "baseURL": "change this",
"clientID": "change this", "clientID": "change this",
"clientSecret": "change this", "clientSecret": "change this",
"scope": "use 'read_user' scope for auth user only or remove this property if you need gitlab snippet import/export support (will result to be default scope 'api')" "scope": "use 'read_user' scope for auth user only or remove this property if you need gitlab snippet import/export support (will result to be default scope 'api')",
"version": "use 'v4' if gitlab version > 11, 'v3' otherwise. Default to 'v4'"
}, },
"mattermost": { "mattermost": {
"baseURL": "change this", "baseURL": "change this",

View file

@ -103,6 +103,12 @@ config.isSAMLEnable = config.saml.idpSsoUrl
config.isOAuth2Enable = config.oauth2.clientID && config.oauth2.clientSecret config.isOAuth2Enable = config.oauth2.clientID && config.oauth2.clientSecret
config.isPDFExportEnable = config.allowPDFExport 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 // Only update i18n files in development setups
config.updateI18nFiles = (env === Environment.development) config.updateI18nFiles = (env === Environment.development)

View file

@ -573,11 +573,11 @@ function gitlabActionProjects (req, res, note) {
} }
}).then(function (user) { }).then(function (user) {
if (!user) { return response.errorNotFound(res) } 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.accesstoken = user.accessToken
ret.profileid = user.profileid ret.profileid = user.profileid
request( 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) { function (error, httpResponse, body) {
if (!error && httpResponse.statusCode === 200) { if (!error && httpResponse.statusCode === 200) {
ret.projects = JSON.parse(body) ret.projects = JSON.parse(body)

View file

@ -970,6 +970,7 @@ ui.toolbar.export.snippet.click(function () {
.done(function (data) { .done(function (data) {
$('#snippetExportModalAccessToken').val(data.accesstoken) $('#snippetExportModalAccessToken').val(data.accesstoken)
$('#snippetExportModalBaseURL').val(data.baseURL) $('#snippetExportModalBaseURL').val(data.baseURL)
$('#snippetExportModalVersion').val(data.version)
$('#snippetExportModalLoading').hide() $('#snippetExportModalLoading').hide()
$('#snippetExportModal').modal('toggle') $('#snippetExportModal').modal('toggle')
$('#snippetExportModalProjects').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Projects</option>') $('#snippetExportModalProjects').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Projects</option>')
@ -1021,6 +1022,7 @@ ui.toolbar.import.snippet.click(function () {
.done(function (data) { .done(function (data) {
$('#snippetImportModalAccessToken').val(data.accesstoken) $('#snippetImportModalAccessToken').val(data.accesstoken)
$('#snippetImportModalBaseURL').val(data.baseURL) $('#snippetImportModalBaseURL').val(data.baseURL)
$('#snippetImportModalVersion').val(data.version)
$('#snippetImportModalContent').prop('disabled', false) $('#snippetImportModalContent').prop('disabled', false)
$('#snippetImportModalConfirm').prop('disabled', false) $('#snippetImportModalConfirm').prop('disabled', false)
$('#snippetImportModalLoading').hide() $('#snippetImportModalLoading').hide()
@ -1243,10 +1245,10 @@ ui.modal.snippetImportProjects.change(function () {
var accesstoken = $('#snippetImportModalAccessToken').val() var accesstoken = $('#snippetImportModalAccessToken').val()
var baseURL = $('#snippetImportModalBaseURL').val() var baseURL = $('#snippetImportModalBaseURL').val()
var project = $('#snippetImportModalProjects').val() var project = $('#snippetImportModalProjects').val()
var version = $('#snippetImportModalVersion').val()
$('#snippetImportModalLoading').show() $('#snippetImportModalLoading').show()
$('#snippetImportModalContent').val('/projects/' + project) $('#snippetImportModalContent').val('/projects/' + project)
$.get(baseURL + '/api/v3/projects/' + project + '/snippets?access_token=' + accesstoken) $.get(baseURL + '/api/' + version + '/projects/' + project + '/snippets?access_token=' + accesstoken)
.done(function (data) { .done(function (data) {
$('#snippetImportModalSnippets').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Snippets</option>') $('#snippetImportModalSnippets').find('option').remove().end().append('<option value="init" selected="selected" disabled="disabled">Select From Available Snippets</option>')
data.forEach(function (snippet) { data.forEach(function (snippet) {
@ -1433,7 +1435,7 @@ $('#snippetImportModalConfirm').click(function () {
} else { } else {
ui.spinner.show() ui.spinner.show()
var accessToken = '?access_token=' + $('#snippetImportModalAccessToken').val() var accessToken = '?access_token=' + $('#snippetImportModalAccessToken').val()
var fullURL = $('#snippetImportModalBaseURL').val() + '/api/v3' + snippeturl var fullURL = $('#snippetImportModalBaseURL').val() + '/api/' + $('#snippetImportModalVersion').val() + snippeturl
$.get(fullURL + accessToken) $.get(fullURL + accessToken)
.done(function (data) { .done(function (data) {
var content = '# ' + (data.title || 'Snippet Import') var content = '# ' + (data.title || 'Snippet Import')
@ -1470,15 +1472,19 @@ $('#snippetImportModalConfirm').click(function () {
$('#snippetExportModalConfirm').click(function () { $('#snippetExportModalConfirm').click(function () {
var accesstoken = $('#snippetExportModalAccessToken').val() var accesstoken = $('#snippetExportModalAccessToken').val()
var baseURL = $('#snippetExportModalBaseURL').val() var baseURL = $('#snippetExportModalBaseURL').val()
var version = $('#snippetExportModalVersion').val()
var data = { var data = {
title: $('#snippetExportModalTitle').val(), title: $('#snippetExportModalTitle').val(),
file_name: $('#snippetExportModalFileName').val(), file_name: $('#snippetExportModalFileName').val(),
code: editor.getValue(), code: editor.getValue(),
visibility_level: $('#snippetExportModalVisibility').val() visibility_level: $('#snippetExportModalVisibility').val(),
visibility: $('#snippetExportModalVisibility').val() === 0 ? 'private' : ($('#snippetExportModalVisibility').val() === 10 ? 'internal' : '')
} }
if (!data.title || !data.file_name || !data.code || !data.visibility_level || !$('#snippetExportModalProjects').val()) return if (!data.title || !data.file_name || !data.code || !data.visibility_level || !$('#snippetExportModalProjects').val()) return
$('#snippetExportModalLoading').show() $('#snippetExportModalLoading').show()
var fullURL = baseURL + '/api/v3/projects/' + $('#snippetExportModalProjects').val() + '/snippets?access_token=' + accesstoken var fullURL = baseURL + '/api/' + version + '/projects/' + $('#snippetExportModalProjects').val() + '/snippets?access_token=' + accesstoken
$.post(fullURL $.post(fullURL
, data , data
, function (ret) { , function (ret) {
@ -1487,7 +1493,6 @@ $('#snippetExportModalConfirm').click(function () {
var redirect = baseURL + '/' + $("#snippetExportModalProjects option[value='" + $('#snippetExportModalProjects').val() + "']").text() + '/snippets/' + ret.id var redirect = baseURL + '/' + $("#snippetExportModalProjects option[value='" + $('#snippetExportModalProjects').val() + "']").text() + '/snippets/' + ret.id
showMessageModal('<i class="fa fa-gitlab"></i> Export to Snippet', 'Export Successful!', redirect, 'View Snippet Here', true) showMessageModal('<i class="fa fa-gitlab"></i> Export to Snippet', 'Export Successful!', redirect, 'View Snippet Here', true)
} }
, 'json'
) )
}) })

View file

@ -153,6 +153,7 @@
<div class="modal-body"> <div class="modal-body">
<input type="hidden" id="snippetImportModalAccessToken" /> <input type="hidden" id="snippetImportModalAccessToken" />
<input type="hidden" id="snippetImportModalBaseURL" /> <input type="hidden" id="snippetImportModalBaseURL" />
<input type="hidden" id="snippetImportModalVersion" />
<div class="ui-field-contain" style="display:table;margin-bottom:10px;width:100%;"> <div class="ui-field-contain" style="display:table;margin-bottom:10px;width:100%;">
<div style="display:table-row;margin-bottom:5px;"> <div style="display:table-row;margin-bottom:5px;">
<label style="display:table-cell;">Project:</label> <label style="display:table-cell;">Project:</label>
@ -191,6 +192,7 @@
<div class="modal-body"> <div class="modal-body">
<input type="hidden" id="snippetExportModalAccessToken" /> <input type="hidden" id="snippetExportModalAccessToken" />
<input type="hidden" id="snippetExportModalBaseURL" /> <input type="hidden" id="snippetExportModalBaseURL" />
<input type="hidden" id="snippetExportModalVersion" />
<div class="ui-field-contain" style="display:table;margin-bottom:10px;width:100%;"> <div class="ui-field-contain" style="display:table;margin-bottom:10px;width:100%;">
<div style="display:table-row;margin-bottom:5px;"> <div style="display:table-row;margin-bottom:5px;">
<label style="display:table-cell;">Title:</label> <label style="display:table-cell;">Title:</label>