This commit is contained in:
Jonas Rutishauser 2025-01-01 01:10:17 +01:00 committed by GitHub
commit c168b6e1b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 90 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import { HeadObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { mockClient } from 'aws-sdk-client-mock';
import { codeBlock } from 'common-tags';
import { GoogleAuth as _googleAuth } from 'google-auth-library';
import { DateTime } from 'luxon';
import type { Release, ReleaseResult } from '..';
@ -315,6 +316,72 @@ describe('modules/datasource/maven/index', () => {
expect(res?.sourceUrl).toBe('https://github.com/example/test');
});
describe('supports relocation', () => {
it('with only groupId present', async () => {
const pom = codeBlock`
<project>
<distributionManagement>
<relocation>
<groupId>io.example</groupId>
</relocation>
</distributionManagement>
</project>
`;
mockGenericPackage({ pom });
const res = await get();
expect(res).toMatchObject({
replacementName: 'io.example:package',
replacementVersion: '2.0.0',
});
});
it('with only artifactId present', async () => {
const pom = codeBlock`
<project>
<distributionManagement>
<relocation>
<artifactId>foo</artifactId>
</relocation>
</distributionManagement>
</project>
`;
mockGenericPackage({ pom });
const res = await get();
expect(res).toMatchObject({
replacementName: 'org.example:foo',
replacementVersion: '2.0.0',
});
});
it('with all elments present', async () => {
const pom = codeBlock`
<project>
<distributionManagement>
<relocation>
<groupId>io.example</groupId>
<artifactId>foo</artifactId>
<version>1.2.3</version>
<message>test relocation</message>
</relocation>
</distributionManagement>
</project>
`;
mockGenericPackage({ pom });
const res = await get();
expect(res).toMatchObject({
replacementName: 'io.example:foo',
replacementVersion: '1.2.3',
deprecationMessage: 'test relocation',
});
});
});
it('removes authentication header after redirect', async () => {
const frontendHost = 'frontend_for_private_s3_repository';
const frontendUrl = `https://${frontendHost}/maven2`;

View file

@ -18,7 +18,12 @@ export type HttpResourceCheckResult = 'found' | 'not-found' | 'error' | Date;
export type DependencyInfo = Pick<
ReleaseResult,
'homepage' | 'sourceUrl' | 'packageScope'
| 'homepage'
| 'sourceUrl'
| 'packageScope'
| 'replacementName'
| 'replacementVersion'
| 'deprecationMessage'
>;
export interface MavenFetchSuccess<T = string> {

View file

@ -543,6 +543,23 @@ export async function getDependencyInfo(
}
}
const relocation = pomContent.descendantWithPath(
'distributionManagement.relocation',
);
if (relocation) {
const relocationGroup =
relocation.valueWithPath('groupId') ?? dependency.group;
const relocationName =
relocation.valueWithPath('artifactId') ?? dependency.name;
result.replacementName = `${relocationGroup}:${relocationName}`;
const relocationVersion = relocation.valueWithPath('version');
result.replacementVersion = relocationVersion ?? version;
const relocationMessage = relocation.valueWithPath('message');
if (relocationMessage) {
result.deprecationMessage = relocationMessage;
}
}
const groupId = pomContent.valueWithPath('groupId');
if (groupId) {
result.packageScope = groupId;