1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const http_call_1 = require("http-call");
|
4 | const KOLKRABBI_BASE_URL = 'https://kolkrabbi.heroku.com';
|
5 | class default_1 {
|
6 | constructor(version, getToken) {
|
7 | this.version = version;
|
8 | this.getToken = getToken;
|
9 | }
|
10 | request(url, options = {}) {
|
11 | options.headers = {
|
12 | Authorization: `Bearer ${this.getToken()}`,
|
13 | 'User-Agent': this.version,
|
14 | };
|
15 | if (['POST', 'PATCH', 'DELETE'].includes(options.method)) {
|
16 | options.headers['Content-type'] = 'application/json';
|
17 | }
|
18 | return http_call_1.HTTP.request(KOLKRABBI_BASE_URL + url, options).then((res) => res.body);
|
19 | }
|
20 | getAccount() {
|
21 | return this.request('/account/github/token');
|
22 | }
|
23 | createPipelineRepository(pipeline, repository) {
|
24 | return this.request(`/pipelines/${pipeline}/repository`, {
|
25 | method: 'POST',
|
26 | body: { repository },
|
27 | });
|
28 | }
|
29 | updatePipelineRepository(pipeline, body) {
|
30 | return this.request(`/pipelines/${pipeline}/repository`, {
|
31 | method: 'PATCH',
|
32 | body,
|
33 | });
|
34 | }
|
35 | updateAppLink(app, body) {
|
36 | return this.request(`/apps/${app}/github`, {
|
37 | method: 'PATCH',
|
38 | body,
|
39 | });
|
40 | }
|
41 | getAppLink(app) {
|
42 | return this.request(`/apps/${app}/github`, {
|
43 | method: 'GET',
|
44 | });
|
45 | }
|
46 | getPipelineRepository(pipeline) {
|
47 | return this.request(`/pipelines/${pipeline}/repository`, {
|
48 | method: 'GET',
|
49 | });
|
50 | }
|
51 | getPipelineGithub(pipeline) {
|
52 | return this.request(`/pipelines/${pipeline}/github`, {
|
53 | method: 'GET',
|
54 | });
|
55 | }
|
56 | getArchiveURL(repo, ref) {
|
57 | return this.request(`/github/repos/${repo}/tarball/${ref}`, {
|
58 | followRedirect: false,
|
59 | }).then(res => res.archive_link);
|
60 | }
|
61 | }
|
62 | exports.default = default_1;
|