Skip to content

Commit a553e7a

Browse files
xangxiongtkyi
authored andcommitted
fix(1662): Update decorate author and commit to replace user uuid with username (#61)
1 parent abfacf3 commit a553e7a

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class BitbucketScm extends Scm {
290290
_parseHook(headers, payload) {
291291
const [typeHeader, actionHeader] = headers['x-event-key'].split(':');
292292
const parsed = {};
293-
const repoOwner = hoek.reach(payload, 'repository.owner.username');
293+
const repoOwner = hoek.reach(payload, 'repository.owner.uuid');
294294
const scmContexts = this._getScmContexts();
295295

296296
parsed.hookId = headers['x-request-uuid'];
@@ -306,8 +306,8 @@ class BitbucketScm extends Scm {
306306

307307
parsed.type = 'repo';
308308
parsed.action = 'push';
309-
parsed.username = hoek.reach(payload, 'actor.username');
310-
parsed.checkoutUrl = `${link.protocol}//${repoOwner}`
309+
parsed.username = hoek.reach(payload, 'actor.uuid');
310+
parsed.checkoutUrl = `${link.protocol}//${encodeURIComponent(repoOwner)}`
311311
+ `@${link.hostname}${link.pathname}.git`;
312312
parsed.branch = hoek.reach(changes[0], 'new.name');
313313
parsed.sha = hoek.reach(changes[0], 'new.target.hash');
@@ -330,8 +330,8 @@ class BitbucketScm extends Scm {
330330
const link = url.parse(hoek.reach(payload, 'repository.links.html.href'));
331331

332332
parsed.type = 'pr';
333-
parsed.username = hoek.reach(payload, 'actor.username');
334-
parsed.checkoutUrl = `${link.protocol}//${repoOwner}`
333+
parsed.username = hoek.reach(payload, 'actor.uuid');
334+
parsed.checkoutUrl = `${link.protocol}//${encodeURIComponent(repoOwner)}`
335335
+ `@${link.hostname}${link.pathname}.git`;
336336
parsed.branch = hoek.reach(payload, 'pullrequest.destination.branch.name');
337337
parsed.sha = hoek.reach(payload, 'pullrequest.source.commit.hash');
@@ -355,7 +355,7 @@ class BitbucketScm extends Scm {
355355
*/
356356
_decorateAuthor(config) {
357357
const options = {
358-
url: `${USER_URL}/${config.username}`,
358+
url: `${USER_URL}/${encodeURIComponent(config.username)}`,
359359
method: 'GET',
360360
json: true,
361361
auth: {
@@ -374,7 +374,7 @@ class BitbucketScm extends Scm {
374374
return {
375375
url: body.links.html.href,
376376
name: body.display_name,
377-
username: body.username,
377+
username: body.uuid,
378378
avatar: body.links.avatar.href
379379
};
380380
});
@@ -448,7 +448,7 @@ class BitbucketScm extends Scm {
448448

449449
// eslint-disable-next-line
450450
return this._decorateAuthor({
451-
username: body.author.user.username,
451+
username: body.author.user.uuid,
452452
token: config.token
453453
}).then(author => ({
454454
url: body.links.html.href,

test/index.test.js

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ describe('index', function () {
252252
const expected = {
253253
type: 'pr',
254254
action: 'opened',
255-
username: 'robin',
256-
checkoutUrl: 'https://batman@bitbucket.org/batman/test.git',
255+
username: '{2dca4f54-ab3f-400c-a777-c059e1ac0394}',
256+
checkoutUrl: 'https://%7B2dca4f54-ab3f-400c-a777-c059e1ac0394%7D@bitbucket.org/batman/test.git', // eslint-disable-line max-len
257257
branch: 'master',
258258
sha: '40171b678527',
259259
prNum: 3,
@@ -274,8 +274,8 @@ describe('index', function () {
274274
const expected = {
275275
type: 'pr',
276276
action: 'synchronized',
277-
username: 'batman',
278-
checkoutUrl: 'https://batman@bitbucket.org/batman/test.git',
277+
username: '{2dca4f54-ab3f-400c-a777-c059e1ac0394}',
278+
checkoutUrl: 'https://%7B2dca4f54-ab3f-400c-a777-c059e1ac0394%7D@bitbucket.org/batman/test.git', // eslint-disable-line max-len
279279
branch: 'master',
280280
sha: 'caeae8cd5fc9',
281281
prNum: 7,
@@ -296,8 +296,8 @@ describe('index', function () {
296296
const expected = {
297297
type: 'pr',
298298
action: 'closed',
299-
username: 'robin',
300-
checkoutUrl: 'https://batman@bitbucket.org/batman/test.git',
299+
username: '{2dca4f54-ab3f-400c-a777-c059e1ac0394}',
300+
checkoutUrl: 'https://%7B2dca4f54-ab3f-400c-a777-c059e1ac0394%7D@bitbucket.org/batman/test.git', // eslint-disable-line max-len
301301
branch: 'master',
302302
sha: '40171b678527',
303303
prNum: 3,
@@ -318,8 +318,8 @@ describe('index', function () {
318318
const expected = {
319319
type: 'pr',
320320
action: 'closed',
321-
username: 'robin',
322-
checkoutUrl: 'https://batman@bitbucket.org/batman/test.git',
321+
username: '{2dca4f54-ab3f-400c-a777-c059e1ac0394}',
322+
checkoutUrl: 'https://%7B2dca4f54-ab3f-400c-a777-c059e1ac0394%7D@bitbucket.org/batman/test.git', // eslint-disable-line max-len
323323
branch: 'master',
324324
sha: '40171b678527',
325325
prNum: 3,
@@ -340,8 +340,8 @@ describe('index', function () {
340340
const expected = {
341341
type: 'repo',
342342
action: 'push',
343-
username: 'robin',
344-
checkoutUrl: 'https://batman@bitbucket.org/batman/test.git',
343+
username: '{2dca4f54-ab3f-400c-a777-c059e1ac0394}',
344+
checkoutUrl: 'https://%7B2dca4f54-ab3f-400c-a777-c059e1ac0394%7D@bitbucket.org/batman/test.git', // eslint-disable-line max-len
345345
branch: 'stuff',
346346
sha: '9ff49b2d1437567cad2b5fed7a0706472131e927',
347347
lastCommitMessage: 'testpayload\n',
@@ -386,7 +386,7 @@ describe('index', function () {
386386
});
387387

388388
describe('decorateAuthor', () => {
389-
const apiUrl = `${API_URL_V2}/users/batman`;
389+
const apiUrl = `${API_URL_V2}/users/%7B4f1a9b7f-586e-4e80-b9eb-a7589b4a165f%7D`;
390390
const expectedOptions = {
391391
url: apiUrl,
392392
method: 'GET',
@@ -401,12 +401,11 @@ describe('index', function () {
401401
fakeResponse = {
402402
statusCode: 200,
403403
body: {
404-
username: 'batman',
405404
display_name: 'Batman',
406405
uuid: '{4f1a9b7f-586e-4e80-b9eb-a7589b4a165f}',
407406
links: {
408407
html: {
409-
href: 'https://bitbucket.org/batman/'
408+
href: 'https://bitbucket.org/%7B4f1a9b7f-586e-4e80-b9eb-a7589b4a165f%7D/' // eslint-disable-line max-len
410409
},
411410
avatar: {
412411
href: 'https://bitbucket.org/account/batman/avatar/32/'
@@ -419,14 +418,14 @@ describe('index', function () {
419418

420419
it('resolves to correct decorated author', () => {
421420
const expected = {
422-
url: 'https://bitbucket.org/batman/',
421+
url: 'https://bitbucket.org/%7B4f1a9b7f-586e-4e80-b9eb-a7589b4a165f%7D/',
423422
name: 'Batman',
424-
username: 'batman',
423+
username: '{4f1a9b7f-586e-4e80-b9eb-a7589b4a165f}',
425424
avatar: 'https://bitbucket.org/account/batman/avatar/32/'
426425
};
427426

428427
return scm.decorateAuthor({
429-
username: 'batman',
428+
username: '{4f1a9b7f-586e-4e80-b9eb-a7589b4a165f}',
430429
token
431430
}).then((decorated) => {
432431
assert.calledWith(requestMock, expectedOptions);
@@ -448,7 +447,7 @@ describe('index', function () {
448447
requestMock.yieldsAsync(null, fakeResponse, fakeResponse.body);
449448

450449
return scm.decorateAuthor({
451-
username: 'batman',
450+
username: '{4f1a9b7f-586e-4e80-b9eb-a7589b4a165f}',
452451
token
453452
}).then(() => {
454453
assert.fail('Should not get here');
@@ -464,7 +463,7 @@ describe('index', function () {
464463
requestMock.yieldsAsync(err);
465464

466465
return scm.decorateAuthor({
467-
username: 'batman',
466+
username: '{4f1a9b7f-586e-4e80-b9eb-a7589b4a165f}',
468467
token
469468
}).then(() => {
470469
assert.fail('Should not get here');
@@ -574,7 +573,7 @@ describe('index', function () {
574573
const sha = '1111111111111111111111111111111111111111';
575574
const repoUrl =
576575
`${API_URL_V2}/repositories/repoId/commit/${sha}`;
577-
const authorUrl = `${API_URL_V2}/users/username`;
576+
const authorUrl = `${API_URL_V2}/users/%7Buuid%7D`;
578577
const selfLink = `https://bitbucket.org/repoId/commits/${sha}`;
579578
const repoOptions = {
580579
url: repoUrl,
@@ -607,23 +606,22 @@ describe('index', function () {
607606
},
608607
author: {
609608
user: {
610-
username: 'username'
609+
uuid: '{uuid}'
611610
}
612611
}
613612
}
614613
};
615614
fakeAuthorResponse = {
616615
statusCode: 200,
617616
body: {
618-
username: 'username',
619617
display_name: 'displayName',
620-
uuid: 'uuid',
618+
uuid: '{uuid}',
621619
links: {
622620
html: {
623-
href: 'https://bitbucket.org/username/'
621+
href: 'https://bitbucket.org/%7Buuid%7D/'
624622
},
625623
avatar: {
626-
href: 'https://bitbucket.org/account/username/avatar/32/'
624+
href: 'https://bitbucket.org/account/%7Buuid%7D/avatar/32/'
627625
}
628626
}
629627
}
@@ -639,10 +637,10 @@ describe('index', function () {
639637
url: selfLink,
640638
message: 'testing',
641639
author: {
642-
url: 'https://bitbucket.org/username/',
640+
url: 'https://bitbucket.org/%7Buuid%7D/',
643641
name: 'displayName',
644-
username: 'username',
645-
avatar: 'https://bitbucket.org/account/username/avatar/32/'
642+
username: '{uuid}',
643+
avatar: 'https://bitbucket.org/account/%7Buuid%7D/avatar/32/'
646644
}
647645
};
648646

0 commit comments

Comments
 (0)