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

Rosanny Sihombing's avatar
Rosanny Sihombing committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const gitlab = {
  getProjects: async function (perPage: number, idAfter: number) {
    try {
      const projects = await axios({
        method: 'get',
        url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects?visibility=public&pagination=keyset&per_page=' + String(perPage) + '&order_by=id&sort=asc&id_after=' + String(idAfter)
      })
      const data = projects.data
      const reposArr = []
      const 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])
Rosanny Sihombing's avatar
updates  
Rosanny Sihombing committed
21
        }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
22
23
24
25
26
27
28
29
30
31
      }
      return {
        error: false,
        data: [reposArr, pagesArr]
      }
    } catch (err) {
      return {
        error: true,
        data: err
      }
Rosanny Sihombing's avatar
updates  
Rosanny Sihombing committed
32
    }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
33
34
35
36
37
38
39
40
41
  },
  getLatestPipelineStatus: async function (projectId: number) {
    return await axios({
      method: 'get',
      url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/' + String(projectId) + '/pipelines'
    })
      .then(res => res.data[0].status)
      .catch(err => console.error(err))
  }
Rosanny Sihombing's avatar
updates  
Rosanny Sihombing committed
42
43
}

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