Skip to content
Snippets Groups Projects
Unverified Commit 8433ad98 authored by Fernando Mora's avatar Fernando Mora Committed by GitHub
Browse files

fix(datasource/sbt-package): Fallbacks to maven when no sbt directory listing available (#18590)

parent 64ddabc8
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,8 @@ describe('modules/datasource/sbt-package/index', () => { ...@@ -32,6 +32,8 @@ describe('modules/datasource/sbt-package/index', () => {
.get('/maven/org/scalatest/') .get('/maven/org/scalatest/')
.reply(404) .reply(404)
.get('/maven/org.scalatest/') .get('/maven/org.scalatest/')
.reply(404)
.get('/maven/org/scalatest/scalatest/maven-metadata.xml')
.reply(404); .reply(404);
const res = await getPkgReleases({ const res = await getPkgReleases({
...@@ -52,6 +54,10 @@ describe('modules/datasource/sbt-package/index', () => { ...@@ -52,6 +54,10 @@ describe('modules/datasource/sbt-package/index', () => {
.get('/maven2/com/example/empty/') .get('/maven2/com/example/empty/')
.reply(200, '') .reply(200, '')
.get('/maven2/com.example/') .get('/maven2/com.example/')
.reply(404)
.get('/maven2/com/example/empty/maven-metadata.xml')
.reply(404)
.get('/maven2/com/example/empty/index.html')
.reply(404); .reply(404);
const res = await getPkgReleases({ const res = await getPkgReleases({
...@@ -206,10 +212,14 @@ describe('modules/datasource/sbt-package/index', () => { ...@@ -206,10 +212,14 @@ describe('modules/datasource/sbt-package/index', () => {
}); });
}); });
it('falls back to Maven for GitLab-hosted packages', async () => { it('falls back to Maven for orgarization root folder non-listable repositories', async () => {
httpMock httpMock
.scope('https://gitlab.com/api/v4/projects/123/packages/maven/') .scope('https://gitlab.com/api/v4/projects/123/packages/maven/')
.get('/org/example/example/maven-metadata.xml') .get('/org/example/')
.reply(404)
.get('/org.example/')
.reply(404)
.get('/org/example/example_2.13/maven-metadata.xml')
.reply( .reply(
200, 200,
` `
...@@ -227,15 +237,15 @@ describe('modules/datasource/sbt-package/index', () => { ...@@ -227,15 +237,15 @@ describe('modules/datasource/sbt-package/index', () => {
</metadata> </metadata>
` `
) )
.head('/org/example/example/1.2.3/example-1.2.3.pom') .head('/org/example/example_2.13/1.2.3/example_2.13-1.2.3.pom')
.reply(200) .reply(200)
.get('/org/example/example/1.2.3/example-1.2.3.pom') .get('/org/example/example_2.13/1.2.3/example_2.13-1.2.3.pom')
.reply(200); .reply(200);
const res = await getPkgReleases({ const res = await getPkgReleases({
versioning: mavenVersioning.id, versioning: mavenVersioning.id,
datasource: SbtPackageDatasource.id, datasource: SbtPackageDatasource.id,
depName: 'org.example:example', depName: 'org.example:example_2.13',
registryUrls: [ registryUrls: [
'https://gitlab.com/api/v4/projects/123/packages/maven/', 'https://gitlab.com/api/v4/projects/123/packages/maven/',
], ],
......
import { XmlDocument } from 'xmldoc'; import { XmlDocument } from 'xmldoc';
import { logger } from '../../../logger'; import { logger } from '../../../logger';
import { detectPlatform } from '../../../util/common';
import { Http } from '../../../util/http'; import { Http } from '../../../util/http';
import { regEx } from '../../../util/regex'; import { regEx } from '../../../util/regex';
import { ensureTrailingSlash } from '../../../util/url'; import { ensureTrailingSlash } from '../../../util/url';
...@@ -153,12 +152,6 @@ export class SbtPackageDatasource extends MavenDatasource { ...@@ -153,12 +152,6 @@ export class SbtPackageDatasource extends MavenDatasource {
return null; return null;
} }
const platform = detectPlatform(registryUrl);
if (platform === 'gitlab') {
const mavenReleases = await super.getReleases(config);
return mavenReleases;
}
const [groupId, artifactId] = packageName.split(':'); const [groupId, artifactId] = packageName.split(':');
const groupIdSplit = groupId.split('.'); const groupIdSplit = groupId.split('.');
const artifactIdSplit = artifactId.split('_'); const artifactIdSplit = artifactId.split('_');
...@@ -200,6 +193,14 @@ export class SbtPackageDatasource extends MavenDatasource { ...@@ -200,6 +193,14 @@ export class SbtPackageDatasource extends MavenDatasource {
} }
} }
logger.debug(
`No versions discovered for ${packageName} listing organization root package folder, fallback to maven datasource for version discovery`
);
const mavenReleaseResult = await super.getReleases(config);
if (mavenReleaseResult) {
return mavenReleaseResult;
}
logger.debug( logger.debug(
`No versions found for ${packageName} in ${searchRoots.length} repositories` `No versions found for ${packageName} in ${searchRoots.length} repositories`
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment