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(datasource/maven): look for maven snapshot pom #11327

Merged
merged 16 commits into from Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
452 changes: 452 additions & 0 deletions lib/datasource/clojure/__snapshots__/index.spec.ts.snap

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions lib/datasource/clojure/index.spec.ts
Expand Up @@ -9,13 +9,20 @@ import { ClojureDatasource } from '.';
const baseUrl = 'https://clojars.org/repo';
const baseUrlCustom = 'https://custom.registry.renovatebot.com';

interface SnapshotOpts {
version: string;
jarStatus?: number;
meta?: string;
}

interface MockOpts {
dep?: string;
base?: string;
meta?: string | null;
pom?: string | null;
latest?: string;
jars?: Record<string, number> | null;
snapshots?: SnapshotOpts[] | null;
}

function mockGenericPackage(opts: MockOpts = {}) {
Expand All @@ -41,6 +48,29 @@ function mockGenericPackage(opts: MockOpts = {}) {
'2.0.0': 200,
}
: opts.jars;
const snapshots =
opts.snapshots === undefined
? [
{
version: '1.0.3-SNAPSHOT',
meta: loadFixture(
'metadata-snapshot-version.xml',
upath.join('..', 'maven')
),
jarStatus: 200,
},
{
version: '1.0.4-SNAPSHOT',
meta: loadFixture(
'metadata-snapshot-version-invalid.xml',
upath.join('..', 'maven')
),
},
{
version: '1.0.5-SNAPSHOT',
},
]
: opts.snapshots;

const scope = httpMock.scope(base);

Expand Down Expand Up @@ -69,6 +99,45 @@ function mockGenericPackage(opts: MockOpts = {}) {
.reply(status, '', { 'Last-Modified': timestamp });
});
}

if (snapshots) {
snapshots.forEach((snapshot) => {
if (snapshot.meta) {
scope
.get(`/${packagePath}/${snapshot.version}/maven-metadata.xml`)
.reply(200, snapshot.meta);
} else {
scope
.get(`/${packagePath}/${snapshot.version}/maven-metadata.xml`)
.reply(404, '');
}

if (snapshot.jarStatus) {
const [major, minor, patch] = snapshot.version
.replace('-SNAPSHOT', '')
.split('.')
.map((x) => parseInt(x, 10))
.map((x) => (x < 10 ? `0${x}` : `${x}`));
const timestamp = `2020-01-01T${major}:${minor}:${patch}.000Z`;
scope
.head(
`/${packagePath}/${
snapshot.version
}/${artifact}-${snapshot.version.replace(
'-SNAPSHOT',
''
)}-20200101.${major}${minor}${patch}-${parseInt(patch, 10)}.pom`
)
.reply(snapshot.jarStatus, '', { 'Last-Modified': timestamp });
} else {
scope
.head(
`/${packagePath}/${snapshot.version}/${artifact}-${snapshot.version}.pom`
)
.reply(404, '');
}
});
}
}
function get(
depName = 'org.example:package',
Expand Down Expand Up @@ -109,6 +178,7 @@ describe('datasource/clojure/index', () => {
meta: loadFixture('metadata-extra.xml', upath.join('..', 'maven')),
latest: '3.0.0',
jars: { '3.0.0': 200 },
snapshots: [],
});

const { releases } = await get(
Expand All @@ -119,6 +189,7 @@ describe('datasource/clojure/index', () => {

expect(releases).toMatchObject([
{ version: '1.0.0' },
{ version: '1.0.3-SNAPSHOT' },
{ version: '2.0.0' },
{ version: '3.0.0' },
]);
Expand Down
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>org.example</groupId>
<artifactId>package</artifactId>
<version>1.0.4-SNAPSHOT</version>
<versioning>
<snapshot>
<buildNumber>4</buildNumber>
<!-- Missing timestamp -->
</snapshot>
<lastUpdated>20130301200000</lastUpdated>
</versioning>
</metadata>
11 changes: 11 additions & 0 deletions lib/datasource/maven/__fixtures__/metadata-snapshot-version.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?><metadata>
<groupId>org.example</groupId>
<artifactId>package</artifactId>
<version>1.0.3-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20200101.010003</timestamp>
<buildNumber>3</buildNumber>
</snapshot>
</versioning>
</metadata>
3 changes: 3 additions & 0 deletions lib/datasource/maven/__fixtures__/metadata.xml
Expand Up @@ -9,6 +9,9 @@
<version>1.0.0</version>
<version>1.0.1</version>
<version>1.0.2</version>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
<version>1.0.5-SNAPSHOT</version>
<version>2.0.0</version>
</versions>
<lastUpdated>20210101000000</lastUpdated>
Expand Down