Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(3211): Add a new field to builds to indicate the severity of the status message #585

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'];
sagar1312 marked this conversation as resolved.
Show resolved Hide resolved

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)
sagar1312 marked this conversation as resolved.
Show resolved Hide resolved
.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