1 | const https = require('https')
|
2 | const KOLKRABBI = 'https://kolkrabbi.heroku.com'
|
3 | const V3_HEADER = 'application/vnd.heroku+json; version=3'
|
4 | const VERSION_HEADER = `${V3_HEADER}.ci`
|
5 | const PIPELINE_HEADER = `${V3_HEADER}.pipelines`
|
6 |
|
7 | function * pipelineCoupling (client, app) {
|
8 | return client.get(`/apps/${app}/pipeline-couplings`)
|
9 | }
|
10 |
|
11 | function * pipelineRepository (client, pipelineID) {
|
12 | return client.request({
|
13 | host: KOLKRABBI,
|
14 | path: `/pipelines/${pipelineID}/repository`,
|
15 | headers: {
|
16 | Authorization: `Bearer ${client.options.token}`
|
17 | }
|
18 | })
|
19 | }
|
20 |
|
21 | function * getDyno (client, appID, dynoID) {
|
22 | return client.request({
|
23 | path: `/apps/${appID}/dynos/${dynoID}`,
|
24 | headers: {
|
25 | Authorization: `Bearer ${client.options.token}`,
|
26 | Accept: VERSION_HEADER
|
27 | }
|
28 | })
|
29 | }
|
30 |
|
31 | function * githubArchiveLink (client, user, repository, ref) {
|
32 | return client.request({
|
33 | host: KOLKRABBI,
|
34 | path: `/github/repos/${user}/${repository}/tarball/${ref}`,
|
35 | headers: {
|
36 | Authorization: `Bearer ${client.options.token}`
|
37 | }
|
38 | })
|
39 | }
|
40 |
|
41 | function * testRun (client, pipelineID, number) {
|
42 | return client.request({
|
43 | path: `/pipelines/${pipelineID}/test-runs/${number}`,
|
44 | headers: {
|
45 | Authorization: `Bearer ${client.options.token}`,
|
46 | Accept: VERSION_HEADER
|
47 | }
|
48 | })
|
49 | }
|
50 |
|
51 | function * testNodes (client, testRunIdD) {
|
52 | return client.request({
|
53 | path: `/test-runs/${testRunIdD}/test-nodes`,
|
54 | headers: {
|
55 | Authorization: `Bearer ${client.options.token}`,
|
56 | Accept: VERSION_HEADER
|
57 | }
|
58 | })
|
59 | }
|
60 |
|
61 | function * testRuns (client, pipelineID) {
|
62 | return client.request({
|
63 | path: `/pipelines/${pipelineID}/test-runs`,
|
64 | headers: {
|
65 | Authorization: `Bearer ${client.options.token}`,
|
66 | Accept: VERSION_HEADER
|
67 | }
|
68 | })
|
69 | }
|
70 |
|
71 | function * latestTestRun (client, pipelineID) {
|
72 | const latestTestRuns = yield client.request({
|
73 | path: `/pipelines/${pipelineID}/test-runs`,
|
74 | headers: {
|
75 | Authorization: `Bearer ${client.options.token}`,
|
76 | Accept: VERSION_HEADER,
|
77 | Range: 'number ..; order=desc,max=1'
|
78 | }
|
79 | })
|
80 |
|
81 | return Promise.resolve(latestTestRuns[0])
|
82 | }
|
83 |
|
84 | function updateTestRun (client, id, body) {
|
85 | return client.request({
|
86 | body,
|
87 | method: 'PATCH',
|
88 | path: `/test-runs/${id}`,
|
89 | headers: {
|
90 | Accept: VERSION_HEADER
|
91 | }
|
92 | })
|
93 | }
|
94 |
|
95 | function logStream (url, fn) {
|
96 | return https.get(url, fn)
|
97 | }
|
98 |
|
99 | function * createSource (client) {
|
100 | return yield client.post(`/sources`)
|
101 | }
|
102 |
|
103 | function * createTestRun (client, body) {
|
104 | const headers = {
|
105 | Accept: VERSION_HEADER
|
106 | }
|
107 |
|
108 | return client.request({
|
109 | headers: headers,
|
110 | method: 'POST',
|
111 | path: '/test-runs',
|
112 | body: body
|
113 | })
|
114 | }
|
115 |
|
116 | function configVars (client, pipelineID) {
|
117 | return client.request({
|
118 | headers: { Accept: PIPELINE_HEADER },
|
119 | path: `/pipelines/${pipelineID}/stage/test/config-vars`
|
120 | })
|
121 | }
|
122 |
|
123 | function setConfigVars (client, pipelineID, body) {
|
124 | return client.request({
|
125 | method: 'PATCH',
|
126 | headers: { Accept: PIPELINE_HEADER },
|
127 | path: `/pipelines/${pipelineID}/stage/test/config-vars`,
|
128 | body
|
129 | })
|
130 | }
|
131 |
|
132 | function appSetup (client, id) {
|
133 | return client.get(`/app-setups/${id}`)
|
134 | }
|
135 |
|
136 | module.exports = {
|
137 | appSetup,
|
138 | configVars,
|
139 | createSource,
|
140 | createTestRun,
|
141 | getDyno,
|
142 | githubArchiveLink,
|
143 | latestTestRun,
|
144 | testNodes,
|
145 | testRun,
|
146 | testRuns,
|
147 | logStream,
|
148 | pipelineCoupling,
|
149 | pipelineRepository,
|
150 | setConfigVars,
|
151 | updateTestRun
|
152 | }
|