[OSSLifecycle OSSLifecycleRedirect] Add file_url param to pull from non-github sources (#10489)

* add file_url param

Add file_url param to allow pulling from non-github sources

* add test for file_url param

Add test using file_url variant of OSS Lifecycle badge using Netflix OSSTracker repo

* remove old pattern from main service

Remove all references and code for the old /{user}/{repo} and /{user}/{repo}/{branch} functionality.
This will be replaced by a redirect service.

Also updated all tests to use the new file_url method

* add osslifecycle redirector

add a redirector for the original osslifecycle pattern

* tweaks to docs and handle function

Tweak the Description to remove reference to GitHub as now works with any repository,
and updated handle function to remove reference to unused variables.
This commit is contained in:
Joe Izzard
2024-09-05 17:06:15 +01:00
committed by GitHub
parent f776f817bd
commit 9717fc202f
4 changed files with 103 additions and 62 deletions

View File

@@ -0,0 +1,20 @@
import { redirector } from '../index.js'
const commonProps = {
category: 'other',
dateAdded: new Date('2024-09-02'),
}
export default [
redirector({
route: {
base: 'osslifecycle',
pattern: ':user/:repo/:branch*',
},
transformPath: () => '/osslifecycle',
transformQueryParams: ({ user, repo, branch }) => ({
file_url: `https://raw.githubusercontent.com/${user}/${repo}/${branch || 'HEAD'}/OSSMETADATA`,
}),
...commonProps,
}),
]

View File

@@ -0,0 +1,26 @@
import queryString from 'querystring'
import { ServiceTester } from '../tester.js'
export const t = new ServiceTester({
id: 'osslifecycleRedirect',
title: 'OSSLifecycleRedirect',
pathPrefix: '/osslifecycle',
})
t.create('oss lifecycle redirect')
.get('/netflix/osstracker.svg')
.expectRedirect(
`/osslifecycle.svg?${queryString.stringify({
file_url:
'https://raw.githubusercontent.com/netflix/osstracker/HEAD/OSSMETADATA',
})}`,
)
t.create('oss lifecycle redirect (branch)')
.get('/netflix/osstracker/documentation.svg')
.expectRedirect(
`/osslifecycle.svg?${queryString.stringify({
file_url:
'https://raw.githubusercontent.com/netflix/osstracker/documentation/OSSMETADATA',
})}`,
)

View File

@@ -1,57 +1,43 @@
import { BaseService, InvalidResponse, pathParams } from '../index.js'
import Joi from 'joi'
import { optionalUrl } from '../validators.js'
import { BaseService, InvalidResponse, queryParam } from '../index.js'
const description = `
OSS Lifecycle is an initiative started by Netflix to classify open-source projects into lifecycles
and clearly identify which projects are active and which ones are retired. To enable this badge,
simply create an OSSMETADATA tagging file at the root of your GitHub repository containing a
simply create an OSSMETADATA tagging file at the root of your repository containing a
single line similar to the following: \`osslifecycle=active\`. Other suggested values are
\`osslifecycle=maintenance\` and \`osslifecycle=archived\`. A working example
can be viewed on the [OSS Tracker repository](https://github.com/Netflix/osstracker).
`
const queryParamSchema = Joi.object({
file_url: optionalUrl.required(),
}).required()
export default class OssTracker extends BaseService {
static category = 'other'
static route = {
base: 'osslifecycle',
pattern: ':user/:repo/:branch*',
base: '',
pattern: 'osslifecycle',
queryParamSchema,
}
static openApi = {
'/osslifecycle/{user}/{repo}': {
'/osslifecycle': {
get: {
summary: 'OSS Lifecycle',
description,
parameters: pathParams(
{
name: 'user',
example: 'Teevity',
},
{
name: 'repo',
example: 'ice',
},
),
},
},
'/osslifecycle/{user}/{repo}/{branch}': {
get: {
summary: 'OSS Lifecycle (branch)',
description,
parameters: pathParams(
{
name: 'user',
example: 'Netflix',
},
{
name: 'repo',
example: 'osstracker',
},
{
name: 'branch',
example: 'documentation',
},
),
parameters: [
queryParam({
name: 'file_url',
example:
'https://raw.githubusercontent.com/Netflix/aws-autoscaling/master/OSSMETADATA',
required: true,
description: 'URL for the `OSSMETADATA` file',
}),
],
},
},
}
@@ -87,17 +73,15 @@ export default class OssTracker extends BaseService {
}
}
async fetch({ user, repo, branch }) {
async fetch({ fileUrl }) {
return this._request({
url: `https://raw.githubusercontent.com/${user}/${repo}/${branch}/OSSMETADATA`,
url: fileUrl,
})
}
async handle({ user, repo, branch }) {
async handle(pathParams, { file_url: fileUrl = '' }) {
const { buffer } = await this.fetch({
user,
repo,
branch: branch || 'HEAD',
fileUrl,
})
try {
const status = buffer.match(/osslifecycle=([a-z]+)/im)[1]

View File

@@ -5,14 +5,20 @@ export const t = new ServiceTester({
title: 'OSS Lifecycle',
})
t.create('osslifecycle active status').get('/netflix/sureal.json').expectBadge({
label: 'oss lifecycle',
message: 'active',
color: 'brightgreen',
})
t.create('osslifecycle active status')
.get(
'.json?file_url=https://raw.githubusercontent.com/Netflix/sureal/HEAD/OSSMETADATA',
)
.expectBadge({
label: 'oss lifecycle',
message: 'active',
color: 'brightgreen',
})
t.create('osslifecycle maintenance status')
.get('/Teevity/ice.json')
.get(
'.json?file_url=https://raw.githubusercontent.com/Teevity/ice/HEAD/OSSMETADATA',
)
.expectBadge({
label: 'oss lifecycle',
message: 'maintenance',
@@ -20,28 +26,29 @@ t.create('osslifecycle maintenance status')
})
t.create('osslifecycle archived status')
.get('/Netflix/rx-aws-java-sdk.json')
.get(
'.json?file_url=https://raw.githubusercontent.com/Netflix/rx-aws-java-sdk/HEAD/OSSMETADATA',
)
.expectBadge({
label: 'oss lifecycle',
message: 'archived',
color: 'red',
})
t.create('osslifecycle other status').get('/Netflix/metacat.json').expectBadge({
label: 'oss lifecycle',
message: 'private',
color: 'lightgrey',
})
t.create('osslifecycle status (branch)')
.get('/Netflix/osstracker/documentation.json')
t.create('osslifecycle other status')
.get(
'.json?file_url=https://raw.githubusercontent.com/Netflix/metacat/HEAD/OSSMETADATA',
)
.expectBadge({
label: 'oss lifecycle',
message: 'active',
message: 'private',
color: 'lightgrey',
})
t.create('oss metadata in unexpected format')
.get('/some-user/some-project.json')
.get(
'.json?file_url=https://raw.githubusercontent.com/some-user/some-project/HEAD/OSSMETADATA',
)
.intercept(
nock =>
nock('https://raw.githubusercontent.com')
@@ -56,7 +63,11 @@ t.create('oss metadata in unexpected format')
message: 'metadata in unexpected format',
})
t.create('oss metadata not found').get('/PyvesB/empty-repo.json').expectBadge({
label: 'oss lifecycle',
message: 'not found',
})
t.create('oss metadata not found')
.get(
'.json?file_url=https://raw.githubusercontent.com/PyvesB/empty-repo/HEAD/OSSMETADATA',
)
.expectBadge({
label: 'oss lifecycle',
message: 'not found',
})