Skip to content

Commit

Permalink
deprecate [criterion] service (badges#8501)
Browse files Browse the repository at this point in the history
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
  • Loading branch information
chris48s and repo-ranger[bot] authored Oct 8, 2022
1 parent c7c6fa7 commit 9520760
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 84 deletions.
77 changes: 11 additions & 66 deletions services/criterion/criterion.service.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,11 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import {
IMPROVED_STATUS,
NOT_FOUND_STATUS,
REGRESSED_STATUS,
NO_CHANGE_STATUS,
} from './constants.js'

const schema = Joi.string()
.allow(IMPROVED_STATUS, REGRESSED_STATUS, NO_CHANGE_STATUS)
.required()

/**
* Criterion Badge Service
*
* Support and Contact:
* - https://github.com/chmoder/api.criterion.dev
*
* API Documentation:
* - https://app.swaggerhub.com/apis-docs/chmoder/Criterion.dev
*/
export default class Criterion extends BaseJsonService {
static category = 'analysis'
static route = { base: 'criterion', pattern: ':user/:repo' }

static examples = [
{
title: 'Criterion',
namedParams: {
user: 'chmoder',
repo: 'data_vault',
},
staticPreview: this.render({ status: IMPROVED_STATUS }),
},
]

static defaultBadgeData = { label: 'criterion' }

static render({ status }) {
let statusColor = 'lightgrey'

if (status === IMPROVED_STATUS) {
statusColor = 'brightgreen'
} else if (status === NO_CHANGE_STATUS) {
statusColor = 'green'
} else if (statusColor === REGRESSED_STATUS) {
statusColor = 'red'
}

return {
message: `${status}`,
color: statusColor,
}
}

async handle({ user, repo }) {
const status = await this._requestJson({
url: `https://api.criterion.dev/v1/${user}/${repo}/status`,
errorMessages: { 404: NOT_FOUND_STATUS },
schema,
})

return this.constructor.render({ status })
}
}
import { deprecatedService } from '../index.js'

export default deprecatedService({
category: 'analysis',
route: {
base: 'criterion',
pattern: ':various*',
},
label: 'criterion',
dateAdded: new Date('2022-10-07'),
})
26 changes: 8 additions & 18 deletions services/criterion/criterion.tester.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
import {
IMPROVED_STATUS,
REGRESSED_STATUS,
NO_CHANGE_STATUS,
NOT_FOUND_STATUS,
} from './constants.js'
export const t = await createServiceTester()
import { ServiceTester } from '../tester.js'

const isStatus = Joi.string()
.allow(IMPROVED_STATUS, REGRESSED_STATUS, NOT_FOUND_STATUS, NO_CHANGE_STATUS)
.required()
export const t = new ServiceTester({
id: 'criterion',
title: 'Criterion',
pathPrefix: '/criterion',
})

t.create('Criterion (valid repo)')
t.create('Criterion')
.get('/chmoder/credit_card.json')
.expectBadge({ label: 'criterion', message: isStatus })

t.create('Criterion (not found)')
.get('/chmoder/not-a-repo.json')
.expectBadge({ label: 'criterion', message: NOT_FOUND_STATUS })
.expectBadge({ label: 'criterion', message: 'no longer available' })

0 comments on commit 9520760

Please sign in to comment.