Skip to content

Commit

Permalink
feat(2022): add source dir message (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshwata authored Oct 16, 2020
1 parent 99170ce commit 59f1830
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
40 changes: 40 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 59f1830

Please sign in to comment.