UNPKG

2.07 kBJavaScriptView Raw
1const https = require('https')
2const KOLKRABBI = 'https://kolkrabbi.herokuapp.com'
3const VERSION_HEADER = 'application/vnd.heroku+json; version=3.ci'
4
5function* pipelineCoupling (client, app) {
6 return client.get(`/apps/${app}/pipeline-couplings`)
7}
8
9function* 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
19function* 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
29function* 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
39function* 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
49function* 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
62function logStream (url, fn) {
63 return https.get(url, fn)
64}
65
66function* createSource (client) {
67 return yield client.post(`/sources`)
68}
69
70function* 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
83module.exports = {
84 pipelineCoupling,
85 pipelineRepository,
86 githubArchiveLink,
87 testRun,
88 testRuns,
89 latestTestRun,
90 logStream,
91 createSource,
92 createTestRun
93}