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* githubArchiveLink (client, user, repository, ref) {
|
22 | return client.request({
|
23 | host: KOLKRABBI,
|
24 | path: `/github/repos/${user}/${repository}/tarball/${ref}`,
|
25 | headers: {
|
26 | Authorization: `Bearer ${client.options.token}`
|
27 | }
|
28 | })
|
29 | }
|
30 |
|
31 | function* testRun (client, pipelineID, number) {
|
32 | return client.request({
|
33 | path: `/pipelines/${pipelineID}/test-runs/${number}`,
|
34 | headers: {
|
35 | Authorization: `Bearer ${client.options.token}`,
|
36 | Accept: VERSION_HEADER
|
37 | }
|
38 | })
|
39 | }
|
40 |
|
41 | function* testNodes (client, testRunIdD) {
|
42 | return client.request({
|
43 | path: `/test-runs/${testRunIdD}/test-nodes`,
|
44 | headers: {
|
45 | Authorization: `Bearer ${client.options.token}`,
|
46 | Accept: VERSION_HEADER
|
47 | }
|
48 | })
|
49 | }
|
50 |
|
51 | function* testRuns (client, pipelineID) {
|
52 | return client.request({
|
53 | path: `/pipelines/${pipelineID}/test-runs`,
|
54 | headers: {
|
55 | Authorization: `Bearer ${client.options.token}`,
|
56 | Accept: VERSION_HEADER
|
57 | }
|
58 | })
|
59 | }
|
60 |
|
61 | function* latestTestRun (client, pipelineID) {
|
62 | const latestTestRuns = yield client.request({
|
63 | path: `/pipelines/${pipelineID}/test-runs`,
|
64 | headers: {
|
65 | Authorization: `Bearer ${client.options.token}`,
|
66 | Accept: VERSION_HEADER,
|
67 | Range: 'number ..; order=desc,max=1'
|
68 | }
|
69 | })
|
70 |
|
71 | return Promise.resolve(latestTestRuns[0])
|
72 | }
|
73 |
|
74 | function updateTestRun (client, id, body) {
|
75 | return client.request({
|
76 | body,
|
77 | method: 'PATCH',
|
78 | path: `/test-runs/${id}`,
|
79 | headers: {
|
80 | Accept: VERSION_HEADER
|
81 | }
|
82 | })
|
83 | }
|
84 |
|
85 | function logStream (url, fn) {
|
86 | return https.get(url, fn)
|
87 | }
|
88 |
|
89 | function* createSource (client) {
|
90 | return yield client.post(`/sources`)
|
91 | }
|
92 |
|
93 | function* createTestRun (client, body) {
|
94 | const headers = {
|
95 | Accept: VERSION_HEADER
|
96 | }
|
97 |
|
98 | return client.request({
|
99 | headers: headers,
|
100 | method: 'POST',
|
101 | path: '/test-runs',
|
102 | body: body
|
103 | })
|
104 | }
|
105 |
|
106 | function configVars (client, pipelineID) {
|
107 | return client.request({
|
108 | headers: { Accept: PIPELINE_HEADER },
|
109 | path: `/pipelines/${pipelineID}/stage/test/config-vars`
|
110 | })
|
111 | }
|
112 |
|
113 | function setConfigVars (client, pipelineID, body) {
|
114 | return client.request({
|
115 | method: 'PATCH',
|
116 | headers: { Accept: PIPELINE_HEADER },
|
117 | path: `/pipelines/${pipelineID}/stage/test/config-vars`,
|
118 | body
|
119 | })
|
120 | }
|
121 |
|
122 | function appSetup (client, id) {
|
123 | return client.get(`/app-setups/${id}`)
|
124 | }
|
125 |
|
126 | module.exports = {
|
127 | appSetup,
|
128 | configVars,
|
129 | createSource,
|
130 | createTestRun,
|
131 | githubArchiveLink,
|
132 | latestTestRun,
|
133 | testNodes,
|
134 | testRun,
|
135 | testRuns,
|
136 | logStream,
|
137 | pipelineCoupling,
|
138 | pipelineRepository,
|
139 | setConfigVars,
|
140 | updateTestRun
|
141 | }
|