From 00a9f0addc4ccb56f913dec85f2dc076fc2d445c Mon Sep 17 00:00:00 2001 From: Dayanand Sagar Date: Mon, 23 Sep 2024 10:10:41 -0700 Subject: [PATCH] fix(3203): Deep merge build meta into event meta (#3204) --- plugins/builds/update.js | 3 ++- test/plugins/builds.test.js | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/plugins/builds/update.js b/plugins/builds/update.js index 161627ce3..6ea40a5f9 100644 --- a/plugins/builds/update.js +++ b/plugins/builds/update.js @@ -5,6 +5,7 @@ const hoek = require('@hapi/hoek'); const schema = require('screwdriver-data-schema'); const joi = require('joi'); const idSchema = schema.models.build.base.extract('id'); +const merge = require('lodash.mergewith'); const { getScmUri, getUserPermissions, getFullStageJobName } = require('../helper'); const STAGE_TEARDOWN_PATTERN = /^stage@([\w-]+)(?::teardown)$/; const TERMINAL_STATUSES = ['FAILURE', 'ABORTED', 'UNSTABLE', 'COLLAPSED']; @@ -247,7 +248,7 @@ module.exports = () => ({ build.statusMessage = statusMessage || build.statusMessage; } else if (['SUCCESS', 'FAILURE', 'ABORTED'].includes(desiredStatus)) { build.meta = request.payload.meta || {}; - event.meta = { ...event.meta, ...build.meta }; + merge(event.meta, build.meta); build.endTime = new Date().toISOString(); } else if (desiredStatus === 'RUNNING') { build.startTime = new Date().toISOString(); diff --git a/test/plugins/builds.test.js b/test/plugins/builds.test.js index fc2aa2c1c..728d722f2 100644 --- a/test/plugins/builds.test.js +++ b/test/plugins/builds.test.js @@ -1078,10 +1078,6 @@ describe('build plugin test', () => { }); it('saves status, statusMessage, meta updates, and merge event meta', () => { - const meta = { - foo: 'bar', - hello: 'bye' - }; const status = 'SUCCESS'; const statusMessage = 'Oh the build passed'; const options = { @@ -1095,7 +1091,14 @@ describe('build plugin test', () => { strategy: ['token'] }, payload: { - meta, + meta: { + foo: 'bar', + hello: 'bye', + deployedAppVersion: { + ui: '2.4.67', + api: '6.9.5' + } + }, status, statusMessage, stats: { @@ -1106,7 +1109,11 @@ describe('build plugin test', () => { eventMock.meta = { foo: 'oldfoo', - oldmeta: 'oldmetastuff' + oldmeta: 'oldmetastuff', + deployedAppVersion: { + ui: '2.4.67', + store: '4.0.1' + } }; return server.inject(options).then(reply => { @@ -1114,14 +1121,19 @@ describe('build plugin test', () => { assert.calledWith(buildFactoryMock.get, id); assert.calledOnce(buildMock.update); assert.strictEqual(buildMock.status, status); - assert.deepEqual(buildMock.meta, meta); + assert.deepEqual(buildMock.meta, options.payload.meta); assert.deepEqual(buildMock.statusMessage, statusMessage); assert.isDefined(buildMock.endTime); assert.calledOnce(eventMock.update); assert.deepEqual(eventMock.meta, { foo: 'bar', hello: 'bye', - oldmeta: 'oldmetastuff' + oldmeta: 'oldmetastuff', + deployedAppVersion: { + ui: '2.4.67', + store: '4.0.1', + api: '6.9.5' + } }); assert.deepEqual(buildMock.stats, { hostname: 'node123.mycluster.com'