Skip to content

Commit

Permalink
[GradlePluginPortal] add gradle plugin portal (#6449)
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 authored Jun 7, 2021
1 parent 300b317 commit b0384f4
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/base-service/redirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const trace = require('./trace')
const attrSchema = Joi.object({
name: Joi.string().min(3),
category: isValidCategory,
isDeprecated: Joi.boolean().default(true),
route: isValidRoute,
examples: Joi.array().has(Joi.object()).default([]),
transformPath: Joi.func()
.maxArity(1)
.required()
Expand All @@ -34,7 +36,9 @@ module.exports = function redirector(attrs) {
const {
name,
category,
isDeprecated,
route,
examples,
transformPath,
transformQueryParams,
overrideTransformedQueryParams,
Expand All @@ -48,8 +52,9 @@ module.exports = function redirector(attrs) {
})}Redirect`

static category = category
static isDeprecated = true
static isDeprecated = isDeprecated
static route = route
static examples = examples

static register({ camp, metricInstance }, { rasterUrl }) {
const { regex, captureNames } = prepareRoute({
Expand Down
18 changes: 18 additions & 0 deletions core/base-service/redirector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ describe('Redirector', function () {
).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 () {
let port, baseUrl
beforeEach(async function () {
Expand Down
39 changes: 39 additions & 0 deletions services/gradle-plugin-portal/gradle-plugin-portal.service.js
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions services/gradle-plugin-portal/gradle-plugin-portal.tester.js
Original file line number Diff line number Diff line change
@@ -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'
)}`
)

0 comments on commit b0384f4

Please sign in to comment.