Skip to content

Commit

Permalink
fix(changelogUrl): migrate and fix (renovatebot#29495)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins authored and kosmoz committed Jun 12, 2024
1 parent 9ecf037 commit 26c5800
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 140 deletions.
10 changes: 4 additions & 6 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -3120,19 +3120,17 @@ Tokens can be configured via `hostRules` using the `"merge-confidence"` `hostTyp
}
```

### customChangelogUrl

Use this field to set the source URL for a package, including overriding an existing one.
Source URLs are necessary in order to look up changelogs.
### changelogUrl

Use this field to set the changelog URL for a package, including overriding any existing one.
Using this field we can specify the exact URL to fetch changelogs from.

```json title="Setting the source URL for the dummy package"
```json title="Setting the changelog URL for the dummy package"
{
"packageRules": [
{
"matchPackageNames": ["dummy"],
"customChangelogUrl": "https://github.com/org/dummy"
"changelogUrl": "https://github.com/org/dummy"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/key-concepts/changelogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Set to `off` if changelog fetching is causing a problem.

Set to `branch` if you have an advanced use case where you're embedding changelogs in the Git commit itself, we don't recommend this due to its potential size.

### [`customChangelogUrl`](../configuration-options.md#customchangelogurl)
### [`changelogUrl`](../configuration-options.md#changelogurl)

This doesn't help with _fetching_ the changelogs, but if you configure it then Renovate will include a link to this URL in the PR body, so users can click through to read the changelog.

Expand Down
1 change: 1 addition & 0 deletions lib/config/migrations/migrations-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class MigrationsService {
static readonly renamedProperties: ReadonlyMap<string, string> = new Map([
['adoptium-java', 'java-version'],
['azureAutoApprove', 'autoApprove'],
['customChangelogUrl', 'changelogUrl'],
['endpoints', 'hostRules'],
['excludedPackageNames', 'excludePackageNames'],
['exposeEnv', 'exposeAllEnv'],
Expand Down
2 changes: 1 addition & 1 deletion lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ const options: RenovateOptions[] = [
env: false,
},
{
name: 'customChangelogUrl',
name: 'changelogUrl',
description:
'If set, Renovate will use this URL to fetch changelogs for a matched dependency. Valid only within a `packageRules` object.',
type: 'string',
Expand Down
2 changes: 1 addition & 1 deletion lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface RenovateSharedConfig {
commitMessagePrefix?: string;
commitMessageTopic?: string;
confidential?: boolean;
customChangelogUrl?: string;
changelogUrl?: string;
dependencyDashboardApproval?: boolean;
draftPR?: boolean;
enabled?: boolean;
Expand Down
35 changes: 0 additions & 35 deletions lib/workers/repository/update/pr/changelog/gitea/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,41 +395,6 @@ describe('workers/repository/update/pr/changelog/gitea/index', () => {
// TODO: find right mocks
httpMock.clear(false);
});

it('supports overwriting sourceUrl for self-hosted gitea changelog', async () => {
httpMock.scope('https://git.test.com').persist().get(/.*/).reply(200, []);
const sourceUrl = 'https://git.test.com/meno/dropzone/';
const replacementSourceUrl =
'https://git.test.com/replacement/sourceurl/';
const config = {
...upgrade,
platform: 'gitea',
endpoint: 'https://git.test.com/api/v1/',
sourceUrl,
customChangelogUrl: replacementSourceUrl,
};
hostRules.add({
hostType: 'gitea',
matchHost: 'https://git.test.com/',
token: 'abc',
});
expect(await getChangeLogJSON(config)).toMatchObject({
hasReleaseNotes: false,
project: {
apiBaseUrl: 'https://git.test.com/api/v1/',
baseUrl: 'https://git.test.com/',
packageName: 'renovate',
repository: 'replacement/sourceurl',
sourceDirectory: undefined,
sourceUrl: 'https://git.test.com/replacement/sourceurl/',
type: 'gitea',
},
});
expect(config.sourceUrl).toBe(sourceUrl); // ensure unmodified function argument

// TODO: find right mocks
httpMock.clear(false);
});
});

describe('hasValidRepository', () => {
Expand Down
59 changes: 0 additions & 59 deletions lib/workers/repository/update/pr/changelog/github/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,34 +275,6 @@ describe('workers/repository/update/pr/changelog/github/index', () => {
});
});

it('supports overwriting sourceUrl for supports github enterprise and github.com changelog', async () => {
const sourceUrl = upgrade.sourceUrl;
const replacementSourceUrl = 'https://github.com/sindresorhus/got';
const config = {
...upgrade,
endpoint: 'https://github-enterprise.example.com/',
customChangelogUrl: replacementSourceUrl,
};
hostRules.add({
hostType: 'github',
token: 'super_secret',
matchHost: 'https://github-enterprise.example.com/',
});
expect(await getChangeLogJSON(config)).toMatchObject({
hasReleaseNotes: true,
project: {
apiBaseUrl: 'https://api.github.com/',
baseUrl: 'https://github.com/',
packageName: 'renovate',
repository: 'sindresorhus/got',
sourceDirectory: undefined,
sourceUrl: 'https://github.com/sindresorhus/got',
type: 'github',
},
});
expect(upgrade.sourceUrl).toBe(sourceUrl); // ensure unmodified function argument
});

it('supports github enterprise and github enterprise changelog', async () => {
hostRules.add({
hostType: 'github',
Expand Down Expand Up @@ -336,37 +308,6 @@ describe('workers/repository/update/pr/changelog/github/index', () => {
});
});

it('supports overwriting sourceUrl for github enterprise and github enterprise changelog', async () => {
const sourceUrl = 'https://github-enterprise.example.com/chalk/chalk';
const replacementSourceUrl =
'https://github-enterprise.example.com/sindresorhus/got';
const config = {
...upgrade,
sourceUrl,
endpoint: 'https://github-enterprise.example.com/',
customChangelogUrl: replacementSourceUrl,
};
hostRules.add({
hostType: 'github',
matchHost: 'https://github-enterprise.example.com/',
token: 'abc',
});
process.env.GITHUB_ENDPOINT = '';
expect(await getChangeLogJSON(config)).toMatchObject({
hasReleaseNotes: true,
project: {
apiBaseUrl: 'https://github-enterprise.example.com/api/v3/',
baseUrl: 'https://github-enterprise.example.com/',
packageName: 'renovate',
repository: 'sindresorhus/got',
sourceDirectory: undefined,
sourceUrl: 'https://github-enterprise.example.com/sindresorhus/got',
type: 'github',
},
});
expect(config.sourceUrl).toBe(sourceUrl); // ensure unmodified function argument
});

it('works with same version releases but different prefix', async () => {
const githubTagsMock = jest.spyOn(githubGraphql, 'queryTags');
githubTagsMock.mockResolvedValue(
Expand Down
33 changes: 0 additions & 33 deletions lib/workers/repository/update/pr/changelog/gitlab/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,39 +316,6 @@ describe('workers/repository/update/pr/changelog/gitlab/index', () => {
],
});
});

it('supports overwriting sourceUrl for self-hosted gitlab changelog', async () => {
httpMock.scope('https://git.test.com').persist().get(/.*/).reply(200, []);
const sourceUrl = 'https://git.test.com/meno/dropzone/';
const replacementSourceUrl =
'https://git.test.com/replacement/sourceurl/';
const config = {
...upgrade,
platform: 'gitlab',
endpoint: 'https://git.test.com/api/v4/',
sourceUrl,
customChangelogUrl: replacementSourceUrl,
};
hostRules.add({
hostType: 'gitlab',
matchHost: 'https://git.test.com/',
token: 'abc',
});
process.env.GITHUB_ENDPOINT = '';
expect(await getChangeLogJSON(config)).toMatchObject({
hasReleaseNotes: false,
project: {
apiBaseUrl: 'https://git.test.com/api/v4/',
baseUrl: 'https://git.test.com/',
packageName: 'renovate',
repository: 'replacement/sourceurl',
sourceDirectory: undefined,
sourceUrl: 'https://git.test.com/replacement/sourceurl/',
type: 'gitlab',
},
});
expect(config.sourceUrl).toBe(sourceUrl); // ensure unmodified function argument
});
});

describe('hasValidRepository', () => {
Expand Down
6 changes: 2 additions & 4 deletions lib/workers/repository/update/pr/changelog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import type { ChangeLogResult } from './types';
export * from './types';

export async function getChangeLogJSON(
_config: BranchUpgradeConfig,
config: BranchUpgradeConfig,
): Promise<ChangeLogResult | null> {
const sourceUrl = _config.customChangelogUrl ?? _config.sourceUrl!;
const config: BranchUpgradeConfig = { ..._config, sourceUrl };
const { versioning, currentVersion, newVersion } = config;
const { sourceUrl, versioning, currentVersion, newVersion } = config;
try {
if (!(sourceUrl && currentVersion && newVersion)) {
return null;
Expand Down

0 comments on commit 26c5800

Please sign in to comment.