Skip to content

Commit

Permalink
feat(3211): Add a new field to builds to indicate the severity of the…
Browse files Browse the repository at this point in the history
… status message (#585)
  • Loading branch information
sagar1312 authored Oct 14, 2024
1 parent 2c2338b commit 6b5bc93
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
21 changes: 21 additions & 0 deletions migrations/20241014165446-add-status-message-type-to-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-disable new-cap */

'use strict';

const prefix = process.env.DATASTORE_SEQUELIZE_PREFIX || '';
const table = `${prefix}builds`;

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.sequelize.transaction(async transaction => {
await queryInterface.addColumn(
table,
'statusMessageType',
{
type: Sequelize.STRING(10)
},
{ transaction }
);
});
}
};
20 changes: 19 additions & 1 deletion models/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const STATUSES = [
'COLLAPSED', // when the build is collapsed
'FROZEN' // when the build is frozen due to freeze window
];
const STATUS_MESSAGE_TYPES = ['ERROR', 'WARN', 'INFO'];

const MODEL = {
id: Joi.number().integer().positive().description('Identifier of this build').example(123345),
Expand Down Expand Up @@ -85,6 +86,12 @@ const MODEL = {
.description('Status message to describe status of the build')
.example('Build failed due to infrastructure error'),

statusMessageType: Joi.string()
.valid(...STATUS_MESSAGE_TYPES)
.max(10)
.description('Severity of the status message')
.example('WARN'),

stats: Joi.object()
.keys({
queueEnterTime: Joi.string().isoDate().description('When this build enters queue'),
Expand Down Expand Up @@ -158,6 +165,7 @@ module.exports = {
'eventId',
'environment',
'statusMessage',
'statusMessageType',
'stats',
'buildClusterName',
'templateId',
Expand All @@ -172,7 +180,9 @@ module.exports = {
* @property update
* @type {Joi}
*/
update: Joi.object(mutate(MODEL, [], ['status', 'meta', 'statusMessage', 'stats'])).label('Update Build'),
update: Joi.object(mutate(MODEL, [], ['status', 'meta', 'statusMessage', 'statusMessageType', 'stats'])).label(
'Update Build'
),

/**
* Properties for Build that will be passed during a CREATE request
Expand Down Expand Up @@ -223,6 +233,14 @@ module.exports = {
*/
allKeys: Object.keys(MODEL),

/**
* All the available status message type
*
* @property allStatusMessageTypes
* @type {Array}
*/
allStatusMessageTypes: STATUS_MESSAGE_TYPES,

/**
* Tablename to be used in the datastore
*
Expand Down
1 change: 1 addition & 0 deletions test/data/build.update.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Build Update Example
status: FAILURE
statusMessage: 'Build failed to start due to infrastructure error'
statusMessageType: 'ERROR'
meta:
yes: no
stats:
Expand Down
16 changes: 16 additions & 0 deletions test/models/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ describe('model build', () => {
it('fails the get', () => {
assert.isNotNull(validate('empty.yaml', models.build.get).error);
});

// valid status message types
models.build.allStatusMessageTypes.forEach(messageType => {
it('validates the valid message types', () => {
assert.isNull(validate('build.get.yaml', models.build.get, { statusMessageType: messageType }).error);
});
});

// invalid status message types
['', 'error', 'warn', 'info', 'some_invalid_message_type'].forEach(messageType => {
it('validates the invalid message types', () => {
assert.isNotNull(
validate('build.get.yaml', models.build.get, { statusMessageType: messageType }).error
);
});
});
});

describe('steps', () => {
Expand Down

0 comments on commit 6b5bc93

Please sign in to comment.