Skip to content

Commit

Permalink
fix(3203): Deep merge build meta into event meta (#3204)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagar1312 authored Sep 23, 2024
1 parent ca176cb commit 00a9f0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion plugins/builds/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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();
Expand Down
28 changes: 20 additions & 8 deletions test/plugins/builds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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: {
Expand All @@ -1106,22 +1109,31 @@ 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 => {
assert.equal(reply.statusCode, 200);
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'
Expand Down

0 comments on commit 00a9f0a

Please sign in to comment.