From 59f18306297795c4288591f562a552396ccacd72 Mon Sep 17 00:00:00 2001 From: Yoshiyuki Watanabe <32473622+yoshwata@users.noreply.github.com> Date: Sat, 17 Oct 2020 03:25:12 +0900 Subject: [PATCH] feat(2022): add source dir message (#32) --- index.js | 6 ++++++ test/index.test.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/index.js b/index.js index 24dedbb..34bac6b 100644 --- a/index.js +++ b/index.js @@ -171,6 +171,12 @@ class SlackNotifier extends NotificationBase { // eslint-disable-next-line max-len `*${notificationStatus}* ${STATUSES_MAP[notificationStatus]} <${pipelineLink}|${buildData.pipeline.scmRepo.name} ${buildData.jobName}>`; + const rootDir = hoek.reach(buildData, 'pipeline.scmRepo.rootDir', { default: false }); + + if (rootDir) { + message = `${message}\n*Source Directory:* ${rootDir}`; + } + const metaMessage = hoek.reach(buildData, 'build.meta.notification.slack.message', { default: false }); diff --git a/test/index.test.js b/test/index.test.js index 23dacbb..8b410f8 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -264,6 +264,46 @@ describe('index', () => { }); }); + it('sets channels, statuses and srcDir for simple slack string name', (done) => { + const buildDataMockSimple = { + settings: { + slack: 'meeseeks' + }, + status: 'FAILURE', + pipeline: { + id: '123', + scmRepo: { + name: 'screwdriver-cd/notifications', + rootDir: 'mydir' + } + }, + jobName: 'publish', + 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' + }, + sha: '1234567890abcdeffedcba098765432100000000' + }, + buildLink: 'http://thisisaSDtest.com/pipelines/12/builds/1234' + }; + + serverMock.event(eventMock); + serverMock.events.on(eventMock, data => notifier.notify(data)); + serverMock.events.emit(eventMock, buildDataMockSimple); + + process.nextTick(() => { + assert.calledOnce(WebClientMock.chat.postMessage); + done(); + }); + }); + it('sets channels and statuses for simple slack string name with message', (done) => { const buildDataMockSimple = { settings: {