Deprecate [Requires] service (#7571)

This commit is contained in:
Pierre-Yves Bigourdan
2022-02-05 15:37:37 +00:00
committed by GitHub
parent 9e8f503150
commit 449b8ed28f
2 changed files with 19 additions and 97 deletions

View File

@@ -1,65 +1,11 @@
import Joi from 'joi'
import { BaseJsonService } from '../index.js'
import { deprecatedService } from '../index.js'
const statusSchema = Joi.object({
status: Joi.string().required(),
}).required()
export default class RequiresIo extends BaseJsonService {
static category = 'dependencies'
static route = {
export default deprecatedService({
category: 'dependencies',
route: {
base: 'requires',
pattern: ':service/:user/:repo/:branch*',
}
static examples = [
{
title: 'Requires.io',
pattern: ':service/:user/:repo',
namedParams: { service: 'github', user: 'zulip', repo: 'zulip' },
staticPreview: this.render({ status: 'up-to-date' }),
},
{
title: 'Requires.io (branch)',
pattern: ':service/:user/:repo/:branch',
namedParams: {
service: 'github',
user: 'zulip',
repo: 'zulip',
branch: 'master',
},
staticPreview: this.render({ status: 'up-to-date' }),
},
]
static defaultBadgeData = { label: 'requirements' }
static render({ status }) {
let message = status
let color = 'lightgrey'
if (status === 'up-to-date') {
message = 'up to date'
color = 'brightgreen'
} else if (status === 'outdated') {
color = 'yellow'
} else if (status === 'insecure') {
color = 'red'
}
return { message, color }
}
async fetch({ service, user, repo, branch }) {
const url = `https://requires.io/api/v1/status/${service}/${user}/${repo}`
return this._requestJson({
url,
schema: statusSchema,
options: { searchParams: { branch } },
})
}
async handle({ service, user, repo, branch }) {
const { status } = await this.fetch({ service, user, repo, branch })
return this.constructor.render({ status })
}
}
format: '(?:.+?)',
},
label: 'requirements',
dateAdded: new Date('2022-02-05'),
})

View File

@@ -1,44 +1,20 @@
import Joi from 'joi'
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()
import { ServiceTester } from '../tester.js'
const isRequireStatus = Joi.string().regex(
/^(up to date|outdated|insecure|unknown)$/
)
export const t = new ServiceTester({
id: 'requires',
title: 'Requires.io',
})
// Package targets can be found at https://requires.io/public
// However, there does seem to be some retention issues where
// results for projects are purged after some number of days.
// https://github.com/badges/shields/issues/7015
// https://github.com/requires/api/issues/5
t.create('requirements (valid GitHub, without branch)')
.get('/github/Hongbo-Miao/hongbomiao.com.json')
.expectBadge({
label: 'requirements',
message: isRequireStatus,
})
t.create('requirements (valid GitHub, with branch)')
.get('/github/Hongbo-Miao/hongbomiao.com/main.json')
.expectBadge({
label: 'requirements',
message: isRequireStatus,
})
t.create('requirements (valid Bitbucket, without branch)')
t.create('no longer available (previously Bitbucket without branch)')
.get('/bitbucket/code-orange/django-ispstack.json')
.expectBadge({
label: 'requirements',
message: isRequireStatus,
message: 'no longer available',
})
t.create('requirements (valid Bitbucket, with branch)')
.get('/bitbucket/code-orange/django-ispstack/master.json')
t.create('no longer available (previously GitHub with branch)')
.get('/github/Hongbo-Miao/hongbomiao.com/main.json')
.expectBadge({
label: 'requirements',
message: isRequireStatus,
message: 'no longer available',
})
t.create('requirements (not found)')
.get('/github/PyvesB/EmptyRepo.json')
.expectBadge({ label: 'requirements', message: 'not found' })