From 4d8f6a1d4f4eb96b1ae969ea67e20b65f610d031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Wed, 19 Jul 2017 16:58:30 +0100 Subject: [PATCH] feat(portal-api): properly expose branches --- packages/portal-api/lib/data/index.js | 24 ++++++++++++++----- packages/portal-api/lib/data/transform.js | 4 ++-- .../portal-api/lib/watch/container-pilot.js | 7 +++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/packages/portal-api/lib/data/index.js b/packages/portal-api/lib/data/index.js index cf345ad5..70bb9c59 100644 --- a/packages/portal-api/lib/data/index.js +++ b/packages/portal-api/lib/data/index.js @@ -1455,13 +1455,15 @@ class Data extends EventEmitter { console.log(`-> Service ${Util.inspect(query)} found ${Util.inspect(service)}`); + const branches = service.branches.map((branch) => { + return Object.assign({}, branch, { + instances: this._instancesFilter(branch.instances) + }); + }); + return cb(null, Transform.fromService({ service, - branches: service.branches.map((service) => { - return Object.assign({}, service, { - instances: this._instancesFilter(service.instances) - }); - }), + branches, instances: this._instancesFilter(service.instance_ids) })); }); @@ -1517,7 +1519,17 @@ class Data extends EventEmitter { } return cb(null, services.map((service) => { - return Transform.fromService({ service, instances: this._instancesFilter(service.instance_ids) }); + const branches = service.branches.map((branch) => { + return Object.assign({}, branch, { + instances: this._instancesFilter(branch.instances) + }); + }); + + return Transform.fromService({ + service, + branches, + instances: this._instancesFilter(service.instance_ids) + }); })); }); } diff --git a/packages/portal-api/lib/data/transform.js b/packages/portal-api/lib/data/transform.js index 4631da57..666e6d25 100644 --- a/packages/portal-api/lib/data/transform.js +++ b/packages/portal-api/lib/data/transform.js @@ -63,7 +63,7 @@ exports.toDeploymentGroup = function (clientDeploymentGroup) { }; -exports.fromService = function ({ service, instances, packages }) { +exports.fromService = function ({ service, instances, branches, packages }) { return { id: service.id, hash: service.version_hash, @@ -72,7 +72,7 @@ exports.fromService = function ({ service, instances, packages }) { slug: service.slug, instances, connections: service.service_dependency_ids, - branches: service.branches, + branches: branches, config: service.config ? service.config : undefined, status: service.status, hasPlan: service.has_plan diff --git a/packages/portal-api/lib/watch/container-pilot.js b/packages/portal-api/lib/watch/container-pilot.js index cdd4c8f7..2111f59a 100644 --- a/packages/portal-api/lib/watch/container-pilot.js +++ b/packages/portal-api/lib/watch/container-pilot.js @@ -342,7 +342,8 @@ module.exports = class ContainerPilotWatcher extends Events { return serviceId; }, null); }) - .filter(Boolean); + .filter(Boolean) + .filter((serviceId) => service.id !== serviceId); } _resolveInstanceHealth ({ name }, instance) { @@ -377,6 +378,10 @@ module.exports = class ContainerPilotWatcher extends Events { } _resolveServiceBranches ({ name, slug, instances }) { + if (instances.length <= 1) { + return []; + } + const deviantJobNames = Uniq(Flatten(instances.map(({ jobs }) => { return Flatten(jobs.filter((jobName) => { return new RegExp(`${name}-.*`).test(jobName);