Skip to content

Commit e307fa2

Browse files
authored
feat(prBody): Support templates in changelogUrl (renovatebot#35380)
1 parent 1a1bc9e commit e307fa2

File tree

3 files changed

+70
-4
lines changed

3 files changed

+70
-4
lines changed

docs/usage/configuration-options.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,6 +2738,19 @@ To read the changelogs you must use the link.
27382738
}
27392739
```
27402740

2741+
`changelogUrl` supports template compilation.
2742+
2743+
```json title="Setting the changelog URL for the dummy package using a template"
2744+
{
2745+
"packageRules": [
2746+
{
2747+
"matchPackageNames": ["dummy"],
2748+
"changelogUrl": "https://github.com/org/monorepo/blob/{{{sourceDirectory}}}/my-custom-changelog.txt"
2749+
}
2750+
]
2751+
}
2752+
```
2753+
27412754
<!-- prettier-ignore -->
27422755
!!! note
27432756
Renovate can fetch changelogs from Bitbucket, Bitbucket Server / Data Center, Gitea (Forgejo), GitHub and GitLab platforms only, and setting the URL to an unsupported host/platform type won't change that.

lib/workers/repository/update/pr/body/index.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ describe('workers/repository/update/pr/body/index', () => {
7171
});
7272

7373
it('massages upgrades', () => {
74+
template.compile.mockImplementation((x) => x);
75+
7476
const upgrade = {
7577
manager: 'some-manager',
7678
branchName: 'some-branch',
@@ -172,6 +174,54 @@ describe('workers/repository/update/pr/body/index', () => {
172174
});
173175
});
174176

177+
it('templates changelogUrl', () => {
178+
template.compile.mockImplementation((x) =>
179+
x === '{{ testTemplate }}'
180+
? 'https://raw.githubusercontent.com/some/templated/CHANGELOG.md'
181+
: x,
182+
);
183+
184+
const upgrade = {
185+
manager: 'some-manager',
186+
branchName: 'some-branch',
187+
dependencyUrl: 'https://github.com/foo/bar',
188+
sourceUrl: 'https://github.com/foo/bar',
189+
sourceDirectory: '/baz',
190+
changelogUrl: '{{ testTemplate }}',
191+
homepage: 'https://example.com',
192+
};
193+
194+
getPrBody(
195+
{
196+
manager: 'some-manager',
197+
baseBranch: 'base',
198+
branchName: 'some-branch',
199+
upgrades: [upgrade],
200+
},
201+
{
202+
debugData: {
203+
updatedInVer: '1.2.3',
204+
createdInVer: '1.2.3',
205+
targetBranch: 'base',
206+
},
207+
},
208+
{},
209+
);
210+
211+
expect(upgrade).toMatchObject({
212+
branchName: 'some-branch',
213+
changelogUrl: '{{ testTemplate }}',
214+
depNameLinked:
215+
'[undefined](https://example.com) ([source](https://github.com/foo/bar/tree/HEAD/baz), [changelog](https://raw.githubusercontent.com/some/templated/CHANGELOG.md))',
216+
dependencyUrl: 'https://github.com/foo/bar',
217+
homepage: 'https://example.com',
218+
references:
219+
'[homepage](https://example.com), [source](https://github.com/foo/bar/tree/HEAD/baz), [changelog](https://raw.githubusercontent.com/some/templated/CHANGELOG.md)',
220+
sourceDirectory: '/baz',
221+
sourceUrl: 'https://github.com/foo/bar',
222+
});
223+
});
224+
175225
it('uses dependencyUrl as primary link', () => {
176226
const upgrade = {
177227
manager: 'some-manager',

lib/workers/repository/update/pr/body/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,11 @@ function massageUpdateMetadata(config: BranchConfig): void {
4848
`[source](${getFullSourceUrl(sourceUrl, sourceRootPath, sourceDirectory)})`,
4949
);
5050
}
51-
if (changelogUrl) {
52-
otherLinks.push(`[changelog](${changelogUrl})`);
51+
const templatedChangelogUrl = changelogUrl
52+
? template.compile(changelogUrl, upgrade, true)
53+
: undefined;
54+
if (templatedChangelogUrl) {
55+
otherLinks.push(`[changelog](${templatedChangelogUrl})`);
5356
}
5457
if (otherLinks.length) {
5558
depNameLinked += ` (${otherLinks.join(', ')})`;
@@ -64,8 +67,8 @@ function massageUpdateMetadata(config: BranchConfig): void {
6467
`[source](${getFullSourceUrl(sourceUrl, sourceRootPath, sourceDirectory)})`,
6568
);
6669
}
67-
if (changelogUrl) {
68-
references.push(`[changelog](${changelogUrl})`);
70+
if (templatedChangelogUrl) {
71+
references.push(`[changelog](${templatedChangelogUrl})`);
6972
}
7073
upgrade.references = references.join(', ');
7174
});

0 commit comments

Comments
 (0)