From 930592355898544b65e98877d1c4bf614ae4fc79 Mon Sep 17 00:00:00 2001 From: Aleksandr Mezin Date: Fri, 28 Jun 2024 11:29:02 +0300 Subject: [PATCH] fix(template): allow `prBodyDefinitions` in templates (#29893) --- lib/util/template/index.spec.ts | 16 ++++++++++++++++ lib/util/template/index.ts | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/util/template/index.spec.ts b/lib/util/template/index.spec.ts index 4c1be2e68877a3..e6a4b732afce93 100644 --- a/lib/util/template/index.spec.ts +++ b/lib/util/template/index.spec.ts @@ -114,6 +114,22 @@ describe('util/template/index', () => { expect(output).toBe('CUSTOM_FOO is foo'); }); + it('and has access to prBodyDefinitions', () => { + const userTemplate = + 'Issues: {{#each upgrades}}{{{prBodyDefinitions.Issue}}} {{/each}}'; + const config = { + upgrades: [ + { + prBodyDefinitions: { + Issue: '1234', + }, + }, + ], + }; + const output = template.compile(userTemplate, config); + expect(output).toBe('Issues: 1234 '); + }); + it('replace', () => { const userTemplate = "{{ replace '[a-z]+\\.github\\.com' 'ghc' depName }}{{ replace 'some' 'other' depType }}"; diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts index 55fc771b2dba0e..e489e2c8df1013 100644 --- a/lib/util/template/index.ts +++ b/lib/util/template/index.ts @@ -207,6 +207,11 @@ const compileInputProxyHandler: ProxyHandler = { const value = target[prop]; + if (prop === 'prBodyDefinitions') { + // Expose all prBodyDefinitions.* + return value; + } + if (is.array(value)) { return value.map((element) => is.primitive(element) @@ -248,6 +253,10 @@ export function compile( continue; } for (const varName of varNames) { + if (varName === 'prBodyDefinitions') { + // Allow all prBodyDefinitions.* + break; + } if (!allowedFieldsList.includes(varName)) { logger.info( { varName, template },