From ff85796a9ecd42d21edddf6463df056140efbbdc Mon Sep 17 00:00:00 2001 From: Yuta Ohkawara Date: Fri, 26 Oct 2018 07:20:24 +0900 Subject: [PATCH] fix: Update build data schema (#16) --- index.js | 17 ++++++--- package.json | 2 +- test/index.test.js | 90 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 93 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index 2d7aa09..7d83ee5 100644 --- a/index.js +++ b/index.js @@ -31,13 +31,20 @@ const SCHEMA_BUILD_SETTINGS = Joi.object() .keys({ email: SCHEMA_EMAIL.required() }).unknown(true); +const SCHEMA_PIPELINE_DATA = Joi.object() + .keys({ + scmRepo: Joi.object().keys({ name: Joi.string() }).required() + }).unknown(true); const SCHEMA_BUILD_DATA = Joi.object() .keys({ settings: SCHEMA_BUILD_SETTINGS.required(), status: SCHEMA_STATUS.required(), - pipelineName: Joi.string(), + pipeline: SCHEMA_PIPELINE_DATA.required(), jobName: Joi.string(), - buildId: Joi.number().integer(), + build: Joi.object().keys({ + id: Joi.number().integer().required() + }).unknown(true), + event: Joi.object(), buildLink: Joi.string() }); const SCHEMA_SMTP_CONFIG = Joi.object() @@ -86,14 +93,14 @@ class EmailNotifier extends NotificationBase { return; } - const subject = `${buildData.status} - Screwdriver ${buildData.pipelineName} ` + - `${buildData.jobName} #${buildData.buildId}`; + const subject = `${buildData.status} - Screwdriver ${buildData.pipeline.scmRepo.name} ` + + `${buildData.jobName} #${buildData.build.id}`; const message = `Build status: ${buildData.status}` + `\nBuild link:${buildData.buildLink}`; const html = tinytim.renderFile(path.resolve(__dirname, './template/email.html'), { buildStatus: buildData.status, buildLink: buildData.buildLink, - buildId: buildData.buildId, + buildId: buildData.build.id, statusColor: COLOR_MAP[buildData.status] }); diff --git a/package.json b/package.json index 6e456d0..43ee622 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "eslint": "^3.9.1", "eslint-config-screwdriver": "^2.0.9", "hapi": "^17.0.0", - "jenkins-mocha": "^4.1.1", + "jenkins-mocha": "^6.0.0", "mockery": "^2.0.0", "sinon": "^1.17.7" }, diff --git a/test/index.test.js b/test/index.test.js index 57a5f66..0b54e4e 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -65,9 +65,23 @@ describe('index', () => { } }, status: 'SUCCESS', - pipelineName: 'screwdriver-cd/notifications', + pipeline: { + id: '123', + scmRepo: { + name: 'screwdriver-cd/notifications' + } + }, jobName: 'publish', - buildId: '1234', + build: { id: '1234' }, + event: { + id: '12345', + causeMessage: 'Merge pull request #26 from screwdriver-cd/notifications', + creator: { username: 'foo' }, + commit: { + author: { name: 'foo' }, + message: 'fixing a bug' + } + }, buildLink: 'http://thisisaSDtest.com/builds/1234' }; notifier = new EmailNotifier(configMock, serverMock, 'build_status_test'); @@ -157,9 +171,21 @@ describe('index', () => { email: 'notify.me@email.com' }, status: 'FAILURE', - pipelineName: 'screwdriver-cd/notifications', + pipeline: { + id: '123', + scmRepo: { name: 'screwdriver-cd/notifications' } + }, jobName: 'publish', - buildId: '1234', + build: { id: '1234' }, + event: { + id: '12345', + causeMessage: 'Merge pull request #26 from screwdriver-cd/notifications', + creator: { username: 'foo' }, + commit: { + author: { name: 'foo' }, + message: 'fixing a bug' + } + }, buildLink: 'http://thisisaSDtest.com/builds/1234' }; @@ -180,9 +206,21 @@ describe('index', () => { email: ['notify.me@email.com', 'notify.you@email.com'] }, status: 'FAILURE', - pipelineName: 'screwdriver-cd/notifications', + pipeline: { + id: '123', + scmRepo: { name: 'screwdriver-cd/notifications' } + }, jobName: 'publish', - buildId: '1234', + build: { id: '1234' }, + event: { + id: '12345', + causeMessage: 'Merge pull request #26 from screwdriver-cd/notifications', + creator: { username: 'foo' }, + commit: { + author: { name: 'foo' }, + message: 'fixing a bug' + } + }, buildLink: 'http://thisisaSDtest.com/builds/1234' }; @@ -233,9 +271,25 @@ describe('index', () => { } }, status: 'SUCCESS', - pipelineName: 'screwdriver-cd/notifications', + pipeline: { + id: '123', + scmRepo: { + name: 'screwdriver-cd/notifications' + } + }, jobName: 'publish', - buildId: '1234', + build: { + id: '1234' + }, + event: { + id: '12345', + causeMessage: 'Merge pull request #26 from screwdriver-cd/notifications', + creator: { username: 'foo' }, + commit: { + author: { name: 'foo' }, + message: 'fixing a bug' + } + }, buildLink: 'http://thisisaSDtest.com/builds/1234' }; }); @@ -326,9 +380,25 @@ describe('index', () => { } }, status: 'SUCCESS', - pipelineName: 'screwdriver-cd/notifications', + pipeline: { + id: '123', + scmRepo: { + name: 'screwdriver-cd/notifications' + } + }, jobName: 'publish', - buildId: '1234', + build: { + id: '1234' + }, + event: { + id: '12345', + causeMessage: 'Merge pull request #26 from screwdriver-cd/notifications', + creator: { username: 'foo' }, + commit: { + author: { name: 'foo' }, + message: 'fixing a bug' + } + }, buildLink: 'http://thisisaSDtest.com/builds/1234' };