gitlab.ts 1.48 KB
Newer Older
Rosanny Sihombing's avatar
updates  
Rosanny Sihombing committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import axios from 'axios'

var gitlab = {
    getProjects: async function(perPage:number, idAfter:number) {
        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 = []
            let pagesArr = []
            for(let i = 0; i < data.length; i++){
                // skip template project
                if (data[i].name == 'page_basic' || data[i].name == 'generic' || data[i].name == 'simple_raw' || data[i].name == 'simple_thesis') {
                    continue
                } else if(data[i].tag_list.includes('website')) {
                    pagesArr.push(data[i])
                } else {
                    reposArr.push(data[i])
                }
            }
            return {
                error: false,
                data: [reposArr, pagesArr]}
        }
        catch (err) {
            return {
                error: true,
                data: err}
        }
    },
    getLatestPipelineStatus: async function(projectId:number) {
        return axios({
            method: 'get',
            url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/'+projectId+'/pipelines'
        })
        .then(res => res.data[0].status)
        .catch(err => console.error(err))
    }
}

export = gitlab