migrate some services from examples to openApi (#9903)

This commit is contained in:
chris48s
2024-01-24 20:23:12 +00:00
committed by GitHub
parent 609775ee25
commit bc41c409ff
6 changed files with 239 additions and 140 deletions

View File

@@ -1,5 +1,6 @@
import Joi from 'joi'
import { isBuildStatus, renderBuildStatusBadge } from '../build-status.js'
import { pathParams } from '../index.js'
import ScrutinizerBase from './scrutinizer-base.js'
const schema = Joi.object({
@@ -38,19 +39,39 @@ class ScrutinizerBuild extends ScrutinizerBuildBase {
pattern: ':vcs(g|b)/:user/:repo/:branch*',
}
static examples = [
{
title: 'Scrutinizer build (GitHub/Bitbucket)',
pattern: ':vcs(g|b)/:user/:repo/:branch?',
namedParams: {
vcs: 'g',
user: 'filp',
repo: 'whoops',
branch: 'master',
static openApi = {
'/scrutinizer/build/{vcs}/{user}/{repo}': {
get: {
summary: 'Scrutinizer build (GitHub/Bitbucket)',
parameters: pathParams(
{
name: 'vcs',
example: 'g',
description: 'Platform: Either Github or Bitbucket',
schema: { type: 'string', enum: this.getEnum('vcs') },
},
{ name: 'user', example: 'filp' },
{ name: 'repo', example: 'whoops' },
),
},
staticPreview: renderBuildStatusBadge({ status: 'passing' }),
},
]
'/scrutinizer/build/{vcs}/{user}/{repo}/{branch}': {
get: {
summary: 'Scrutinizer build (GitHub/Bitbucket) with branch',
parameters: pathParams(
{
name: 'vcs',
example: 'g',
description: 'Platform: Either Github or Bitbucket',
schema: { type: 'string', enum: this.getEnum('vcs') },
},
{ name: 'user', example: 'filp' },
{ name: 'repo', example: 'whoops' },
{ name: 'branch', example: 'master' },
),
},
},
}
async handle({ vcs, user, repo, branch }) {
return this.makeBadge({
@@ -71,19 +92,29 @@ class ScrutinizerGitLabBuild extends ScrutinizerBuildBase {
// The example used is valid, but the project will not be accessible if Shields users try to use it.
// https://gitlab.propertywindow.nl/propertywindow/client
// https://scrutinizer-ci.com/gl/propertywindow/propertywindow/client/badges/quality-score.png?b=master&s=dfae6992a48184cc2333b4c349cec0447f0d67c2
static examples = [
{
title: 'Scrutinizer build (GitLab)',
pattern: ':instance/:user/:repo/:branch?',
namedParams: {
instance: 'propertywindow',
user: 'propertywindow',
repo: 'client',
branch: 'master',
static openApi = {
'/scrutinizer/build/gl/{instance}/{user}/{repo}': {
get: {
summary: 'Scrutinizer build (GitLab)',
parameters: pathParams(
{ name: 'instance', example: 'propertywindow' },
{ name: 'user', example: 'propertywindow' },
{ name: 'repo', example: 'client' },
),
},
staticPreview: renderBuildStatusBadge({ status: 'passing' }),
},
]
'/scrutinizer/build/gl/{instance}/{user}/{repo}/{branch}': {
get: {
summary: 'Scrutinizer build (GitLab) with branch',
parameters: pathParams(
{ name: 'instance', example: 'propertywindow' },
{ name: 'user', example: 'propertywindow' },
{ name: 'repo', example: 'client' },
{ name: 'branch', example: 'master' },
),
},
},
}
async handle({ instance, user, repo, branch }) {
return this.makeBadge({

View File

@@ -1,6 +1,6 @@
import Joi from 'joi'
import { colorScale } from '../color-formatters.js'
import { NotFound } from '../index.js'
import { NotFound, pathParams } from '../index.js'
import ScrutinizerBase from './scrutinizer-base.js'
const schema = Joi.object({
@@ -70,19 +70,39 @@ class ScrutinizerCoverage extends ScrutinizerCoverageBase {
pattern: ':vcs(g|b)/:user/:repo/:branch*',
}
static examples = [
{
title: 'Scrutinizer coverage (GitHub/BitBucket)',
pattern: ':vcs(g|b)/:user/:repo/:branch?',
namedParams: {
vcs: 'g',
user: 'filp',
repo: 'whoops',
branch: 'master',
static openApi = {
'/scrutinizer/coverage/{vcs}/{user}/{repo}': {
get: {
summary: 'Scrutinizer coverage (GitHub/Bitbucket)',
parameters: pathParams(
{
name: 'vcs',
example: 'g',
description: 'Platform: Either Github or Bitbucket',
schema: { type: 'string', enum: this.getEnum('vcs') },
},
{ name: 'user', example: 'filp' },
{ name: 'repo', example: 'whoops' },
),
},
staticPreview: this.render({ coverage: 86 }),
},
]
'/scrutinizer/coverage/{vcs}/{user}/{repo}/{branch}': {
get: {
summary: 'Scrutinizer coverage (GitHub/Bitbucket) with branch',
parameters: pathParams(
{
name: 'vcs',
example: 'g',
description: 'Platform: Either Github or Bitbucket',
schema: { type: 'string', enum: this.getEnum('vcs') },
},
{ name: 'user', example: 'filp' },
{ name: 'repo', example: 'whoops' },
{ name: 'branch', example: 'master' },
),
},
},
}
async handle({ vcs, user, repo, branch }) {
return this.makeBadge({
@@ -103,19 +123,29 @@ class ScrutinizerCoverageGitLab extends ScrutinizerCoverageBase {
// The example used is valid, but the project will not be accessible if Shields users try to use it.
// https://gitlab.propertywindow.nl/propertywindow/client
// https://scrutinizer-ci.com/gl/propertywindow/propertywindow/client/badges/quality-score.png?b=master&s=dfae6992a48184cc2333b4c349cec0447f0d67c2
static examples = [
{
title: 'Scrutinizer coverage (GitLab)',
pattern: ':instance/:user/:repo/:branch?',
namedParams: {
instance: 'propertywindow',
user: 'propertywindow',
repo: 'client',
branch: 'master',
static openApi = {
'/scrutinizer/coverage/gl/{instance}/{user}/{repo}': {
get: {
summary: 'Scrutinizer coverage (GitLab)',
parameters: pathParams(
{ name: 'instance', example: 'propertywindow' },
{ name: 'user', example: 'propertywindow' },
{ name: 'repo', example: 'client' },
),
},
staticPreview: this.render({ coverage: 94 }),
},
]
'/scrutinizer/coverage/gl/{instance}/{user}/{repo}/{branch}': {
get: {
summary: 'Scrutinizer coverage (GitLab) with branch',
parameters: pathParams(
{ name: 'instance', example: 'propertywindow' },
{ name: 'user', example: 'propertywindow' },
{ name: 'repo', example: 'client' },
{ name: 'branch', example: 'master' },
),
},
},
}
async handle({ instance, user, repo, branch }) {
return this.makeBadge({

View File

@@ -1,5 +1,6 @@
import Joi from 'joi'
import { colorScale } from '../color-formatters.js'
import { pathParams } from '../index.js'
import ScrutinizerBase from './scrutinizer-base.js'
const schema = Joi.object({
@@ -58,19 +59,39 @@ class ScrutinizerQuality extends ScrutinizerQualityBase {
pattern: ':vcs(g|b)/:user/:repo/:branch*',
}
static examples = [
{
title: 'Scrutinizer code quality (GitHub/Bitbucket)',
pattern: ':vcs(g|b)/:user/:repo/:branch?',
namedParams: {
vcs: 'g',
user: 'filp',
repo: 'whoops',
branch: 'master',
static openApi = {
'/scrutinizer/quality/{vcs}/{user}/{repo}': {
get: {
summary: 'Scrutinizer quality (GitHub/Bitbucket)',
parameters: pathParams(
{
name: 'vcs',
example: 'g',
description: 'Platform: Either Github or Bitbucket',
schema: { type: 'string', enum: this.getEnum('vcs') },
},
{ name: 'user', example: 'filp' },
{ name: 'repo', example: 'whoops' },
),
},
staticPreview: this.render({ score: 8.26 }),
},
]
'/scrutinizer/quality/{vcs}/{user}/{repo}/{branch}': {
get: {
summary: 'Scrutinizer quality (GitHub/Bitbucket) with branch',
parameters: pathParams(
{
name: 'vcs',
example: 'g',
description: 'Platform: Either Github or Bitbucket',
schema: { type: 'string', enum: this.getEnum('vcs') },
},
{ name: 'user', example: 'filp' },
{ name: 'repo', example: 'whoops' },
{ name: 'branch', example: 'master' },
),
},
},
}
async handle({ vcs, user, repo, branch }) {
return this.makeBadge({
@@ -91,19 +112,29 @@ class ScrutinizerQualityGitLab extends ScrutinizerQualityBase {
// The example used is valid, but the project will not be accessible if Shields users try to use it.
// https://gitlab.propertywindow.nl/propertywindow/client
// https://scrutinizer-ci.com/gl/propertywindow/propertywindow/client/badges/quality-score.png?b=master&s=dfae6992a48184cc2333b4c349cec0447f0d67c2
static examples = [
{
title: 'Scrutinizer coverage (GitLab)',
pattern: ':instance/:user/:repo/:branch?',
namedParams: {
instance: 'propertywindow',
user: 'propertywindow',
repo: 'client',
branch: 'master',
static openApi = {
'/scrutinizer/quality/gl/{instance}/{user}/{repo}': {
get: {
summary: 'Scrutinizer quality (GitLab)',
parameters: pathParams(
{ name: 'instance', example: 'propertywindow' },
{ name: 'user', example: 'propertywindow' },
{ name: 'repo', example: 'client' },
),
},
staticPreview: this.render({ score: 10.0 }),
},
]
'/scrutinizer/quality/gl/{instance}/{user}/{repo}/{branch}': {
get: {
summary: 'Scrutinizer quality (GitLab) with branch',
parameters: pathParams(
{ name: 'instance', example: 'propertywindow' },
{ name: 'user', example: 'propertywindow' },
{ name: 'repo', example: 'client' },
{ name: 'branch', example: 'master' },
),
},
},
}
async handle({ instance, user, repo, branch }) {
return this.makeBadge({