2022-06-21 11:00:21 +00:00
// TODO #7154
2021-11-23 20:10:45 +00:00
import { GlobalConfig } from '../../config/global' ;
2021-04-20 08:52:57 +00:00
import type { RenovateConfig } from '../../config/types' ;
2020-05-01 16:03:48 +00:00
import { logger } from '../../logger' ;
2022-03-03 09:35:26 +00:00
import { platform } from '../../modules/platform' ;
2020-08-18 10:19:19 +00:00
import { PrState } from '../../types' ;
2021-10-27 14:37:11 +00:00
import { regEx } from '../../util/regex' ;
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 ` ;
2021-05-17 07:40:54 +00:00
if ( error . validationSource ) {
body += ` Location: \` ${ error . validationSource } \` \ n ` ;
2017-12-18 08:39:52 +00:00
}
2022-06-20 09:47:07 +00:00
body += ` Error type: ${ error . validationError ! } \ n ` ;
2017-12-18 08:39:52 +00:00
if ( error . validationMessage ) {
2021-10-27 14:37:11 +00:00
body += ` Message: \` ${ error . validationMessage . replace (
regEx ( /`/g ) ,
"'"
) } \ ` \ n ` ;
2017-12-18 08:39:52 +00:00
}
2022-06-20 09:47:07 +00:00
const pr = await platform . getBranchPr ( config . onboardingBranch ! ) ;
2020-08-18 10:19:19 +00:00
if ( pr ? . state === PrState . 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. ` ;
2021-11-23 20:10:45 +00:00
if ( GlobalConfig . get ( 'dryRun' ) ) {
2020-08-10 14:18:08 +00:00
logger . info ( ` DRY-RUN: Would update PR # ${ pr . number } ` ) ;
2020-03-17 11:15:22 +00:00
} else {
2021-05-12 13:06:02 +00:00
try {
await platform . updatePr ( {
number : pr . number ,
2022-06-20 09:47:07 +00:00
prTitle : config.onboardingPrTitle ! ,
2021-05-12 13:06:02 +00:00
prBody : body ,
} ) ;
} catch ( err ) /* istanbul ignore next */ {
logger . warn ( { err } , 'Error updating onboarding PR' ) ;
}
2020-03-17 11:15:22 +00:00
}
2021-11-23 20:10:45 +00:00
} else if ( GlobalConfig . get ( 'dryRun' ) ) {
2019-07-12 05:41:34 +00:00
logger . info ( 'DRY-RUN: Would ensure config error issue' ) ;
2022-04-28 12:54:49 +00:00
} else if ( config . suppressNotifications ? . includes ( 'configErrorIssue' ) ) {
logger . info (
'configErrorIssue - configuration failure, issues will be suppressed'
) ;
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 ,
2021-11-24 05:14:24 +00:00
confidential : config.confidential ,
2020-01-07 10:40:53 +00:00
} ) ;
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' ) ;
}
}
}