Skip to content

Commit 63f48e8

Browse files
committed
fix: includes pipelineId in description
1 parent ab61094 commit 63f48e8

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,18 @@ class BitbucketScm extends Scm {
573573
* @param {String} config.token The token used to authenticate to the SCM
574574
* @param {String} config.url Target Url of this commit status
575575
* @param {String} [config.jobName] Optional name of the job that finished
576+
* @param {Number} [config.pipelineId] Pipeline ID
576577
* @return {Promise}
577578
*/
578579
_updateCommitStatus(config) {
580+
let context = `Screwdriver/${config.pipelineId}`;
579581
const scm = getScmUriParts(config.scmUri);
582+
const jobName = config.jobName && /^PR/.test(config.jobName) ? 'PR' : config.jobName;
583+
584+
if (jobName) {
585+
context += `/${jobName}`;
586+
}
587+
580588
const options = {
581589
url: `${REPO_URL}/${scm.repoId}/commit/${config.sha}/statuses/build`,
582590
method: 'POST',
@@ -585,7 +593,7 @@ class BitbucketScm extends Scm {
585593
url: config.url,
586594
state: STATE_MAP[config.buildStatus],
587595
key: config.sha,
588-
description: config.jobName ? `Screwdriver/${config.jobName}` : 'Screwdriver'
596+
description: context
589597
},
590598
auth: {
591599
bearer: decodeURIComponent(config.token)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"hoek": "^4.1.0",
5050
"joi": "^10.0.5",
5151
"request": "^2.75.0",
52-
"screwdriver-data-schema": "^16.0.0",
52+
"screwdriver-data-schema": "^16.9.2",
5353
"screwdriver-scm-base": "^2.5.1"
5454
}
5555
}

test/index.test.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,8 @@ describe('index', function () {
10341034
buildStatus: 'SUCCESS',
10351035
token: 'bearerToken',
10361036
url: 'http://valid.url',
1037-
jobName: 'main'
1037+
jobName: 'main',
1038+
pipelineId: 123
10381039
};
10391040
apiUrl = `${API_URL_V2}/repositories/repoId/commit/${config.sha}/statuses/build`;
10401041
fakeResponse = {
@@ -1048,7 +1049,7 @@ describe('index', function () {
10481049
url: config.url,
10491050
state: 'SUCCESSFUL',
10501051
key: config.sha,
1051-
description: 'Screwdriver/main'
1052+
description: 'Screwdriver/123/main'
10521053
},
10531054
auth: {
10541055
bearer: 'bearerToken' // Decoded access token
@@ -1057,6 +1058,15 @@ describe('index', function () {
10571058
requestMock.yieldsAsync(null, fakeResponse);
10581059
});
10591060

1061+
it('successfully update status for PR', () => {
1062+
config.jobName = 'PR-1';
1063+
expectedOptions.body.description = 'Screwdriver/123/PR';
1064+
1065+
return scm.updateCommitStatus(config).then(() => {
1066+
assert.calledWith(requestMock, expectedOptions);
1067+
});
1068+
});
1069+
10601070
it('successfully update status', () =>
10611071
scm.updateCommitStatus(config).then(() => {
10621072
assert.calledWith(requestMock, expectedOptions);
@@ -1068,7 +1078,7 @@ describe('index', function () {
10681078
delete config.jobName;
10691079

10701080
expectedOptions.body.state = 'STOPPED';
1071-
expectedOptions.body.description = 'Screwdriver';
1081+
expectedOptions.body.description = 'Screwdriver/123';
10721082

10731083
return scm.updateCommitStatus(config).then(() => {
10741084
assert.calledWith(requestMock, expectedOptions);

0 commit comments

Comments
 (0)