Skip to content

Commit

Permalink
fix: pipeline link at pr builds (#46)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuta Kaneda <yukaneda@yahoo-corp.jp>
  • Loading branch information
yk634 and Yuta Kaneda authored Jan 13, 2023
1 parent 0f1d8ed commit 72d4876
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ function buildStatus(buildData, config) {
return;
}

const pipelineLink = buildData.buildLink.split('/builds')[0];
const pipelineLink = /^PR-/.test(buildData.jobName)
? `${buildData.buildLink.split('/builds')[0]}/pulls`
: buildData.buildLink.split('/builds')[0];
const truncatedSha = buildData.event.sha.slice(0, 6);
const cutOff = 150;
const commitMessage =
Expand Down
79 changes: 77 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,19 +250,94 @@ describe('index', () => {
creator: { username: 'foo' },
commit: {
author: { name: 'foo' },
message: 'fixing a bug'
message: 'fixing a bug',
url: 'http://scmtest/org/repo/commit/123456'
},
sha: '1234567890abcdeffedcba098765432100000000'
},
buildLink: 'http://thisisaSDtest.com/pipelines/12/builds/1234'
};

const postMessagePayloadData = {
channel: 'meeseeks',
text: '*FAILURE* :umbrella: <http://thisisaSDtest.com/pipelines/12|screwdriver-cd/notifications publish>',
as_user: true,
attachments: [
{
fallback: '',
color: 'danger',
title: '#1234',
title_link: 'http://thisisaSDtest.com/pipelines/12/builds/1234',
text:
'fixing a bug (<http://scmtest/org/repo/commit/123456|123456>)\n' +
'Merge pull request #26 from screwdriver-cd/notifications'
}
]
};

serverMock.event(eventMock);
serverMock.events.on(eventMock, data => notifier.notify(eventMock, data));
serverMock.events.emit(eventMock, buildDataMockSimple);

process.nextTick(() => {
assert.calledOnce(WebClientMock.chat.postMessage);
assert.calledWith(WebClientMock.chat.postMessage, postMessagePayloadData);
done();
});
});

it('sets channels and statuses for simple slack string name for PR builds.', done => {
const buildDataMockSimple = {
settings: {
slack: 'meeseeks'
},
status: 'FAILURE',
pipeline: {
id: '123',
scmRepo: {
name: 'screwdriver-cd/notifications'
}
},
jobName: 'PR-1: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',
url: 'http://scmtest/org/repo/commit/123456'
},
sha: '1234567890abcdeffedcba098765432100000000'
},
buildLink: 'http://thisisaSDtest.com/pipelines/12/builds/1234'
};

const postMessagePayloadData = {
channel: 'meeseeks',
text: '*FAILURE* :umbrella: <http://thisisaSDtest.com/pipelines/12/pulls|screwdriver-cd/notifications PR-1:publish>',
as_user: true,
attachments: [
{
fallback: '',
color: 'danger',
title: '#1234',
title_link: 'http://thisisaSDtest.com/pipelines/12/builds/1234',
text:
'fixing a bug (<http://scmtest/org/repo/commit/123456|123456>)\n' +
'Merge pull request #26 from screwdriver-cd/notifications'
}
]
};

serverMock.event(eventMock);
serverMock.events.on(eventMock, data => notifier.notify(eventMock, data));
serverMock.events.emit(eventMock, buildDataMockSimple);

process.nextTick(() => {
assert.calledWith(WebClientMock.chat.postMessage, postMessagePayloadData);
done();
});
});
Expand Down

0 comments on commit 72d4876

Please sign in to comment.