Skip to content

Commit

Permalink
feat(changelogs): Include depName in release name patterns (#30395)
Browse files Browse the repository at this point in the history
  • Loading branch information
usmonster authored Aug 14, 2024
1 parent 5ff0778 commit f001bd9
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 10 deletions.
47 changes: 46 additions & 1 deletion lib/workers/repository/update/pr/changelog/release-notes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
});
});

it('gets release notes with body "other-"', async () => {
it('gets release notes with body "other-" (packageName)', async () => {
githubReleasesMock.mockResolvedValueOnce([
{
version: 'other-1.0.0',
Expand Down Expand Up @@ -644,6 +644,51 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
});
});

it('gets release notes with body "other-" (depName)', async () => {
githubReleasesMock.mockResolvedValueOnce([
{
version: 'other-1.0.0',
releaseTimestamp: '2020-01-01',
id: 1,
url: 'https://github.com/some/other-repository/releases/other-1.0.0',
name: 'some/dep',
description: 'some body',
},
{
version: 'other-1.0.1',
releaseTimestamp: '2020-01-01',
id: 2,
url: 'https://github.com/some/other-repository/releases/other-1.0.1',
name: 'some/dep',
description:
'some body #123, [#124](https://github.com/some/yet-other-repository/issues/124)',
},
]);

const res = await getReleaseNotes(
{
...githubProject,
repository: 'some/other-repository',
packageName: 'some.registry/some/other',
depName: 'other',
},
partial<ChangeLogRelease>({
version: '1.0.1',
gitRef: '1.0.1',
}),
partial<BranchUpgradeConfig>(),
);
expect(res).toEqual({
body: 'some body [#123](https://github.com/some/other-repository/issues/123), [#124](https://github.com/some/yet-other-repository/issues/124)\n',
id: 2,
name: 'some/dep',
notesSourceUrl:
'https://api.github.com/repos/some/other-repository/releases',
tag: 'other-1.0.1',
url: 'https://github.com/some/other-repository/releases/other-1.0.1',
});
});

it('gets release notes with body "other_v"', async () => {
githubReleasesMock.mockResolvedValueOnce([
{
Expand Down
18 changes: 14 additions & 4 deletions lib/workers/repository/update/pr/changelog/release-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,22 @@ export async function getReleaseNotes(
release: ChangeLogRelease,
config: BranchUpgradeConfig,
): Promise<ChangeLogNotes | null> {
const { packageName, repository } = project;
const { packageName, depName, repository } = project;
const { version, gitRef } = release;
// TODO: types (#22198)
logger.trace(`getReleaseNotes(${repository}, ${version}, ${packageName!})`);
logger.trace(
`getReleaseNotes(${repository}, ${version}, ${packageName!}, ${depName!})`,
);
const releases = await getCachedReleaseList(project, release);
logger.trace({ releases }, 'Release list from getReleaseList');
let releaseNotes: ChangeLogNotes | null = null;

let matchedRelease = getExactReleaseMatch(packageName!, version, releases);
let matchedRelease = getExactReleaseMatch(
packageName!,
depName!,
version,
releases,
);
if (is.undefined(matchedRelease)) {
// no exact match of a release then check other cases
matchedRelease = releases.find(
Expand All @@ -166,10 +173,13 @@ export async function getReleaseNotes(

function getExactReleaseMatch(
packageName: string,
depName: string,
version: string,
releases: ChangeLogNotes[],
): ChangeLogNotes | undefined {
const exactReleaseReg = regEx(`${packageName}[@_-]v?${version}`);
const exactReleaseReg = regEx(
`(?:^|/)(?:${packageName}|${depName})[@_-]v?${version}`,
);
const candidateReleases = releases.filter((r) => r.tag?.endsWith(version));
const matchedRelease = candidateReleases.find((r) =>
exactReleaseReg.test(r.tag!),
Expand Down
17 changes: 12 additions & 5 deletions lib/workers/repository/update/pr/changelog/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export abstract class ChangeLogSource {
const newVersion = config.newVersion!;
const sourceUrl = config.sourceUrl!;
const packageName = config.packageName!;
const depName = config.depName!;
const sourceDirectory = config.sourceDirectory;
const version = allVersioning.get(versioning);

Expand Down Expand Up @@ -111,7 +112,9 @@ export abstract class ChangeLogSource {
.sort((a, b) => version.sortVersions(a.version, b.version));

if (validReleases.length < 2) {
logger.debug(`Not enough valid releases for dep ${packageName}`);
logger.debug(
`Not enough valid releases for dep ${depName} (${packageName})`,
);
return null;
}

Expand Down Expand Up @@ -143,8 +146,8 @@ export abstract class ChangeLogSource {
compare: {},
};
const tags = await getTags();
const prevHead = this.getRef(version, packageName, prev, tags);
const nextHead = this.getRef(version, packageName, next, tags);
const prevHead = this.getRef(version, packageName, depName, prev, tags);
const nextHead = this.getRef(version, packageName, depName, next, tags);
if (is.nonEmptyString(prevHead) && is.nonEmptyString(nextHead)) {
release.compare.url = this.getCompareURL(
baseUrl,
Expand Down Expand Up @@ -185,11 +188,13 @@ export abstract class ChangeLogSource {
private findTagOfRelease(
version: allVersioning.VersioningApi,
packageName: string,
depName: string,
depNewVersion: string,
tags: string[],
): string | undefined {
const regex = regEx(`(?:${packageName}|release)[@-]`, undefined, false);
const exactReleaseRegex = regEx(`${packageName}[@\\-_]v?${depNewVersion}`);
const releaseRegexPrefix = `^(?:${packageName}|${depName}|release)[@_-]v?`;
const regex = regEx(releaseRegexPrefix, undefined, false);
const exactReleaseRegex = regEx(`${releaseRegexPrefix}${depNewVersion}`);
const exactTagsList = tags.filter((tag) => {
return exactReleaseRegex.test(tag);
});
Expand All @@ -202,12 +207,14 @@ export abstract class ChangeLogSource {
private getRef(
version: allVersioning.VersioningApi,
packageName: string,
depName: string,
release: Release,
tags: string[],
): string | null {
const tagName = this.findTagOfRelease(
version,
packageName,
depName,
release.version,
tags,
);
Expand Down
1 change: 1 addition & 0 deletions lib/workers/repository/update/pr/changelog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type ChangeLogPlatform = 'bitbucket' | 'gitea' | 'github' | 'gitlab';

export interface ChangeLogProject {
packageName?: string;
depName?: string;
type: ChangeLogPlatform;
apiBaseUrl: string;
baseUrl: string;
Expand Down

0 comments on commit f001bd9

Please sign in to comment.