forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecate [criterion] service (badges#8501)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
- Loading branch information
1 parent
c7c6fa7
commit 9520760
Showing
2 changed files
with
19 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }) |