diff --git a/lib/workers/repository/onboarding/branch/index.ts b/lib/workers/repository/onboarding/branch/index.ts index fb881e3525edb5483a2479deb9e18e34a23e8415..c2031ab1efb76e211a4646cb504c708a7921ff0d 100644 --- a/lib/workers/repository/onboarding/branch/index.ts +++ b/lib/workers/repository/onboarding/branch/index.ts @@ -60,6 +60,7 @@ export async function checkOnboardingBranch( logger.debug('Onboarding PR already exists'); if ( + isConfigHashPresent(onboardingPr) && // needed so that existing onboarding PRs are updated with config hash comment isOnboardingCacheValid(config.defaultBranch!, config.onboardingBranch!) && !(config.onboardingRebaseCheckbox && OnboardingState.prUpdateRequested) ) { @@ -165,3 +166,13 @@ function isOnboardingCacheValid( onboardingBranchCache.configFileParsed ); } + +function isConfigHashPresent(pr: Pr): boolean { + const platform = GlobalConfig.get('platform')!; + // if platform does not support html comments return true + if (!['github', 'gitlab', 'gitea'].includes(platform)) { + return true; + } + + return !!pr.bodyStruct?.rawConfigHash; +} diff --git a/lib/workers/repository/onboarding/pr/__snapshots__/index.spec.ts.snap b/lib/workers/repository/onboarding/pr/__snapshots__/index.spec.ts.snap index f8041b7fcb64ddf6c26fdce541f1e397c67cac2a..625b52c907cee783f6cb53d31447f75ef591d859 100644 --- a/lib/workers/repository/onboarding/pr/__snapshots__/index.spec.ts.snap +++ b/lib/workers/repository/onboarding/pr/__snapshots__/index.spec.ts.snap @@ -27,6 +27,8 @@ If you need any further assistance then you can also [request help here](https:/ --- + +<!--renovate-config-hash:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855--> " `; @@ -94,6 +96,8 @@ If you need any further assistance then you can also [request help here](https:/ --- And this is a footer for repository:test baseBranch:some-branch + +<!--renovate-config-hash:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855--> " `; @@ -166,6 +170,8 @@ There should be several empty lines at the end of the PR + +<!--renovate-config-hash:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855--> " `; diff --git a/lib/workers/repository/onboarding/pr/index.spec.ts b/lib/workers/repository/onboarding/pr/index.spec.ts index b8647263459f26247dce42fd7a5ced911c03ba94..490d9afcf26d899c916159d674e0d7b79b19bbe1 100644 --- a/lib/workers/repository/onboarding/pr/index.spec.ts +++ b/lib/workers/repository/onboarding/pr/index.spec.ts @@ -187,7 +187,7 @@ describe('workers/repository/onboarding/pr/index', () => { '(onboardingRebaseCheckbox="$onboardingRebaseCheckbox")', async ({ onboardingRebaseCheckbox }) => { const hash = - '8d5d8373c3fc54803f573ea57ded60686a9df8eb0430ad25da281472eed9ce4e'; // no rebase checkbox PR hash + '30029ee05ed80b34d2f743afda6e78fe20247a1eedaa9ce6a8070045c229ebfa'; // no rebase checkbox PR hash config.onboardingRebaseCheckbox = onboardingRebaseCheckbox; OnboardingState.prUpdateRequested = true; // case 'false' is tested in "breaks early when onboarding" platform.getBranchPr.mockResolvedValue( diff --git a/lib/workers/repository/onboarding/pr/index.ts b/lib/workers/repository/onboarding/pr/index.ts index 6b478979c7572c4e7fc13c51acc33ccafdc22b8b..3c1609893e14682a780927a470689eb9f363ee43 100644 --- a/lib/workers/repository/onboarding/pr/index.ts +++ b/lib/workers/repository/onboarding/pr/index.ts @@ -60,8 +60,10 @@ export async function ensureOnboardingPr( return; } } - const { rebaseCheckBox, renovateConfigHashComment } = - await getRebaseCheckboxComponents(config); + const onboardingConfigHashComment = await getOnboardingConfigHashComment( + config + ); + const rebaseCheckBox = getRebaseCheckbox(config.onboardingRebaseCheckbox); logger.debug('Filling in onboarding PR template'); let prTemplate = `Welcome to [Renovate](${ config.productLinks!.homepage @@ -135,7 +137,7 @@ If you need any further assistance then you can also [request help here](${ prBody = `${prBody}\n---\n\n${template.compile(config.prFooter, config)}\n`; } - prBody += renovateConfigHashComment; + prBody += onboardingConfigHashComment; logger.trace('prBody:\n' + prBody); @@ -203,29 +205,23 @@ If you need any further assistance then you can also [request help here](${ } } -interface RebaseCheckboxComponents { - rebaseCheckBox: string; - renovateConfigHashComment: string; -} - -async function getRebaseCheckboxComponents( - config: RenovateConfig -): Promise<RebaseCheckboxComponents> { +function getRebaseCheckbox(onboardingRebaseCheckbox?: boolean): string { let rebaseCheckBox = ''; - let renovateConfigHashComment = ''; - if (!config.onboardingRebaseCheckbox) { - return { rebaseCheckBox, renovateConfigHashComment }; + if (onboardingRebaseCheckbox) { + // Create markdown checkbox + rebaseCheckBox = `\n\n---\n\n - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.\n`; } - // Create markdown checkbox - rebaseCheckBox = `\n\n---\n\n - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.\n`; + return rebaseCheckBox; +} - // Create hashMeta +async function getOnboardingConfigHashComment( + config: RenovateConfig +): Promise<string> { const configFile = defaultConfigFile(config); const existingContents = (await getFile(configFile, config.onboardingBranch)) ?? ''; const hash = toSha256(existingContents); - renovateConfigHashComment = `\n<!--renovate-config-hash:${hash}-->\n`; - return { rebaseCheckBox, renovateConfigHashComment }; + return `\n<!--renovate-config-hash:${hash}-->\n`; }