Skip to content

Commit 4e034a1

Browse files
pritamstyz4everppaul
andauthored
feat: add prMerged flag to webhook result (#96)
* Update index.js * update tests * fix tests --------- Co-authored-by: ppaul <pritam.paul@yahooinc.com>
1 parent 772522a commit 4e034a1

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class BitbucketScm extends Scm {
374374
parsed.scmContext = scmContexts[0];
375375

376376
if (hoek.reach(payload, 'repository.links.html.href') === undefined) {
377-
throwError(`Invalid webhook payload`, 400);
377+
throwError('Invalid webhook payload', 400);
378378
}
379379

380380
const link = Url.parse(hoek.reach(payload, 'repository.links.html.href'));
@@ -420,6 +420,10 @@ class BitbucketScm extends Scm {
420420
parsed.prNum = hoek.reach(payload, 'pullrequest.id');
421421
parsed.prRef = hoek.reach(payload, 'pullrequest.source.branch.name');
422422

423+
const state = hoek.reach(payload, 'pullrequest.state');
424+
425+
parsed.prMerged = state === 'MERGED';
426+
423427
return parsed;
424428
}
425429
default:
@@ -808,8 +812,8 @@ class BitbucketScm extends Scm {
808812
// Set recursive option
809813
command.push(
810814
'if [ ! -z $GIT_RECURSIVE_CLONE ] && [ $GIT_RECURSIVE_CLONE = false ]; ' +
811-
`then export GIT_RECURSIVE_OPTION=""; ` +
812-
`else export GIT_RECURSIVE_OPTION="--recursive"; fi`
815+
'then export GIT_RECURSIVE_OPTION=""; ' +
816+
'else export GIT_RECURSIVE_OPTION="--recursive"; fi'
813817
);
814818

815819
// Checkout config pipeline if this is a child pipeline

test/index.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ describe('index', function () {
324324
prNum: 3,
325325
prRef: 'mynewbranch',
326326
hookId: '1e8d4e8e-5fcf-4624-b091-b10bd6ecaf5e',
327-
scmContext: 'bitbucket:bitbucket.org'
327+
scmContext: 'bitbucket:bitbucket.org',
328+
prMerged: false
328329
};
329330
const headers = {
330331
'x-event-key': 'pullrequest:created',
@@ -345,7 +346,8 @@ describe('index', function () {
345346
prNum: 7,
346347
prRef: 'prbranch',
347348
hookId: '1e8d4e8e-5fcf-4624-b091-b10bd6ecaf5e',
348-
scmContext: 'bitbucket:bitbucket.org'
349+
scmContext: 'bitbucket:bitbucket.org',
350+
prMerged: false
349351
};
350352
const headers = {
351353
'x-event-key': 'pullrequest:updated',
@@ -366,7 +368,8 @@ describe('index', function () {
366368
prNum: 3,
367369
prRef: 'mynewbranch',
368370
hookId: '1e8d4e8e-5fcf-4624-b091-b10bd6ecaf5e',
369-
scmContext: 'bitbucket:bitbucket.org'
371+
scmContext: 'bitbucket:bitbucket.org',
372+
prMerged: true
370373
};
371374
const headers = {
372375
'x-event-key': 'pullrequest:fullfilled',
@@ -387,7 +390,8 @@ describe('index', function () {
387390
prNum: 3,
388391
prRef: 'mynewbranch',
389392
hookId: '1e8d4e8e-5fcf-4624-b091-b10bd6ecaf5e',
390-
scmContext: 'bitbucket:bitbucket.org'
393+
scmContext: 'bitbucket:bitbucket.org',
394+
prMerged: true
391395
};
392396
const headers = {
393397
'x-event-key': 'pullrequest:rejected',

0 commit comments

Comments
 (0)