Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(changelogs): wrong release url #25097

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('workers/repository/update/pr/changelog/gitea/index', () => {
notesSourceUrl:
'https://gitea.com/api/v1/repos/meno/dropzone/releases',
tag: 'v5.6.1',
url: 'https://gitea.com/api/v1/repos/meno/dropzone/releases/tag/v5.6.1',
url: 'https://gitea.com/meno/dropzone/releases/tag/v5.6.1',
},
},
{ version: '5.6.0' },
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/update/pr/changelog/gitea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function getReleaseList(
ReleasesSchema
);
return res.body.map((release) => ({
url: `${apiUrl}/tag/${release.tag_name}`,
url: `${project.baseUrl}${project.repository}/releases/tag/${release.tag_name}`,
notesSourceUrl: apiUrl,
name: release.name,
body: release.body,
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/update/pr/changelog/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function getReleaseList(
_release: ChangeLogRelease
): Promise<ChangeLogNotes[]> {
logger.trace('github.getReleaseList()');
const apiBaseUrl = project.apiBaseUrl!; // TODO #22198
const apiBaseUrl = project.apiBaseUrl;
const repository = project.repository;
const notesSourceUrl = joinUrlParts(
apiBaseUrl,
Expand Down
17 changes: 5 additions & 12 deletions lib/workers/repository/update/pr/changelog/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { logger } from '../../../../../../logger';
import type { GitlabRelease } from '../../../../../../modules/datasource/gitlab-releases/types';
import type { GitlabTreeNode } from '../../../../../../types/platform/gitlab';
import { GitlabHttp } from '../../../../../../util/http/gitlab';
import { ensureTrailingSlash } from '../../../../../../util/url';
import type {
ChangeLogFile,
ChangeLogNotes,
Expand All @@ -21,9 +20,7 @@ export async function getReleaseNotesMd(
): Promise<ChangeLogFile | null> {
logger.trace('gitlab.getReleaseNotesMd()');
const urlEncodedRepo = encodeURIComponent(repository);
const apiPrefix = `${ensureTrailingSlash(
apiBaseUrl
)}projects/${urlEncodedRepo}/repository/`;
const apiPrefix = `${apiBaseUrl}projects/${urlEncodedRepo}/repository/`;

// https://docs.gitlab.com/13.2/ee/api/repositories.html#list-repository-tree
const tree = (
Expand Down Expand Up @@ -64,20 +61,16 @@ export async function getReleaseList(
_release: ChangeLogRelease
): Promise<ChangeLogNotes[]> {
logger.trace('gitlab.getReleaseNotesMd()');
// TODO #22198
const apiBaseUrl = project.apiBaseUrl!;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
const repository = project.repository!;
const apiBaseUrl = project.apiBaseUrl;
const repository = project.repository;
const urlEncodedRepo = encodeURIComponent(repository);
const apiUrl = `${ensureTrailingSlash(
apiBaseUrl
)}projects/${urlEncodedRepo}/releases`;
const apiUrl = `${apiBaseUrl}projects/${urlEncodedRepo}/releases`;

const res = await http.getJson<GitlabRelease[]>(`${apiUrl}?per_page=100`, {
paginate: true,
});
return res.body.map((release) => ({
url: `${apiUrl}/${release.tag_name}`,
url: `${project.baseUrl}${repository}/-/releases/${release.tag_name}`,
notesSourceUrl: apiUrl,
name: release.name,
body: release.description,
Expand Down
24 changes: 18 additions & 6 deletions lib/workers/repository/update/pr/changelog/release-notes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,21 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
});

it('returns ChangeLogResult without release notes', async () => {
httpMock
.scope(
'https://gitlab.com/api/v4/projects/gitlab-org%2Fgitter%2Fwebapp'
)
.get('/repository/tree?per_page=100&path=lib')
.reply(200, [])
.get('/releases?per_page=100')
.reply(200, []);
const input = {
project: partial<ChangeLogProject>({
type: 'gitlab',
repository: 'https://gitlab.com/gitlab-org/gitter/webapp/',
repository: 'gitlab-org/gitter/webapp',
sourceDirectory: 'lib',
apiBaseUrl: 'https://gitlab.com/api/v4/',
baseUrl: 'https://gitlab.com/',
}),
versions: [
partial<ChangeLogRelease>({
Expand All @@ -159,9 +169,11 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
).toEqual({
hasReleaseNotes: false,
project: {
repository: 'https://gitlab.com/gitlab-org/gitter/webapp/',
repository: 'gitlab-org/gitter/webapp',
type: 'gitlab',
sourceDirectory: 'lib',
apiBaseUrl: 'https://gitlab.com/api/v4/',
baseUrl: 'https://gitlab.com/',
},
versions: [
{
Expand Down Expand Up @@ -252,13 +264,13 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
notesSourceUrl:
'https://gitlab.com/api/v4/projects/some%2Fyet-other-repository/releases',
tag: 'v1.0.0',
url: 'https://gitlab.com/api/v4/projects/some%2Fyet-other-repository/releases/v1.0.0',
url: 'https://gitlab.com/some/yet-other-repository/-/releases/v1.0.0',
},
{
notesSourceUrl:
'https://gitlab.com/api/v4/projects/some%2Fyet-other-repository/releases',
tag: 'v1.0.1',
url: 'https://gitlab.com/api/v4/projects/some%2Fyet-other-repository/releases/v1.0.1',
url: 'https://gitlab.com/some/yet-other-repository/-/releases/v1.0.1',
},
]);
});
Expand Down Expand Up @@ -291,13 +303,13 @@ describe('workers/repository/update/pr/changelog/release-notes', () => {
notesSourceUrl:
'https://my.custom.domain/api/v4/projects/some%2Fyet-other-repository/releases',
tag: 'v1.0.0',
url: 'https://my.custom.domain/api/v4/projects/some%2Fyet-other-repository/releases/v1.0.0',
url: 'https://my.custom.domain/some/yet-other-repository/-/releases/v1.0.0',
},
{
notesSourceUrl:
'https://my.custom.domain/api/v4/projects/some%2Fyet-other-repository/releases',
tag: 'v1.0.1',
url: 'https://my.custom.domain/api/v4/projects/some%2Fyet-other-repository/releases/v1.0.1',
url: 'https://my.custom.domain/some/yet-other-repository/-/releases/v1.0.1',
},
]);
});
Expand Down
8 changes: 4 additions & 4 deletions lib/workers/repository/update/pr/changelog/release-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function getCachedReleaseList(
): Promise<ChangeLogNotes[]> {
const { repository, apiBaseUrl } = project;
// TODO: types (#22198)
const cacheKey = `getReleaseList-${apiBaseUrl!}-${repository}`;
const cacheKey = `getReleaseList-${apiBaseUrl}-${repository}`;
const cachedResult = memCache.get<Promise<ChangeLogNotes[]>>(cacheKey);
// istanbul ignore if
if (cachedResult !== undefined) {
Expand Down Expand Up @@ -241,7 +241,7 @@ export async function getReleaseNotesMdFileInner(
project: ChangeLogProject
): Promise<ChangeLogFile | null> {
const { repository, type } = project;
const apiBaseUrl = project.apiBaseUrl!;
const apiBaseUrl = project.apiBaseUrl;
const sourceDirectory = project.sourceDirectory!;
try {
switch (type) {
Expand Down Expand Up @@ -295,8 +295,8 @@ export function getReleaseNotesMdFile(
const { sourceDirectory, repository, apiBaseUrl } = project;
// TODO: types (#22198)
const cacheKey = sourceDirectory
? `getReleaseNotesMdFile@v2-${repository}-${sourceDirectory}-${apiBaseUrl!}`
: `getReleaseNotesMdFile@v2-${repository}-${apiBaseUrl!}`;
? `getReleaseNotesMdFile@v2-${repository}-${sourceDirectory}-${apiBaseUrl}`
: `getReleaseNotesMdFile@v2-${repository}-${apiBaseUrl}`;
const cachedResult = memCache.get<Promise<ChangeLogFile | null>>(cacheKey);
// istanbul ignore if
if (cachedResult !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/update/pr/changelog/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type ChangeLogPlatform = 'bitbucket' | 'gitea' | 'github' | 'gitlab';
export interface ChangeLogProject {
packageName?: string;
type: ChangeLogPlatform;
apiBaseUrl?: string;
apiBaseUrl: string;
baseUrl: string;
repository: string;
sourceUrl: string;
Expand Down
1 change: 1 addition & 0 deletions lib/workers/repository/update/pr/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ describe('workers/repository/update/pr/index', () => {
type: 'github',
repository: 'some/repo',
baseUrl: 'https://github.com',
apiBaseUrl: 'https://api.github.com/',
sourceUrl: 'https://github.com/some/repo',
},
versions: [
Expand Down