File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ,
You can’t perform that action at this time.
0 commit comments