gitlab.ts 1.48 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
import axios from 'axios'
2
3

var gitlab = {
Rosanny Sihombing's avatar
Rosanny Sihombing committed
4
    getProjects: async function(perPage:number, idAfter:number) {
5
6
7
8
9
10
11
12
13
14
        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
15
                if (data[i].name == 'page_basic' || data[i].name == 'generic' || data[i].name == 'simple_raw' || data[i].name == 'simple_thesis') {
16
17
18
                    continue
                } else if(data[i].tag_list.includes('website')) {
                    pagesArr.push(data[i])
19
20
                } else {
                    reposArr.push(data[i])
21
22
23
24
                }
            }
            return {
                error: false,
25
                data: [reposArr, pagesArr]}
26
27
28
29
30
31
32
        }
        catch (err) {
            return {
                error: true,
                data: err}
        }
    },
Rosanny Sihombing's avatar
Rosanny Sihombing committed
33
    getLatestPipelineStatus: async function(projectId:number) {
34
35
36
37
38
39
        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))
40
41
42
    }
}

Rosanny Sihombing's avatar
Rosanny Sihombing committed
43
export = gitlab