Skip to content

Commit 5c27b27

Browse files
authored
Merge pull request #39 from screwdriver-cd/description
fix: includes pipelineId in description
2 parents ab61094 + 56e201e commit 5c27b27

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,16 @@ class BitbucketScm extends Scm {
572572
* @param {String} config.buildStatus The screwdriver build status to translate into scm commit status
573573
* @param {String} config.token The token used to authenticate to the SCM
574574
* @param {String} config.url Target Url of this commit status
575-
* @param {String} [config.jobName] Optional name of the job that finished
575+
* @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) {
579580
const scm = getScmUriParts(config.scmUri);
581+
let context = `Screwdriver/${config.pipelineId}/`;
582+
583+
context += /^PR/.test(config.jobName) ? 'PR' : config.jobName;
584+
580585
const options = {
581586
url: `${REPO_URL}/${scm.repoId}/commit/${config.sha}/statuses/build`,
582587
method: 'POST',
@@ -585,7 +590,7 @@ class BitbucketScm extends Scm {
585590
url: config.url,
586591
state: STATE_MAP[config.buildStatus],
587592
key: config.sha,
588-
description: config.jobName ? `Screwdriver/${config.jobName}` : 'Screwdriver'
593+
description: context
589594
},
590595
auth: {
591596
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: 12 additions & 14 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,24 +1058,21 @@ describe('index', function () {
10571058
requestMock.yieldsAsync(null, fakeResponse);
10581059
});
10591060

1060-
it('successfully update status', () =>
1061-
scm.updateCommitStatus(config).then(() => {
1062-
assert.calledWith(requestMock, expectedOptions);
1063-
})
1064-
);
1065-
1066-
it('successfully update status with correct values', () => {
1067-
config.buildStatus = 'ABORTED';
1068-
delete config.jobName;
1069-
1070-
expectedOptions.body.state = 'STOPPED';
1071-
expectedOptions.body.description = 'Screwdriver';
1061+
it('successfully update status for PR', () => {
1062+
config.jobName = 'PR-1';
1063+
expectedOptions.body.description = 'Screwdriver/123/PR';
10721064

10731065
return scm.updateCommitStatus(config).then(() => {
10741066
assert.calledWith(requestMock, expectedOptions);
10751067
});
10761068
});
10771069

1070+
it('successfully update status', () =>
1071+
scm.updateCommitStatus(config).then(() => {
1072+
assert.calledWith(requestMock, expectedOptions);
1073+
})
1074+
);
1075+
10781076
it('rejects if status code is not 201 or 200', () => {
10791077
fakeResponse = {
10801078
statusCode: 401,

0 commit comments

Comments
 (0)