Skip to content

Commit

Permalink
Merge branch 'main' into fix/source-links-bitbucket-2
Browse files Browse the repository at this point in the history
  • Loading branch information
setchy authored Nov 24, 2024
2 parents 3b27407 + 1234169 commit 34ea176
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 37 deletions.
30 changes: 8 additions & 22 deletions lib/modules/datasource/maven/util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type Request from 'got/dist/source/core';
import { partial } from '../../../../test/util';
import { HOST_DISABLED } from '../../../constants/error-messages';
import { type Http, HttpError } from '../../../util/http';
import { parseUrl } from '../../../util/url';
import { Http, HttpError } from '../../../util/http';
import {
checkResource,
downloadHttpProtocol,
downloadMavenXml,
downloadS3Protocol,
} from './util';

const http = new Http('test');

function httpError({
name,
message = 'unknown error',
Expand Down Expand Up @@ -46,25 +47,16 @@ describe('modules/datasource/maven/util', () => {
describe('downloadMavenXml', () => {
it('returns empty object for unsupported protocols', async () => {
const res = await downloadMavenXml(
null as never, // #22198
parseUrl('unsupported://server.com/'),
);
expect(res).toEqual({});
});

it('returns empty object for invalid URLs', async () => {
const res = await downloadMavenXml(
null as never, // #22198
null,
http,
new URL('unsupported://server.com/'),
);
expect(res).toEqual({});
});
});

describe('downloadS3Protocol', () => {
it('returns null for non-S3 URLs', async () => {
// #22198
const res = await downloadS3Protocol(parseUrl('http://not-s3.com/')!);
const res = await downloadS3Protocol(new URL('http://not-s3.com/'));
expect(res).toBeNull();
});
});
Expand Down Expand Up @@ -114,18 +106,12 @@ describe('modules/datasource/maven/util', () => {

describe('checkResource', () => {
it('returns not found for unsupported protocols', async () => {
const res = await checkResource(
null as never, // #22198
'unsupported://server.com/',
);
const res = await checkResource(http, 'unsupported://server.com/');
expect(res).toBe('not-found');
});

it('returns error for invalid URLs', async () => {
const res = await checkResource(
null as never, // #22198
'not-a-valid-url',
);
const res = await checkResource(http, 'not-a-valid-url');
expect(res).toBe('error');
});
});
Expand Down
6 changes: 1 addition & 5 deletions lib/modules/datasource/maven/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,8 @@ export function getMavenUrl(

export async function downloadMavenXml(
http: Http,
pkgUrl: URL | null,
pkgUrl: URL,
): Promise<MavenXml> {
if (!pkgUrl) {
return {};
}

const protocol = pkgUrl.protocol;

if (protocol === 'http:' || protocol === 'https:') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('workers/repository/update/pr/changelog/bitbucket/index', () => {
it('handles release notes', async () => {
httpMock
.scope(apiBaseUrl)
.get('/2.0/repositories/some-org/some-repo/src?pagelen=100')
.get('/2.0/repositories/some-org/some-repo/src/HEAD?pagelen=100')
.reply(200, bitbucketTreeResponse)
.get('/2.0/repositories/some-org/some-repo/src/abcd/CHANGELOG.md')
.reply(200, changelogMd);
Expand All @@ -94,7 +94,7 @@ describe('workers/repository/update/pr/changelog/bitbucket/index', () => {
it('handles missing release notes', async () => {
httpMock
.scope(apiBaseUrl)
.get('/2.0/repositories/some-org/some-repo/src?pagelen=100')
.get('/2.0/repositories/some-org/some-repo/src/HEAD?pagelen=100')
.reply(200, bitbucketTreeResponseNoChangelogFiles);
const res = await getReleaseNotesMdFile(bitbucketProject);
expect(res).toBeNull();
Expand Down
17 changes: 12 additions & 5 deletions lib/workers/repository/update/pr/changelog/bitbucket/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'node:path';
import is from '@sindresorhus/is';
import changelogFilenameRegex from 'changelog-filename-regex';
import { logger } from '../../../../../../logger';
Expand All @@ -18,15 +19,16 @@ const bitbucketHttp = new BitbucketHttp(id);
export async function getReleaseNotesMd(
repository: string,
apiBaseUrl: string,
_sourceDirectory?: string,
sourceDirectory?: string,
): Promise<ChangeLogFile | null> {
logger.trace('bitbucket.getReleaseNotesMd()');

const repositorySourceURl = joinUrlParts(
apiBaseUrl,
`2.0/repositories`,
'2.0/repositories',
repository,
'src',
'src/HEAD',
sourceDirectory ?? '',
);

const rootFiles = (
Expand All @@ -41,7 +43,9 @@ export async function getReleaseNotesMd(

const allFiles = rootFiles.filter((f) => f.type === 'commit_file');

const files = allFiles.filter((f) => changelogFilenameRegex.test(f.path));
const files = allFiles.filter((f) =>
changelogFilenameRegex.test(path.basename(f.path)),
);

const changelogFile = files
.sort((a, b) => compareChangelogFilePath(a.path, b.path))
Expand All @@ -59,7 +63,10 @@ export async function getReleaseNotesMd(

const fileRes = await bitbucketHttp.get(
joinUrlParts(
repositorySourceURl,
apiBaseUrl,
'2.0/repositories',
repository,
'src',
changelogFile.commit.hash,
changelogFile.path,
),
Expand Down
6 changes: 3 additions & 3 deletions tools/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ ARG BASE_IMAGE_TYPE=slim
# --------------------------------------
# slim image
# --------------------------------------
FROM ghcr.io/renovatebot/base-image:9.9.6@sha256:4a0e4b6be9cd684dc5d5e5e4ae82acfae92c200e9bc129d318f865a192c0808e AS slim-base
FROM ghcr.io/renovatebot/base-image:9.10.0@sha256:8d2882ef06158bf71a0ac95085582c0bbbf775d51c3ac567639fa718d4dac091 AS slim-base

# --------------------------------------
# full image
# --------------------------------------
FROM ghcr.io/renovatebot/base-image:9.9.6-full@sha256:7c4ee885c42417b083839f4ea32a4eb2514c080835a12e6357bd05af925f8398 AS full-base
FROM ghcr.io/renovatebot/base-image:9.10.0-full@sha256:d39f9b1f282850a2e397db6c03b6eef0f1e6eb44e984a4f344e05a45ea3bc895 AS full-base

ENV RENOVATE_BINARY_SOURCE=global

# --------------------------------------
# build image
# --------------------------------------
FROM --platform=$BUILDPLATFORM ghcr.io/renovatebot/base-image:9.9.6@sha256:4a0e4b6be9cd684dc5d5e5e4ae82acfae92c200e9bc129d318f865a192c0808e AS build
FROM --platform=$BUILDPLATFORM ghcr.io/renovatebot/base-image:9.10.0@sha256:8d2882ef06158bf71a0ac95085582c0bbbf775d51c3ac567639fa718d4dac091 AS build

# We want a specific node version here
# renovate: datasource=node-version
Expand Down

0 comments on commit 34ea176

Please sign in to comment.