deprecate [travis].org badges (#9171)

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
chris48s
2023-05-14 20:24:07 +01:00
committed by GitHub
parent 0c44117b5b
commit 165159eec3
4 changed files with 39 additions and 136 deletions

View File

@@ -1,6 +1,6 @@
import Joi from 'joi' import Joi from 'joi'
import { isBuildStatus, renderBuildStatusBadge } from '../build-status.js' import { isBuildStatus, renderBuildStatusBadge } from '../build-status.js'
import { BaseSvgScrapingService } from '../index.js' import { BaseSvgScrapingService, deprecatedService } from '../index.js'
const schema = Joi.object({ const schema = Joi.object({
message: Joi.alternatives() message: Joi.alternatives()
@@ -8,13 +8,13 @@ const schema = Joi.object({
.required(), .required(),
}).required() }).required()
export default class TravisBuild extends BaseSvgScrapingService { export class TravisComBuild extends BaseSvgScrapingService {
static category = 'build' static category = 'build'
static route = { static route = {
base: 'travis', base: 'travis',
format: '(?:(com)/)?(?!php-v)([^/]+/[^/]+?)(?:/(.+?))?', format: 'com/(?!php-v)([^/]+/[^/]+?)(?:/(.+?))?',
capture: ['comDomain', 'userRepo', 'branch'], capture: ['userRepo', 'branch'],
} }
static examples = [ static examples = [
@@ -73,11 +73,10 @@ export default class TravisBuild extends BaseSvgScrapingService {
return renderBuildStatusBadge({ status }) return renderBuildStatusBadge({ status })
} }
async handle({ comDomain, userRepo, branch }) { async handle({ userRepo, branch }) {
const domain = comDomain || 'org'
const { message: status } = await this._requestSvg({ const { message: status } = await this._requestSvg({
schema, schema,
url: `https://api.travis-ci.${domain}/${userRepo}.svg`, url: `https://api.travis-ci.com/${userRepo}.svg`,
options: { searchParams: { branch } }, options: { searchParams: { branch } },
valueMatcher: />([^<>]+)<\/text><\/g>/, valueMatcher: />([^<>]+)<\/text><\/g>/,
}) })
@@ -85,3 +84,14 @@ export default class TravisBuild extends BaseSvgScrapingService {
return this.constructor.render({ status }) return this.constructor.render({ status })
} }
} }
export const TravisOrgBuild = deprecatedService({
category: 'build',
route: {
base: 'travis',
format: '(?!php-v)([^/]+/[^/]+?)(?:/(.+?))?',
capture: ['userRepo', 'branch'],
},
label: 'build',
dateAdded: new Date('2023-05-13'),
})

View File

@@ -5,31 +5,20 @@ export const t = await createServiceTester()
// Travis (.org) CI // Travis (.org) CI
t.create('build status on default branch') t.create('build status without branch, deprecated')
.get('/rust-lang/rust.json') .get('/rust-lang/rust.json')
.expectBadge({ .expectBadge({
label: 'build', label: 'build',
message: Joi.alternatives().try(isBuildStatus, Joi.equal('unknown')), message: 'no longer available',
}) })
t.create('build status on named branch') t.create('build status on named branch, deprecated')
.get('/rust-lang/rust/stable.json') .get('/rust-lang/rust/stable.json')
.expectBadge({ .expectBadge({
label: 'build', label: 'build',
message: Joi.alternatives().try(isBuildStatus, Joi.equal('unknown')), message: 'no longer available',
}) })
t.create('unknown repo')
.get('/this-repo/does-not-exist.json')
.expectBadge({ label: 'build', message: 'unknown' })
t.create('invalid svg response')
.get('/foo/bar.json')
.intercept(nock =>
nock('https://api.travis-ci.org').get('/foo/bar.svg').reply(200)
)
.expectBadge({ label: 'build', message: 'unparseable svg response' })
// Travis (.com) CI // Travis (.com) CI
t.create('build status on default branch') t.create('build status on default branch')

View File

@@ -1,100 +1,13 @@
import Joi from 'joi' import { deprecatedService } from '../index.js'
import {
minorVersion,
versionReduction,
getPhpReleases,
} from '../php-version.js'
import { BaseJsonService } from '../index.js'
const optionalNumberOrString = Joi.alternatives(Joi.string(), Joi.number()) const TravisPhpVersion = deprecatedService({
const schema = Joi.object({ category: 'platform-support',
branch: Joi.object({ route: {
config: Joi.object({
php: Joi.array().items(optionalNumberOrString),
matrix: Joi.object({
include: Joi.array().items(Joi.object({ php: optionalNumberOrString })),
}),
jobs: Joi.object({
include: Joi.array().items(Joi.object({ php: optionalNumberOrString })),
}),
}).required(),
}).required(),
}).required()
export default class TravisPhpVersion extends BaseJsonService {
static category = 'platform-support'
static route = {
base: 'travis/php-v', base: 'travis/php-v',
pattern: ':user/:repo/:branch+', pattern: ':params+',
} },
label: 'php',
dateAdded: new Date('2023-05-13'),
})
static examples = [ export default TravisPhpVersion
{
title: 'PHP version from Travis config',
namedParams: { user: 'yiisoft', repo: 'yii', branch: 'master' },
staticPreview: this.render({ reduction: ['5.3 - 7.4'] }),
},
]
static defaultBadgeData = {
label: 'php',
}
static render({ reduction, hasHhvm }) {
return {
message: reduction.concat(hasHhvm ? ['HHVM'] : []).join(', '),
color: 'blue',
}
}
constructor(context, config) {
super(context, config)
this._githubApiProvider = context.githubApiProvider
}
async transform({ branch: { config } }) {
let travisVersions = []
// from php
if (config.php) {
travisVersions = travisVersions.concat(config.php.map(v => v.toString()))
}
// from matrix
if (config.matrix && config.matrix.include) {
travisVersions = travisVersions.concat(
config.matrix.include.filter(v => 'php' in v).map(v => v.php.toString())
)
}
// from jobs
if (config.jobs && config.jobs.include) {
travisVersions = travisVersions.concat(
config.jobs.include.filter(v => 'php' in v).map(v => v.php.toString())
)
}
const versions = travisVersions
.map(v => minorVersion(v))
.filter(v => v.includes('.'))
return {
reduction: versionReduction(
versions,
await getPhpReleases(this._githubApiProvider)
),
hasHhvm: travisVersions.find(v => v.startsWith('hhvm')),
}
}
async handle({ user, repo, branch }) {
const travisConfig = await this._requestJson({
schema,
url: `https://api.travis-ci.org/repos/${user}/${repo}/branches/${branch}`,
errorMessages: {
404: 'repo not found',
},
})
const { reduction, hasHhvm } = await this.transform(travisConfig)
return this.constructor.render({ reduction, hasHhvm })
}
}

View File

@@ -1,19 +1,10 @@
import { isPhpVersionReduction } from '../test-validators.js' import { ServiceTester } from '../tester.js'
import { createServiceTester } from '../tester.js' export const t = new ServiceTester({
export const t = await createServiceTester() id: 'TravisPhpVersion',
title: 'TravisPhpVersion',
pathPrefix: '/travis/php-v',
})
t.create('gets the package version of symfony 5.1') t.create('travis php version, deprecated')
.get('/symfony/symfony/5.1.json') .get('/symfony/symfony/5.1.json')
.expectBadge({ label: 'php', message: isPhpVersionReduction }) .expectBadge({ label: 'php', message: 'no longer available' })
t.create('gets the package version of yii')
.get('/yiisoft/yii/master.json')
.expectBadge({ label: 'php', message: isPhpVersionReduction })
t.create('gets the package version of pagination-bundle')
.get('/gpslab/pagination-bundle/master.json')
.expectBadge({ label: 'php', message: isPhpVersionReduction })
t.create('invalid package name')
.get('/frodo/is-not-a-package/master.json')
.expectBadge({ label: 'php', message: 'repo not found' })