Commit f8f078aa authored by Rosanny Sihombing's avatar Rosanny Sihombing
Browse files

update gitlab API

parent a954d29e
......@@ -5,13 +5,36 @@ const fs = require('fs')
var formData = require('form-data')
var gitlab = {
getUserIdByEmail: function(email, callback) {
let dataConfig = {
method: 'get',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/users?search='+email,
headers: {
'Authorization': 'Bearer '+config.gitlab.token_readWriteProjects}
}
axios(dataConfig)
.then(function (response) {
let res = {
error: false,
data: response.data[0].id}
callback(res)
})
.catch(function (err) {
let res = {
error: true,
data: err}
callback(res)
})
},
// todo: fixing callback
createNewPages: function(newPagesdata, callback) {
let data = new formData()
data.append('avatar', fs.createReadStream(newPagesdata.avatar))
let dataConfig = {
method: 'post',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/user/'+newPagesdata.gitlabId+
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/user/'+newPagesdata.gitlabUserId+
'?name='+newPagesdata.name+'&description='+newPagesdata.description+'&tag_list=website'+
'&use_custom_template=true&template_name=page_basic',
headers: {
......@@ -20,6 +43,7 @@ var gitlab = {
},
data : data
}
axios(dataConfig)
.then(function (response) {
callback(response.data)
......@@ -27,7 +51,54 @@ var gitlab = {
.catch(function (err) {
if(err)
callback(err.response.data)
})
},
getUserProjects: function(gitlabUserId, callback) {
axios.get('https://transfer.hft-stuttgart.de/gitlab/api/v4/users/'+gitlabUserId+'/projects?private_token='+
config.gitlab.token_readWriteProjects+'&owned=true&simple=true&visibility=public')
.then(response => {
let res = {
error: false,
data: response.data}
callback(res)
})
.catch(err => {
let res = {
error: true,
data: err}
callback(res)
})
},
getProjectIdsFromRunners: function(gitlabUserId, callback) {
let projectIds = []
let dataConfig = {
method: 'get',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/runners/7',
headers: {
'Authorization': 'Bearer '+config.gitlab.token_readWriteProjects}
}
axios(dataConfig)
.then(function (response) {
let projects = response.data.projects
projects.forEach((project) => {
if(project.namespace.id == gitlabUserId) {
projectIds.push(project.id)
}
})
let res = {
error: false,
data: projectIds}
callback(res)
})
.catch(function (err) {
let res = {
error: true,
data: err}
callback(res)
});
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment