1 | const https = require('https')
|
2 | const KOLKRABBI = 'https://kolkrabbi.herokuapp.com'
|
3 | const VERSION_HEADER = 'application/vnd.heroku+json; version=3.ci'
|
4 |
|
5 | function* pipelineCoupling (client, app) {
|
6 | return client.get(`/apps/${app}/pipeline-couplings`)
|
7 | }
|
8 |
|
9 | function* pipelineRepository (client, pipelineID) {
|
10 | return client.request({
|
11 | host: KOLKRABBI,
|
12 | path: `/pipelines/${pipelineID}/repository`,
|
13 | headers: {
|
14 | Authorization: `Bearer ${client.options.token}`
|
15 | }
|
16 | })
|
17 | }
|
18 |
|
19 | function* githubArchiveLink (client, user, repository, ref) {
|
20 | return client.request({
|
21 | host: KOLKRABBI,
|
22 | path: `/github/repos/${user}/${repository}/tarball/${ref}`,
|
23 | headers: {
|
24 | Authorization: `Bearer ${client.options.token}`
|
25 | }
|
26 | })
|
27 | }
|
28 |
|
29 | function* testRun (client, pipelineID, number) {
|
30 | return client.request({
|
31 | path: `/pipelines/${pipelineID}/test-runs/${number}`,
|
32 | headers: {
|
33 | Authorization: `Bearer ${client.options.token}`,
|
34 | Accept: VERSION_HEADER
|
35 | }
|
36 | })
|
37 | }
|
38 |
|
39 | function* testRuns (client, pipelineID) {
|
40 | return client.request({
|
41 | path: `/pipelines/${pipelineID}/test-runs`,
|
42 | headers: {
|
43 | Authorization: `Bearer ${client.options.token}`,
|
44 | Accept: VERSION_HEADER
|
45 | }
|
46 | })
|
47 | }
|
48 |
|
49 | function* latestTestRun (client, pipelineID) {
|
50 | const latestTestRuns = yield client.request({
|
51 | path: `/pipelines/${pipelineID}/test-runs`,
|
52 | headers: {
|
53 | Authorization: `Bearer ${client.options.token}`,
|
54 | Accept: VERSION_HEADER,
|
55 | Range: 'number ..; order=desc,max=1'
|
56 | }
|
57 | })
|
58 |
|
59 | return Promise.resolve(latestTestRuns[0])
|
60 | }
|
61 |
|
62 | function logStream (url, fn) {
|
63 | return https.get(url, fn)
|
64 | }
|
65 |
|
66 | function* createSource (client) {
|
67 | return yield client.post(`/sources`)
|
68 | }
|
69 |
|
70 | function* createTestRun (client, body) {
|
71 | const headers = {
|
72 | Accept: VERSION_HEADER
|
73 | }
|
74 |
|
75 | return client.request({
|
76 | headers: headers,
|
77 | method: 'POST',
|
78 | path: '/test-runs',
|
79 | body: body
|
80 | })
|
81 | }
|
82 |
|
83 | module.exports = {
|
84 | pipelineCoupling,
|
85 | pipelineRepository,
|
86 | githubArchiveLink,
|
87 | testRun,
|
88 | testRuns,
|
89 | latestTestRun,
|
90 | logStream,
|
91 | createSource,
|
92 | createTestRun
|
93 | }
|