1 | const cli = require('heroku-cli-util')
|
2 | const KOLKRABBI_BASE_URL = 'https://kolkrabbi.heroku.com'
|
3 |
|
4 | module.exports = class KolkrabbiAPI {
|
5 | constructor (version, token) {
|
6 | this.version = version
|
7 | this.token = token
|
8 | }
|
9 |
|
10 | request (url, options = {}) {
|
11 | if (options.body) {
|
12 | options.body = JSON.stringify(options.body)
|
13 | }
|
14 |
|
15 | options.headers = Object.assign({
|
16 | Authorization: `Bearer ${this.token}`,
|
17 | 'User-Agent': this.version
|
18 | })
|
19 |
|
20 | if (['POST', 'PATCH', 'DELETE'].includes(options.method)) {
|
21 | options.headers['Content-type'] = 'application/json'
|
22 | }
|
23 |
|
24 | options.json = true
|
25 |
|
26 | return cli.got(KOLKRABBI_BASE_URL + url, options).then((res) => res.body)
|
27 | }
|
28 |
|
29 | getAccount () {
|
30 | return this.request('/account/github/token')
|
31 | }
|
32 |
|
33 | createPipelineRepository (pipeline, repository) {
|
34 | return this.request(`/pipelines/${pipeline}/repository`, {
|
35 | method: 'POST',
|
36 | body: { repository }
|
37 | })
|
38 | }
|
39 |
|
40 | updatePipelineRepository (pipeline, body) {
|
41 | return this.request(`/pipelines/${pipeline}/repository`, {
|
42 | method: 'PATCH',
|
43 | body
|
44 | })
|
45 | }
|
46 |
|
47 | updateAppLink (app, body) {
|
48 | return this.request(`/apps/${app}/github`, {
|
49 | method: 'PATCH',
|
50 | body
|
51 | })
|
52 | }
|
53 | }
|