Skip to content

Commit

Permalink
fix: Update build data schema (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
yokawara authored and tkyi committed Oct 25, 2018
1 parent 45b1aaf commit ff85796
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 16 deletions.
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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]
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
90 changes: 80 additions & 10 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -157,9 +171,21 @@ describe('index', () => {
email: '[email protected]'
},
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'
};

Expand All @@ -180,9 +206,21 @@ describe('index', () => {
email: ['[email protected]', '[email protected]']
},
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'
};

Expand Down Expand Up @@ -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'
};
});
Expand Down Expand Up @@ -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'
};

Expand Down

0 comments on commit ff85796

Please sign in to comment.