From 0edc13a45a03b9967c8f8b17c06da8314b005731 Mon Sep 17 00:00:00 2001 From: Paul Melnikow Date: Tue, 27 Nov 2018 00:20:30 -0500 Subject: [PATCH] Add static examples to a few legacy services [travis david coveralls amo] --- services/amo/amo.service.js | 52 ++++++++++++++++++++----- services/coveralls/coveralls.service.js | 37 ++++++++++++++++-- services/david/david.service.js | 32 ++++++++++++--- services/travis/travis-build.service.js | 25 ++++++++---- 4 files changed, 119 insertions(+), 27 deletions(-) diff --git a/services/amo/amo.service.js b/services/amo/amo.service.js index 685449be5ff87..93e126fcd479a 100644 --- a/services/amo/amo.service.js +++ b/services/amo/amo.service.js @@ -17,6 +17,8 @@ const { floorCount: floorCountColor, } = require('../../lib/color-formatters') +const keywords = ['amo', 'firefox'] + class AmoDownloads extends LegacyService { static get category() { return 'downloads' @@ -25,6 +27,7 @@ class AmoDownloads extends LegacyService { static get route() { return { base: 'amo/d', + pattern: ':addonId', } } @@ -32,8 +35,9 @@ class AmoDownloads extends LegacyService { return [ { title: 'Mozilla Add-on', - previewUrl: 'dustman', - keywords: ['amo', 'firefox'], + namedParams: { addonId: 'dustman' }, + staticExample: { message: '12k', color: 'brightgreen' }, + keywords, }, ] } @@ -49,6 +53,7 @@ class AmoVersion extends LegacyService { static get route() { return { base: 'amo/v', + pattern: ':addonId', } } @@ -56,12 +61,19 @@ class AmoVersion extends LegacyService { return [ { title: 'Mozilla Add-on', - previewUrl: 'dustman', - keywords: ['amo', 'firefox'], + namedParams: { addonId: 'dustman' }, + staticExample: { message: 'v2.1.0', color: 'blue' }, + keywords, }, ] } + static get defaultBadgeData() { + return { + label: 'mozilla add-on', + } + } + static registerLegacyRouteHandler() {} } @@ -80,13 +92,25 @@ class AmoRating extends LegacyService { return [ { title: 'Mozilla Add-on', - previewUrl: 'rating/dustman', - keywords: ['amo', 'firefox'], + pattern: 'rating/:addonId', + namedParams: { addonId: 'dustman' }, + staticExample: { + label: 'rating', + message: '4/5', + color: 'brightgreen', + }, + keywords, }, { title: 'Mozilla Add-on', - previewUrl: 'stars/dustman', - keywords: ['amo', 'firefox'], + pattern: 'stars/:addonId', + namedParams: { addonId: 'dustman' }, + staticExample: { + label: 'rating', + message: starRating(4), + color: 'brightgreen', + }, + keywords, }, ] } @@ -102,6 +126,7 @@ class AmoUsers extends LegacyService { static get route() { return { base: 'amo/users', + pattern: ':addonId', } } @@ -109,12 +134,19 @@ class AmoUsers extends LegacyService { return [ { title: 'Mozilla Add-on', - previewUrl: 'dustman', - keywords: ['amo', 'firefox'], + namedParams: { addonId: 'dustman' }, + staticExample: { message: '706', color: 'brightgreen' }, + keywords, }, ] } + static get defaultBadgeData() { + return { + label: 'users', + } + } + static registerLegacyRouteHandler() {} } diff --git a/services/coveralls/coveralls.service.js b/services/coveralls/coveralls.service.js index 31cced912e6ce..7bff7774fb4f1 100644 --- a/services/coveralls/coveralls.service.js +++ b/services/coveralls/coveralls.service.js @@ -18,26 +18,55 @@ module.exports = class Coveralls extends LegacyService { } static get examples() { + const { staticExample } = this return [ { title: 'Coveralls github', - previewUrl: 'github/jekyll/jekyll', + pattern: ':vcsType/:user/:repo', + namedParams: { vcsType: 'github', user: 'jekyll', repo: 'jekyll' }, + staticExample, }, { title: 'Coveralls github branch', - previewUrl: 'github/jekyll/jekyll/master', + pattern: ':vcsType/:user/:repo/:branch', + namedParams: { + vcsType: 'github', + user: 'jekyll', + repo: 'jekyll', + branch: 'master', + }, + staticExample, }, { title: 'Coveralls bitbucket', - previewUrl: 'bitbucket/pyKLIP/pyklip', + pattern: ':vcsType/:user/:repo', + namedParams: { vcsType: 'bitbucket', user: 'pyKLIP', repo: 'pyklip' }, + staticExample, }, { title: 'Coveralls bitbucket branch', - previewUrl: 'bitbucket/pyKLIP/pyklip/master', + pattern: ':vcsType/:user/:repo/:branch', + namedParams: { + vcsType: 'bitbucket', + user: 'pyKLIP', + repo: 'pyklip', + branch: 'master', + }, + staticExample, }, ] } + static get staticExample() { + return { message: '83%', color: 'yellowgreen' } + } + + static get defaultBadgeData() { + return { + label: 'coverage', + } + } + static registerLegacyRouteHandler({ camp, cache }) { camp.route( /^\/coveralls\/(?:(bitbucket|github)\/)?([^/]+\/[^/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/, diff --git a/services/david/david.service.js b/services/david/david.service.js index fd93c6d2ad766..6c9a5a15076ff 100644 --- a/services/david/david.service.js +++ b/services/david/david.service.js @@ -18,28 +18,50 @@ module.exports = class David extends LegacyService { return [ { title: 'David', - previewUrl: 'expressjs/express', + pattern: ':user/:repo', + namedParams: { user: 'expressjs', repo: 'express' }, + staticExample: this.renderStaticExample(), }, { title: 'David', - previewUrl: 'dev/expressjs/express', + pattern: 'dev/:user/:repo', + namedParams: { user: 'expressjs', repo: 'express' }, + staticExample: this.renderStaticExample({ label: 'dev dependencies' }), }, { title: 'David', - previewUrl: 'optional/elnounch/byebye', + pattern: 'optional/:user/:repo', + namedParams: { user: 'elnounch', repo: 'byebye' }, + staticExample: this.renderStaticExample({ + label: 'optional dependencies', + }), }, { title: 'David', - previewUrl: 'peer/webcomponents/generator-element', + pattern: 'peer/:user/:repo', + namedParams: { user: 'webcomponents', repo: 'generator-element' }, + staticExample: this.renderStaticExample({ label: 'peer dependencies' }), }, { title: 'David (path)', - previewUrl: 'babel/babel', + pattern: ':user/:repo', + namedParams: { user: 'babel', repo: 'babel' }, query: { path: 'packages/babel-core' }, + staticExample: this.renderStaticExample(), }, ] } + static get defaultBadgeData() { + return { + label: 'dependencies', + } + } + + static renderStaticExample({ label } = {}) { + return { label, message: 'up to date', color: 'brightgreen' } + } + static registerLegacyRouteHandler({ camp, cache }) { camp.route( /^\/david\/(dev\/|optional\/|peer\/)?(.+?)\.(svg|png|gif|jpg|json)$/, diff --git a/services/travis/travis-build.service.js b/services/travis/travis-build.service.js index ceb919afaf517..6cd06b8b34b33 100644 --- a/services/travis/travis-build.service.js +++ b/services/travis/travis-build.service.js @@ -18,34 +18,43 @@ module.exports = class TravisBuild extends LegacyService { } static get examples() { + const { staticExample } = this return [ { title: 'Travis (.org)', - previewUrl: 'rust-lang/rust', pattern: ':user/:repo', - exampleUrl: 'rust-lang/rust', + namedParams: { user: 'rust-lang', repo: 'rust' }, + staticExample, }, { title: 'Travis (.org) branch', - previewUrl: 'rust-lang/rust/master', pattern: ':user/:repo/:branch', - exampleUrl: 'rust-lang/rust/master', + namedParams: { user: 'rust-lang', repo: 'rust', branch: 'master' }, + staticExample, }, { title: 'Travis (.com)', - previewUrl: 'com/ivandelabeldad/rackian-gateway', pattern: 'com/:user/:repo', - exampleUrl: 'com/ivandelabeldad/rackian-gateway', + namedParams: { user: 'ivandelabeldad', repo: 'rackian-gateway' }, + staticExample, }, { title: 'Travis (.com) branch', - previewUrl: 'com/ivandelabeldad/rackian-gateway/master', pattern: 'com/:user/:repo/:branch', - exampleUrl: 'com/ivandelabeldad/rackian-gateway/master', + namedParams: { + user: 'ivandelabeldad', + repo: 'rackian-gateway', + branch: 'master', + }, + staticExample, }, ] } + static staticExample() { + return { message: 'passing', color: 'brightgreen' } + } + static registerLegacyRouteHandler({ camp, cache }) { camp.route( /^\/travis(-ci)?\/(?:(com)\/)?(?!php-v)([^/]+\/[^/]+)(?:\/(.+))?\.(svg|png|gif|jpg|json)$/,