UNPKG

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