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' ;
2023-05-17 17:47:16 +00:00
import { Pr , platform } from '../../modules/platform' ;
2021-10-27 14:37:11 +00:00
import { regEx } from '../../util/regex' ;
2019-01-06 13:47:42 +00:00
2023-05-17 17:47:16 +00:00
export function raiseConfigWarningIssue (
2020-01-10 10:35:49 +00:00
config : RenovateConfig ,
error : Error
) : Promise < void > {
2017-12-18 08:39:52 +00:00
logger . debug ( 'raiseConfigWarningIssue()' ) ;
2023-05-17 17:47:16 +00:00
const title = ` Action Required: Fix Renovate Configuration ` ;
const 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 ` ;
const notificationName = 'configErrorIssue' ;
return raiseWarningIssue ( config , notificationName , title , body , error ) ;
2023-05-18 17:02:13 +00:00
}
export function raiseCredentialsWarningIssue (
config : RenovateConfig ,
error : Error
) : Promise < void > {
logger . debug ( 'raiseCredentialsWarningIssue()' ) ;
const title = ` Action Required: Add missing credentials ` ;
const body = ` There are missing credentials for the authentication-required feature. As a precaution, Renovate will pause PRs until it is resolved. \ n \ n ` ;
const notificationName = 'missingCredentialsError' ;
return raiseWarningIssue ( config , notificationName , title , body , error ) ;
2023-05-17 17:47:16 +00:00
}
async function raiseWarningIssue (
config : RenovateConfig ,
notificationName : string ,
title : string ,
initialBody : string ,
error : Error
) : Promise < void > {
let body = initialBody ;
2021-05-17 07:40:54 +00:00
if ( error . validationSource ) {
body += ` Location: \` ${ error . validationSource } \` \ n ` ;
2017-12-18 08:39:52 +00:00
}
2023-05-17 17:47:16 +00:00
if ( error . validationError ) {
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
}
2023-05-17 17:47:16 +00:00
2022-06-20 09:47:07 +00:00
const pr = await platform . getBranchPr ( config . onboardingBranch ! ) ;
2022-11-14 18:55:38 +00:00
if ( pr ? . state === 'open' ) {
2023-05-17 17:47:16 +00:00
await handleOnboardingPr ( pr , body ) ;
return ;
}
if ( GlobalConfig . get ( 'dryRun' ) ) {
2022-04-28 12:54:49 +00:00
logger . info (
2023-05-17 17:47:16 +00:00
{ configError : error } ,
'DRY-RUN: Would ensure configuration error issue'
2022-04-28 12:54:49 +00:00
) ;
2023-05-17 17:47:16 +00:00
return ;
}
if ( config . suppressNotifications ? . includes ( notificationName ) ) {
logger . info (
{ notificationName } ,
'Configuration failure, issues will be suppressed'
) ;
return ;
}
const res = await platform . ensureIssue ( {
title ,
body ,
once : false ,
shouldReOpen : config.configWarningReuseIssue ,
confidential : config.confidential ,
} ) ;
if ( res === 'created' ) {
logger . warn ( { configError : error , res } , 'Configuration Warning' ) ;
}
}
async function handleOnboardingPr ( pr : Pr , issueMessage : string ) : Promise < void > {
logger . debug ( 'Updating onboarding PR with config error notice' ) ;
if ( GlobalConfig . get ( 'dryRun' ) ) {
logger . info ( ` DRY-RUN: Would update PR # ${ pr . number } ` ) ;
return ;
}
let prBody = ` ## Action Required: Fix Renovate Configuration \ n \ n ${ issueMessage } ` ;
prBody += ` \ 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. ` ;
try {
await platform . updatePr ( {
number : pr . number ,
prTitle : pr.title ,
prBody ,
2020-01-07 10:40:53 +00:00
} ) ;
2023-05-17 17:47:16 +00:00
} catch ( err ) /* istanbul ignore next */ {
logger . warn ( { err } , 'Error updating onboarding PR' ) ;
2017-12-18 08:39:52 +00:00
}
}