Skip to content

Commit 75e1573

Browse files
authored
fix: fix for Bitbucket Deprecation of username usage (#68)
1 parent 296bf45 commit 75e1573

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,18 @@ class BitbucketScm extends Scm {
376376
const response = await this.breaker.runCommand(options);
377377
const body = response.body;
378378

379-
if (response.statusCode !== 200) {
379+
if (response.statusCode === 404 && !config.username.match(/^\{.*\}/)) {
380+
// Bitbucket API has changed, cannot use strict username request anymore, for now we will
381+
// have to return a simple generated decoration result to allow all builds to function.
382+
// We will only allow this if the username is not a {uuid} pattern. Since if this is a {uuid}
383+
// pattern, this likely is a valid 404.
384+
return {
385+
url: '',
386+
name: config.username,
387+
username: config.username,
388+
avatar: ''
389+
};
390+
} else if (response.statusCode !== 200) {
380391
throw new Error(`STATUS CODE ${response.statusCode}: ${JSON.stringify(body)}`);
381392
}
382393

test/index.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,42 @@ describe('index', function () {
438438
assert.deepEqual(decorated, expected);
439439
});
440440
});
441+
it('resolves to a fabricated decorated author', () => {
442+
fakeResponse = {
443+
statusCode: 404,
444+
body: {
445+
error: {
446+
message: 'Resource not found',
447+
detail: 'There is no API hosted at this URL'
448+
}
449+
}
450+
};
451+
452+
requestMock.yieldsAsync(null, fakeResponse, fakeResponse.body);
453+
454+
const expected = {
455+
url: '',
456+
name: 'batman',
457+
username: 'batman',
458+
avatar: ''
459+
};
460+
const expectedFabricatedOptions = {
461+
url: `${API_URL_V2}/users/batman`,
462+
method: 'GET',
463+
json: true,
464+
auth: {
465+
bearer: systemToken
466+
}
467+
};
441468

469+
return scm.decorateAuthor({
470+
username: 'batman',
471+
token
472+
}).then((decorated) => {
473+
assert.calledWith(requestMock, expectedFabricatedOptions);
474+
assert.deepEqual(decorated, expected);
475+
});
476+
});
442477
it('rejects if status code is not 200', () => {
443478
fakeResponse = {
444479
statusCode: 404,

0 commit comments

Comments
 (0)