1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const lodash_keyby_1 = tslib_1.__importDefault(require("lodash.keyby"));
|
5 | exports.V3_HEADER = 'application/vnd.heroku+json; version=3';
|
6 | exports.FILTERS_HEADER = `${exports.V3_HEADER}.filters`;
|
7 | exports.PIPELINES_HEADER = `${exports.V3_HEADER}.pipelines`;
|
8 | function createAppSetup(heroku, body) {
|
9 | return heroku.post('/app-setups', { body });
|
10 | }
|
11 | exports.createAppSetup = createAppSetup;
|
12 | function postCoupling(heroku, pipeline, app, stage) {
|
13 | return heroku.post('/pipeline-couplings', {
|
14 | body: { app, pipeline, stage },
|
15 | });
|
16 | }
|
17 | exports.postCoupling = postCoupling;
|
18 | function createCoupling(heroku, pipeline, app, stage) {
|
19 | return postCoupling(heroku, pipeline.id, app, stage);
|
20 | }
|
21 | exports.createCoupling = createCoupling;
|
22 | function createPipeline(heroku, name, owner) {
|
23 | return heroku.request('/pipelines', {
|
24 | method: 'POST',
|
25 | headers: { Accept: exports.PIPELINES_HEADER },
|
26 | body: { name, owner },
|
27 | });
|
28 | }
|
29 | exports.createPipeline = createPipeline;
|
30 | function createPipelineTransfer(heroku, pipeline) {
|
31 | return heroku.post('/pipeline-transfers', {
|
32 | body: pipeline,
|
33 | });
|
34 | }
|
35 | exports.createPipelineTransfer = createPipelineTransfer;
|
36 | function deleteCoupling(heroku, id) {
|
37 | return heroku.delete(`/pipeline-couplings/${id}`);
|
38 | }
|
39 | function destroyPipeline(heroku, name, pipelineId) {
|
40 | return heroku.request(`/pipelines/${pipelineId}`, {
|
41 | method: 'DELETE',
|
42 | headers: { Accept: exports.PIPELINES_HEADER },
|
43 | body: { name },
|
44 | });
|
45 | }
|
46 | exports.destroyPipeline = destroyPipeline;
|
47 | function findPipelineByName(heroku, idOrName) {
|
48 | return heroku.request(`/pipelines?eq[name]=${idOrName}`, {
|
49 | method: 'GET',
|
50 | headers: { Accept: exports.PIPELINES_HEADER },
|
51 | });
|
52 | }
|
53 | exports.findPipelineByName = findPipelineByName;
|
54 | function getCoupling(heroku, app) {
|
55 | return heroku.get(`/apps/${app}/pipeline-couplings`);
|
56 | }
|
57 | exports.getCoupling = getCoupling;
|
58 | function getPipeline(heroku, id) {
|
59 | return heroku.request(`/pipelines/${id}`, {
|
60 | method: 'GET',
|
61 | headers: { Accept: exports.PIPELINES_HEADER },
|
62 | });
|
63 | }
|
64 | exports.getPipeline = getPipeline;
|
65 | function updatePipeline(heroku, id, body) {
|
66 | return heroku.patch(`/pipelines/${id}`, {
|
67 | body,
|
68 | });
|
69 | }
|
70 | exports.updatePipeline = updatePipeline;
|
71 |
|
72 |
|
73 |
|
74 | function getTeam(heroku, teamId) {
|
75 | return heroku.get(`/teams/${teamId}`);
|
76 | }
|
77 | exports.getTeam = getTeam;
|
78 | function getAppFilter(heroku, appIds) {
|
79 | return heroku.request('/filters/apps', {
|
80 | method: 'POST',
|
81 | headers: { Accept: exports.FILTERS_HEADER },
|
82 | body: { in: { id: appIds } },
|
83 | });
|
84 | }
|
85 | function getAccountInfo(heroku, id = '~') {
|
86 | return heroku.get(`/users/${id}`);
|
87 | }
|
88 | exports.getAccountInfo = getAccountInfo;
|
89 | function getAppSetup(heroku, buildId) {
|
90 | return heroku.get(`/app-setups/${buildId}`);
|
91 | }
|
92 | exports.getAppSetup = getAppSetup;
|
93 | function listCouplings(heroku, pipelineId) {
|
94 | return heroku.get(`/pipelines/${pipelineId}/pipeline-couplings`);
|
95 | }
|
96 | function listPipelineApps(heroku, pipelineId) {
|
97 | return listCouplings(heroku, pipelineId).then(({ body: couplings }) => {
|
98 | const appIds = couplings.map(coupling => (coupling.app && coupling.app.id) || '');
|
99 | return getAppFilter(heroku, appIds).then(({ body: apps }) => {
|
100 | const couplingsByAppId = lodash_keyby_1.default(couplings, coupling => coupling.app && coupling.app.id);
|
101 | return apps.map(app => {
|
102 | return Object.assign(Object.assign({}, app), { coupling: couplingsByAppId[app.id] });
|
103 | });
|
104 | });
|
105 | });
|
106 | }
|
107 | exports.listPipelineApps = listPipelineApps;
|
108 | function patchCoupling(heroku, id, stage) {
|
109 | return heroku.patch(`/pipeline-couplings/${id}`, { body: { stage } });
|
110 | }
|
111 | exports.patchCoupling = patchCoupling;
|
112 | function removeCoupling(heroku, app) {
|
113 | return getCoupling(heroku, app)
|
114 | .then(({ body }) => {
|
115 | return deleteCoupling(heroku, body.id);
|
116 | });
|
117 | }
|
118 | exports.removeCoupling = removeCoupling;
|
119 | function updateCoupling(heroku, app, stage) {
|
120 | return getCoupling(heroku, app)
|
121 | .then(({ body: coupling }) => patchCoupling(heroku, coupling.id, stage));
|
122 | }
|
123 | exports.updateCoupling = updateCoupling;
|
124 | function getReleases(heroku, appId) {
|
125 | return heroku.get(`/apps/${appId}/releases`, {
|
126 | headers: { Accept: exports.V3_HEADER, Range: 'version ..; order=desc' },
|
127 | partial: true,
|
128 | });
|
129 | }
|
130 | exports.getReleases = getReleases;
|