Skip to content

Commit

Permalink
fix(template): allow prBodyDefinitions in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
amezin committed Jun 27, 2024
1 parent bbde807 commit d5d289f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/util/template/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}";
Expand Down
9 changes: 9 additions & 0 deletions lib/util/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ const compileInputProxyHandler: ProxyHandler<CompileInput> = {

const value = target[prop];

if (prop === 'prBodyDefinitions') {
// Expose all prBodyDefinitions.*
return value;
}

if (is.array(value)) {
return value.map((element) =>
is.primitive(element)
Expand Down Expand Up @@ -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 },
Expand Down

0 comments on commit d5d289f

Please sign in to comment.