Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate [Requires] service #7571

Merged
merged 2 commits into from
Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 9 additions & 63 deletions services/requires/requires.service.js
Original file line number Diff line number Diff line change
@@ -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'),
})
44 changes: 10 additions & 34 deletions services/requires/requires.tester.js
Original file line number Diff line number Diff line change
@@ -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' })