-
-
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
[GradlePluginPortal] add gradle plugin portal #6449
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bc71797
add gradle-plugin-portal as a copy of maven-central
anatawa12 2f29da8
update entrypoint and fetching
anatawa12 0c5b7f6
update example
anatawa12 7ba795b
update tests
anatawa12 3bf9147
change name of class of gradle-plugin-portal
anatawa12 ab71049
add examples and isDeprecated for redirector
anatawa12 e63a555
implement gradle-plugin-portal as a redirector
anatawa12 dc38a2e
run pret tier
anatawa12 ef6439f
fix falling tests
anatawa12 43a792a
add more tests
anatawa12 8c66f39
delete commented example
anatawa12 74ede93
Merge branch 'master' into gradle-plugin-portal
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
81 changes: 81 additions & 0 deletions
81
services/gradle-plugin-portal/gradle-plugin-portal.service.js
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,81 @@ | ||
'use strict' | ||
|
||
const Joi = require('joi') | ||
const { renderVersionBadge } = require('../version') | ||
const { BaseXmlService, NotFound } = require('..') | ||
|
||
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 GradlePluginPortal extends BaseXmlService { | ||
static category = 'version' | ||
|
||
static route = { | ||
base: 'gradle-plugin-portal/v', | ||
pattern: ':pluginId/:versionPrefix?', | ||
} | ||
|
||
static examples = [ | ||
{ | ||
title: 'Gradle Plugin Portal', | ||
pattern: ':pluginId', | ||
namedParams: { | ||
pluginId: 'com.gradle.plugin-publish', | ||
}, | ||
staticPreview: { | ||
label: 'plugin portal', | ||
message: 'v0.14.0', | ||
color: 'blue', | ||
}, | ||
}, | ||
{ | ||
title: 'Gradle Plugin Portal with version prefix filter', | ||
pattern: ':pluginId/:versionPrefix', | ||
namedParams: { | ||
pluginId: 'com.gradle.plugin-publish', | ||
versionPrefix: '0.10', | ||
}, | ||
staticPreview: { | ||
label: 'plugin portal', | ||
message: 'v0.10.1', | ||
color: 'blue', | ||
}, | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { | ||
label: 'plugin portal', | ||
} | ||
|
||
async fetch({ pluginId }) { | ||
const plugin = encodeURIComponent(pluginId) | ||
const group = plugin.replace(/\./g, '/') | ||
const artifact = `${plugin}.gradle.plugin` | ||
const url = `https://plugins.gradle.org/m2/${group}/${artifact}/maven-metadata.xml` | ||
return this._requestXml({ | ||
schema, | ||
url, | ||
parserOptions: { parseNodeValue: false }, | ||
}) | ||
} | ||
|
||
async handle({ pluginId, versionPrefix }) { | ||
const data = await this.fetch({ pluginId }) | ||
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' }) | ||
} | ||
return renderVersionBadge({ version }) | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
services/gradle-plugin-portal/gradle-plugin-portal.tester.js
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,55 @@ | ||
'use strict' | ||
|
||
const { | ||
isVPlusDottedVersionNClausesWithOptionalSuffix, | ||
} = require('../test-validators') | ||
const t = (module.exports = require('../tester').createServiceTester()) | ||
|
||
// https://plugins.gradle.org/m2/com/gradle/plugin-publish/com.gradle.plugin-publish.gradle.plugin/ | ||
t.create('latest version').get('/com.gradle.plugin-publish.json').expectBadge({ | ||
label: 'plugin portal', | ||
message: isVPlusDottedVersionNClausesWithOptionalSuffix, | ||
}) | ||
|
||
// https://plugins.gradle.org/m2/com/gradle/plugin-publish/com.gradle.plugin-publish.gradle.plugin/ | ||
t.create('latest 0.10 version') | ||
.get('/com.gradle.plugin-publish/0.10.json') | ||
.expectBadge({ | ||
label: 'plugin portal', | ||
message: isVPlusDottedVersionNClausesWithOptionalSuffix, | ||
}) | ||
|
||
t.create('inexistent artifact') | ||
.get('/inexistent-plugin-id.json') | ||
.expectBadge({ label: 'plugin portal', message: 'not found' }) | ||
|
||
t.create('inexistent version prefix') | ||
.get('/com.gradle.plugin-publish/1000.json') | ||
.expectBadge({ label: 'plugin portal', message: 'version prefix not found' }) | ||
|
||
t.create('version ending with zero') | ||
.get('/mocked-plugin-id.json') | ||
.intercept(nock => | ||
nock('https://plugins.gradle.org/m2') | ||
.get( | ||
'/mocked-plugin-id/mocked-plugin-id.gradle.plugin/maven-metadata.xml' | ||
) | ||
.reply( | ||
200, | ||
` | ||
<metadata> | ||
<groupId>mocked-plugin-id</groupId> | ||
<artifactId>mocked-plugin-id.gradle.plugin</artifactId> | ||
<versioning> | ||
<latest>1.30</latest> | ||
<release>1.30</release> | ||
<versions> | ||
<version>1.30</version> | ||
</versions> | ||
<lastUpdated>20190902002617</lastUpdated> | ||
</versioning> | ||
</metadata> | ||
` | ||
) | ||
) | ||
.expectBadge({ label: 'plugin portal', message: 'v1.30' }) |
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.
Please remove this commented example for now. When and if we get round to adding a version prefix attribute to maven-metadata, it's easy enough to re-add at that point, without the risk of the commented code having gone stale in the meantime. 😉
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.
I removed this comment.