2020-01-10 10:35:49 +00:00
import { logger } from '../../logger' ;
import { platform } from '../../platform' ;
import { RenovateConfig } from '../../config' ;
2020-03-05 06:03:47 +00:00
import { PR_STATE_OPEN } from '../../constants/pull-requests' ;
2019-01-06 13:47:42 +00:00
2020-01-10 10:35:49 +00:00
export async function raiseConfigWarningIssue (
config : RenovateConfig ,
error : Error
) : Promise < void > {
2017-12-18 08:39:52 +00:00
logger . debug ( 'raiseConfigWarningIssue()' ) ;
2019-12-05 10:55:14 +00:00
let body = ` There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved. \ n \ n ` ;
2017-12-18 08:39:52 +00:00
if ( error . configFile ) {
2018-03-22 10:55:58 +00:00
body += ` File: \` ${ error . configFile } \` \ n ` ;
2017-12-18 08:39:52 +00:00
}
body += ` Error type: ${ error . validationError } \ n ` ;
if ( error . validationMessage ) {
2018-12-05 08:04:27 +00:00
body += ` Message: \` ${ error . validationMessage } \` \ n ` ;
2017-12-18 08:39:52 +00:00
}
2019-12-05 08:39:39 +00:00
const pr = await platform . getBranchPr ( config . onboardingBranch ) ;
2020-03-05 06:03:47 +00:00
if ( pr && pr . state && pr . state === PR_STATE_OPEN ) {
2020-02-24 07:43:01 +00:00
logger . debug ( 'Updating onboarding PR with config error notice' ) ;
2019-12-05 10:55:14 +00:00
body = ` ## Action Required: Fix Renovate Configuration \ n \ n ${ body } ` ;
body += ` \ n \ nOnce you have resolved this problem (in this onboarding branch), Renovate will return to providing you with a preview of your repository's configuration. ` ;
2019-07-12 05:41:34 +00:00
if ( config . dryRun ) {
logger . info ( 'DRY-RUN: Would update PR #' + pr . number ) ;
2019-12-05 08:39:39 +00:00
} else await platform . updatePr ( pr . number , config . onboardingPrTitle , body ) ;
2019-07-12 05:41:34 +00:00
} else if ( config . dryRun ) {
logger . info ( 'DRY-RUN: Would ensure config error issue' ) ;
2018-01-08 14:53:52 +00:00
} else {
2019-08-15 05:41:01 +00:00
const once = false ;
const shouldReopen = config . configWarningReuseIssue ;
2020-01-07 10:40:53 +00:00
const res = await platform . ensureIssue ( {
title : ` Action Required: Fix Renovate Configuration ` ,
2019-08-15 05:41:01 +00:00
body ,
once ,
2020-01-07 10:40:53 +00:00
shouldReOpen : shouldReopen ,
} ) ;
2018-03-22 10:55:58 +00:00
if ( res === 'created' ) {
2017-12-18 08:39:52 +00:00
logger . warn ( { configError : error , res } , 'Config Warning' ) ;
}
}
}