[GradlePluginPortal] add gradle plugin portal (#6449)
This commit is contained in:
@@ -17,7 +17,9 @@ const trace = require('./trace')
|
|||||||
const attrSchema = Joi.object({
|
const attrSchema = Joi.object({
|
||||||
name: Joi.string().min(3),
|
name: Joi.string().min(3),
|
||||||
category: isValidCategory,
|
category: isValidCategory,
|
||||||
|
isDeprecated: Joi.boolean().default(true),
|
||||||
route: isValidRoute,
|
route: isValidRoute,
|
||||||
|
examples: Joi.array().has(Joi.object()).default([]),
|
||||||
transformPath: Joi.func()
|
transformPath: Joi.func()
|
||||||
.maxArity(1)
|
.maxArity(1)
|
||||||
.required()
|
.required()
|
||||||
@@ -34,7 +36,9 @@ module.exports = function redirector(attrs) {
|
|||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
category,
|
category,
|
||||||
|
isDeprecated,
|
||||||
route,
|
route,
|
||||||
|
examples,
|
||||||
transformPath,
|
transformPath,
|
||||||
transformQueryParams,
|
transformQueryParams,
|
||||||
overrideTransformedQueryParams,
|
overrideTransformedQueryParams,
|
||||||
@@ -48,8 +52,9 @@ module.exports = function redirector(attrs) {
|
|||||||
})}Redirect`
|
})}Redirect`
|
||||||
|
|
||||||
static category = category
|
static category = category
|
||||||
static isDeprecated = true
|
static isDeprecated = isDeprecated
|
||||||
static route = route
|
static route = route
|
||||||
|
static examples = examples
|
||||||
|
|
||||||
static register({ camp, metricInstance }, { rasterUrl }) {
|
static register({ camp, metricInstance }, { rasterUrl }) {
|
||||||
const { regex, captureNames } = prepareRoute({
|
const { regex, captureNames } = prepareRoute({
|
||||||
|
|||||||
@@ -47,6 +47,24 @@ describe('Redirector', function () {
|
|||||||
).to.throw('"dateAdded" is required')
|
).to.throw('"dateAdded" is required')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('sets specified example', function () {
|
||||||
|
const examples = [
|
||||||
|
{
|
||||||
|
title: 'very old service',
|
||||||
|
pattern: ':namedParamA',
|
||||||
|
namedParams: {
|
||||||
|
namedParamA: 'namedParamAValue',
|
||||||
|
},
|
||||||
|
staticPreview: {
|
||||||
|
label: 'service',
|
||||||
|
message: 'v0.14.0',
|
||||||
|
color: 'blue',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
expect(redirector({ ...attrs, examples }).examples).to.equal(examples)
|
||||||
|
})
|
||||||
|
|
||||||
describe('ScoutCamp integration', function () {
|
describe('ScoutCamp integration', function () {
|
||||||
let port, baseUrl
|
let port, baseUrl
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const { redirector } = require('..')
|
||||||
|
|
||||||
|
module.exports = redirector({
|
||||||
|
category: 'version',
|
||||||
|
isDeprecated: false,
|
||||||
|
route: {
|
||||||
|
base: 'gradle-plugin-portal/v',
|
||||||
|
// TODO: add /:versionPrefix? when maven-metadata have versionPrefix attribute.
|
||||||
|
pattern: ':pluginId',
|
||||||
|
},
|
||||||
|
examples: [
|
||||||
|
{
|
||||||
|
title: 'Gradle Plugin Portal',
|
||||||
|
namedParams: {
|
||||||
|
pluginId: 'com.gradle.plugin-publish',
|
||||||
|
},
|
||||||
|
staticPreview: {
|
||||||
|
label: 'plugin portal',
|
||||||
|
message: 'v0.14.0',
|
||||||
|
color: 'blue',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
transformPath: () => `/maven-metadata/v`,
|
||||||
|
transformQueryParams: ({ pluginId }) => {
|
||||||
|
const groupPath = pluginId.replace(/\./g, '/')
|
||||||
|
const artifactId = `${pluginId}.gradle.plugin`
|
||||||
|
const metadataUrl = `https://plugins.gradle.org/m2/${groupPath}/${artifactId}/maven-metadata.xml`
|
||||||
|
return {
|
||||||
|
metadataUrl,
|
||||||
|
label: 'plugin portal',
|
||||||
|
color: 'blue',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
overrideTransformedQueryParams: true,
|
||||||
|
dateAdded: new Date('2021-05-30'),
|
||||||
|
})
|
||||||
27
services/gradle-plugin-portal/gradle-plugin-portal.tester.js
Normal file
27
services/gradle-plugin-portal/gradle-plugin-portal.tester.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const t = (module.exports = require('../tester').createServiceTester())
|
||||||
|
|
||||||
|
t.create('gradle plugin portal')
|
||||||
|
.get('/com.gradle.plugin-publish')
|
||||||
|
.expectRedirect(
|
||||||
|
`/maven-metadata/v.svg?color=blue&label=plugin%20portal&metadataUrl=${encodeURIComponent(
|
||||||
|
'https://plugins.gradle.org/m2/com/gradle/plugin-publish/com.gradle.plugin-publish.gradle.plugin/maven-metadata.xml'
|
||||||
|
)}`
|
||||||
|
)
|
||||||
|
|
||||||
|
t.create('gradle plugin portal with custom labels')
|
||||||
|
.get('/com.gradle.plugin-publish?label=custom%20label')
|
||||||
|
.expectRedirect(
|
||||||
|
`/maven-metadata/v.svg?color=blue&label=custom%20label&metadataUrl=${encodeURIComponent(
|
||||||
|
'https://plugins.gradle.org/m2/com/gradle/plugin-publish/com.gradle.plugin-publish.gradle.plugin/maven-metadata.xml'
|
||||||
|
)}`
|
||||||
|
)
|
||||||
|
|
||||||
|
t.create('gradle plugin portal with custom color')
|
||||||
|
.get('/com.gradle.plugin-publish?color=gray')
|
||||||
|
.expectRedirect(
|
||||||
|
`/maven-metadata/v.svg?color=gray&label=plugin%20portal&metadataUrl=${encodeURIComponent(
|
||||||
|
'https://plugins.gradle.org/m2/com/gradle/plugin-publish/com.gradle.plugin-publish.gradle.plugin/maven-metadata.xml'
|
||||||
|
)}`
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user