Repository: badges/shields (js)

Issue:
Add badge for gradle plugin portal
It would be cool if we have a badge for the [gradle plugin portal](https://plugins.gradle.org/).

I image it like similar the maven central or the bintray badge.
[![Bintray](https://img.shields.io/bintray/v/asciidoctor/maven/asciidoctorj.svg)]() (If it's working of course 🙃)
[![Maven Central](https://img.shields.io/maven-central/v/org.apache.maven/apache-maven.svg)]()
plugin portal | v0.9.95

You can use this URL for example: (don't know how shields works, but I think you need that 😄)
https://plugins.gradle.org/plugin/org.shipkit.java-publish/0.9.95

Pull request:
[GradlePluginPortal] add gradle plugin portal
<!--
    Be sure to review our Contributing guidelines to help streamline the merging of your PR!

    * PR title conventions - https://github.com/badges/shields/blob/master/CONTRIBUTING.md#running-service-tests-in-pull-requests
    * Code formatting - https://github.com/badges/shields/blob/master/CONTRIBUTING.md#prettier
    * Merge processes and reminders - https://github.com/badges/shields/blob/master/CONTRIBUTING.md#pull-requests
-->

Closes #1125 

Patch:
diff --git a/core/base-service/redirector.js b/core/base-service/redirector.js
index 1028f033a1..5d499e9dad 100644
--- a/core/base-service/redirector.js
+++ b/core/base-service/redirector.js
@@ -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()
@@ -34,7 +36,9 @@ module.exports = function redirector(attrs) {
   const {
     name,
     category,
+    isDeprecated,
     route,
+    examples,
     transformPath,
     transformQueryParams,
     overrideTransformedQueryParams,
@@ -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({
diff --git a/core/base-service/redirector.spec.js b/core/base-service/redirector.spec.js
index ef051723cb..1f81913c6f 100644
--- a/core/base-service/redirector.spec.js
+++ b/core/base-service/redirector.spec.js
@@ -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 () {
diff --git a/services/gradle-plugin-portal/gradle-plugin-portal.service.js b/services/gradle-plugin-portal/gradle-plugin-portal.service.js
new file mode 100644
index 0000000000..25f82e9307
--- /dev/null
+++ b/services/gradle-plugin-portal/gradle-plugin-portal.service.js
@@ -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'),
+})


Test patch:
diff --git a/services/gradle-plugin-portal/gradle-plugin-portal.tester.js b/services/gradle-plugin-portal/gradle-plugin-portal.tester.js
new file mode 100644
index 0000000000..6de2421c8b
--- /dev/null
+++ b/services/gradle-plugin-portal/gradle-plugin-portal.tester.js
@@ -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'
+    )}`
+  )