/
kolkrabbi-api.ts
76 lines (61 loc) · 1.71 KB
/
kolkrabbi-api.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import {HTTP} from 'http-call'
const KOLKRABBI_BASE_URL = 'https://kolkrabbi.heroku.com'
export default class {
version: any
getToken: () => any
constructor(version: any, getToken: () => any) {
this.version = version
this.getToken = getToken
}
request(url: string, options: any = {}) {
options.headers = {
Authorization: `Bearer ${this.getToken()}`,
'User-Agent': this.version,
}
if (['POST', 'PATCH', 'DELETE'].includes(options.method)) {
options.headers['Content-type'] = 'application/json'
}
return HTTP.request(KOLKRABBI_BASE_URL + url, options).then((res: any) => res.body)
}
getAccount() {
return this.request('/account/github/token')
}
createPipelineRepository(pipeline: any, repository: any) {
return this.request(`/pipelines/${pipeline}/repository`, {
method: 'POST',
body: {repository},
})
}
updatePipelineRepository(pipeline: any, body: any) {
return this.request(`/pipelines/${pipeline}/repository`, {
method: 'PATCH',
body,
})
}
updateAppLink(app: any, body: any) {
return this.request(`/apps/${app}/github`, {
method: 'PATCH',
body,
})
}
getAppLink(app: any) {
return this.request(`/apps/${app}/github`, {
method: 'GET',
})
}
getPipelineRepository(pipeline: any) {
return this.request(`/pipelines/${pipeline}/repository`, {
method: 'GET',
})
}
getPipelineGitHub(pipeline: any) {
return this.request(`/pipelines/${pipeline}/github`, {
method: 'GET',
})
}
getArchiveURL(repo: any, ref: any) {
return this.request(`/github/repos/${repo}/tarball/${ref}`, {
followRedirect: false,
}).then(res => res.archive_link)
}
}