-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
improve [MavenCentral], [MavenMetadata], and [GradlePluginPortal] #6628
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6b4f111
implement version prefix and suffix
anatawa12 33cf8bd
add tests for maven-metadata
anatawa12 dd47a0c
use maven-metadata in maven-central
anatawa12 d8c71c3
add tests of maven-central for redirecting
anatawa12 3729734
add tests of maven-central for redirecting
anatawa12 1ec3ebe
fix: maven-central: don't force color as blue
anatawa12 059fcdb
add versionPrefix for gradle-plugin-portal
anatawa12 b888cf9
add example for gradle-plugin-portal
anatawa12 cfff903
fix: gradle-plugin-portal: don't force color as blue
anatawa12 3754db5
fix test
anatawa12 2c35b3e
fix test
anatawa12 c9f7b7f
fix test
anatawa12 166a0df
remove expectBadge tests for maven central
anatawa12 559eb5f
fix test for maven-metadata
anatawa12 ba51afa
remove :versionPrefix from gradle-plugin-portal
anatawa12 f2adc83
use query parameter versionPrefix in maven-central example
anatawa12 32368dc
fix redundant pattern
anatawa12 c3927d4
remove some examples
anatawa12 37d3476
fix static preview of gradle-plugin-portal
anatawa12 845f645
fix tests
anatawa12 ee9a94d
add documentation
anatawa12 22284b8
fix static preview of gradle-plugin-portal
anatawa12 5cb4f36
fix: version prefix or suffix not found if either versionPrefix or ve…
anatawa12 1426170
Merge branch 'master' into maven-central-and-metadata
PyvesB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,46 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
const { renderVersionBadge } = require('../version') | ||
const { BaseXmlService, NotFound } = require('..') | ||
const { redirector } = require('..') | ||
const { documentation } = require('../maven-metadata/maven-metadata') | ||
|
||
const schema = Joi.object({ | ||
metadata: Joi.object({ | ||
versioning: Joi.object({ | ||
versions: Joi.object({ | ||
version: Joi.array().items(Joi.string().required()).single().required(), | ||
}).required(), | ||
}).required(), | ||
}).required(), | ||
}).required() | ||
|
||
module.exports = class MavenCentral extends BaseXmlService { | ||
static category = 'version' | ||
|
||
static route = { | ||
module.exports = redirector({ | ||
category: 'version', | ||
isDeprecated: false, | ||
route: { | ||
base: 'maven-central/v', | ||
pattern: ':groupId/:artifactId/:versionPrefix?', | ||
} | ||
|
||
static examples = [ | ||
}, | ||
examples: [ | ||
{ | ||
title: 'Maven Central', | ||
pattern: ':groupId/:artifactId', | ||
namedParams: { | ||
groupId: 'org.apache.maven', | ||
artifactId: 'apache-maven', | ||
queryParams: { | ||
versionSuffix: '-android', | ||
versionPrefix: '29', | ||
}, | ||
staticPreview: { | ||
label: 'maven-central', | ||
message: 'v3.6.0', | ||
color: 'blue', | ||
}, | ||
}, | ||
{ | ||
title: 'Maven Central with version prefix filter', | ||
pattern: ':groupId/:artifactId/:versionPrefix', | ||
namedParams: { | ||
groupId: 'org.apache.maven', | ||
artifactId: 'apache-maven', | ||
versionPrefix: '2', | ||
groupId: 'com.google.guava', | ||
artifactId: 'guava', | ||
}, | ||
staticPreview: { | ||
label: 'maven-central', | ||
message: 'v2.2.1', | ||
message: 'v29.0-android', | ||
color: 'blue', | ||
}, | ||
documentation, | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { | ||
label: 'maven-central', | ||
} | ||
|
||
async fetch({ groupId, artifactId }) { | ||
], | ||
transformPath: () => `/maven-metadata/v`, | ||
transformQueryParams: ({ groupId, artifactId, versionPrefix }) => { | ||
const group = encodeURIComponent(groupId).replace(/\./g, '/') | ||
const artifact = encodeURIComponent(artifactId) | ||
const url = `https://repo1.maven.org/maven2/${group}/${artifact}/maven-metadata.xml` | ||
return this._requestXml({ | ||
schema, | ||
url, | ||
parserOptions: { parseNodeValue: false }, | ||
}) | ||
} | ||
|
||
async handle({ groupId, artifactId, versionPrefix }) { | ||
const data = await this.fetch({ groupId, artifactId }) | ||
const versions = data.metadata.versioning.versions.version.reverse() | ||
let version = versions[0] | ||
if (versionPrefix !== undefined) { | ||
version = versions.filter(v => v.toString().startsWith(versionPrefix))[0] | ||
// if the filter returned no results, throw a NotFound | ||
if (version === undefined) | ||
throw new NotFound({ prettyMessage: 'version prefix not found' }) | ||
const metadataUrl = `https://repo1.maven.org/maven2/${group}/${artifact}/maven-metadata.xml` | ||
return { | ||
metadataUrl, | ||
label: 'maven-central', | ||
versionPrefix, | ||
} | ||
return renderVersionBadge({ version }) | ||
} | ||
} | ||
}, | ||
overrideTransformedQueryParams: true, | ||
dateAdded: new Date('2021-06-12'), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,19 @@ | ||
'use strict' | ||
|
||
const { | ||
isVPlusDottedVersionNClausesWithOptionalSuffix, | ||
} = require('../test-validators') | ||
const t = (module.exports = require('../tester').createServiceTester()) | ||
|
||
t.create('latest version') | ||
t.create('latest version redirection') | ||
.get('/com.github.fabriziocucci/yacl4j.json') // http://repo1.maven.org/maven2/com/github/fabriziocucci/yacl4j/ | ||
.expectBadge({ | ||
label: 'maven-central', | ||
message: isVPlusDottedVersionNClausesWithOptionalSuffix, | ||
}) | ||
.expectRedirect( | ||
`/maven-metadata/v.json?label=maven-central&metadataUrl=${encodeURIComponent( | ||
'https://repo1.maven.org/maven2/com/github/fabriziocucci/yacl4j/maven-metadata.xml' | ||
)}` | ||
) | ||
|
||
t.create('latest 0.8 version') | ||
t.create('latest 0.8 version redirection') | ||
.get('/com.github.fabriziocucci/yacl4j/0.8.json') // http://repo1.maven.org/maven2/com/github/fabriziocucci/yacl4j/ | ||
.expectBadge({ | ||
label: 'maven-central', | ||
message: isVPlusDottedVersionNClausesWithOptionalSuffix, | ||
}) | ||
|
||
t.create('inexistent artifact') | ||
.get('/inexistent-group-id/inexistent-artifact-id.json') | ||
.expectBadge({ label: 'maven-central', message: 'not found' }) | ||
|
||
t.create('inexistent version prefix') | ||
.get('/com.github.fabriziocucci/yacl4j/99.json') | ||
.expectBadge({ label: 'maven-central', message: 'version prefix not found' }) | ||
|
||
t.create('version ending with zero') | ||
.get('/mocked-group-id/mocked-artifact-id.json') | ||
.intercept(nock => | ||
nock('https://repo1.maven.org/maven2') | ||
.get('/mocked-group-id/mocked-artifact-id/maven-metadata.xml') | ||
.reply( | ||
200, | ||
` | ||
<metadata> | ||
<groupId>mocked-group-id</groupId> | ||
<artifactId>mocked-artifact-id</artifactId> | ||
<versioning> | ||
<latest>1.30</latest> | ||
<release>1.30</release> | ||
<versions> | ||
<version>1.30</version> | ||
</versions> | ||
<lastUpdated>20190902002617</lastUpdated> | ||
</versioning> | ||
</metadata> | ||
` | ||
) | ||
.expectRedirect( | ||
`/maven-metadata/v.json?label=maven-central&metadataUrl=${encodeURIComponent( | ||
'https://repo1.maven.org/maven2/com/github/fabriziocucci/yacl4j/maven-metadata.xml' | ||
)}&versionPrefix=0.8` | ||
) | ||
.expectBadge({ label: 'maven-central', message: 'v1.30' }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
// the file contains common constants for badges uses maven-metadata | ||
|
||
module.exports = {} | ||
|
||
module.exports.documentation = ` | ||
<p> | ||
<code>versionPrefix</code> and <code>versionSuffix</code> allow narrowing down | ||
the range of versions the badge will take into account, | ||
but they are completely optional. | ||
</p> | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a test for this case?