Skip to content

Commit

Permalink
Avoid double-encoding backticks in title template (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Mar 5, 2024
1 parent 496a06f commit 93101ca
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
38 changes: 38 additions & 0 deletions src/lib/github/v3/createPullRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,4 +560,42 @@ describe('getTitle', () => {
'Branch: "7.x". Messages: My commit message (#55) | Another commit message (#56)',
);
});

it('support backticks', () => {
const options = {
prTitle: '[{{targetBranch}}] {{commitMessages}}',
} as ValidConfigOptions;

const commits = [
{
author: {
email: '[email protected]',
name: 'Søren Louv-Jansen',
},
sourceBranch: 'main',
sourcePullRequest: {
labels: [],
title: 'My PR Title',
number: 55,
url: 'https://github.com/backport-org/different-merge-strategies/pull/55',
mergeCommit: {
sha: 'abcdefghi',
message: 'My commit message (#55)',
},
},
suggestedTargetBranches: [],
sourceCommit: {
branchLabelMapping: {},
committedDate: '2020',
sha: 'abcdefghi',
message: 'My commit message with `backticks` (#55)',
},
targetPullRequestStates: [],
},
];

expect(getTitle({ options, commits, targetBranch: '7.x' })).toEqual(
'[7.x] My commit message with `backticks` (#55)',
);
});
});
6 changes: 3 additions & 3 deletions src/lib/github/v3/createPullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ export function getTitle({

const defaultPrTitle = '[{{targetBranch}}] {{commitMessages}}';

const template = Handlebars.compile(options.prTitle ?? defaultPrTitle);

commits[0].author.name;
const template = Handlebars.compile(options.prTitle ?? defaultPrTitle, {
noEscape: true,
});

return template({
sourcePullRequest: commits[0].sourcePullRequest, // assume that all commits are from the same PR
Expand Down

0 comments on commit 93101ca

Please sign in to comment.