File tree Expand file tree Collapse file tree 3 files changed +56
-4
lines changed Expand file tree Collapse file tree 3 files changed +56
-4
lines changed Original file line number Diff line number Diff line change 33/* eslint-disable no-underscore-dangle */
44const Hoek = require ( '@hapi/hoek' ) ;
55const Joi = require ( 'joi' ) ;
6+ const logger = require ( 'screwdriver-logger' ) ;
67const dataSchema = require ( 'screwdriver-data-schema' ) ;
78const { getAnnotations } = require ( './lib/helper' ) ;
89
910const repoManifestAnnotation = 'screwdriver.cd/repoManifest' ;
1011
12+ const DEFAULT_AUTHOR = {
13+ id : '' ,
14+ avatar : 'https://cd.screwdriver.cd/assets/unknown_user.png' ,
15+ name : 'n/a' ,
16+ username : 'n/a' ,
17+ url : 'https://cd.screwdriver.cd/'
18+ } ;
19+
1120/**
1221 * Validate the config using the schema
1322 * @method validate
@@ -328,7 +337,23 @@ class ScmBase {
328337 */
329338 decorateAuthor ( config ) {
330339 return validate ( config , dataSchema . plugins . scm . decorateAuthor )
331- . then ( validAuthor => this . _decorateAuthor ( this . getConfig ( validAuthor ) ) )
340+ . then ( async validAuthor => {
341+ let author ;
342+
343+ try {
344+ author = await this . _decorateAuthor ( this . getConfig ( validAuthor ) ) ;
345+ } catch ( err ) {
346+ logger . error ( 'Failed to decorateAuthor: ' , err ) ;
347+
348+ author = {
349+ ...DEFAULT_AUTHOR ,
350+ name : config . username ,
351+ username : config . username
352+ } ;
353+ }
354+
355+ return author ;
356+ } )
332357 . then ( decoratedAuthor => validate ( decoratedAuthor , dataSchema . core . scm . user ) ) ;
333358 }
334359
Original file line number Diff line number Diff line change 4747 "dependencies" : {
4848 "@hapi/hoek" : " ^11.0.7" ,
4949 "joi" : " ^17.13.3" ,
50- "screwdriver-data-schema" : " ^25.0.0"
50+ "screwdriver-data-schema" : " ^25.0.0" ,
51+ "screwdriver-logger" : " ^3.0.0"
5152 }
5253}
Original file line number Diff line number Diff line change @@ -596,12 +596,38 @@ describe('index test', () => {
596596 it ( 'returns not implemented' , ( ) =>
597597 instance
598598 . decorateAuthor ( config )
599- . then ( ( ) => {
600- assert . fail ( 'you will never get dis' ) ;
599+ . then ( author => {
600+ assert . deepEqual (
601+ {
602+ id : '' ,
603+ avatar : 'https://cd.screwdriver.cd/assets/unknown_user.png' ,
604+ name : config . username ,
605+ username : config . username ,
606+ url : 'https://cd.screwdriver.cd/'
607+ } ,
608+ author
609+ ) ;
601610 } )
602611 . catch ( err => {
603612 assert . equal ( err . message , 'Not implemented' ) ;
604613 } ) ) ;
614+
615+ it ( 'returns default author when there is a failure get author from scm' , ( ) => {
616+ instance . _decorateAuthor = ( ) => Promise . reject ( new Error ( 'User profile does not exist' ) ) ;
617+
618+ return instance . decorateAuthor ( config ) . then ( author => {
619+ assert . deepEqual (
620+ {
621+ id : '' ,
622+ avatar : 'https://cd.screwdriver.cd/assets/unknown_user.png' ,
623+ name : config . username ,
624+ username : config . username ,
625+ url : 'https://cd.screwdriver.cd/'
626+ } ,
627+ author
628+ ) ;
629+ } ) ;
630+ } ) ;
605631 } ) ;
606632
607633 describe ( 'getPermissons' , ( ) => {
You can’t perform that action at this time.
0 commit comments