var env = process.env.NODE_ENV || 'testing' const config = require('../config/config')[env] const axios = require('axios') var gitlab = { getRepos: async function(perPage, idAfter) { try { let projects = await axios({ method: 'get', url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects?visibility=public&pagination=keyset&per_page='+perPage+'&order_by=id&sort=asc&id_after='+idAfter }) let data = projects.data let reposArr = [] for(let i = 0; i < data.length; i++){ // skip template project if (data[i].name == 'template_gitlab_page') { continue } else if(!data[i].tag_list.includes('website')) { reposArr.push(data[i]) } } return { error: false, data: reposArr} } catch (err) { return { error: true, data: err} } }, getPages: async function(perPage, idAfter) { try { let projects = await axios({ method: 'get', url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects?visibility=public&pagination=keyset&per_page='+perPage+'&order_by=id&sort=asc&id_after='+idAfter }) let data = projects.data let pagesArr = [] for(let i = 0; i < data.length; i++){ // skip template project if (data[i].name == 'template_gitlab_page') { continue } else if(data[i].tag_list.includes('website')) { pagesArr.push(data[i]) } } return { error: false, data: pagesArr} } catch (err) { return { error: true, data: err} } }, getProjectsFromRunners: async function() { try { let runner = await axios({ method: 'get', url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/runners/7', headers: { 'Authorization': 'Bearer '+config.gitlab.token_readWriteProjects } }) let runnerProjects = runner.data.projects return { error: false, data: runnerProjects } } catch (err) { return { error: true, data: err} } } } module.exports = gitlab