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

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

Merged
merged 5 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions services/osslifecycle/osslifecycle-redirector.service.js
Original file line number Diff line number Diff line change
@@ -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,
}),
]
26 changes: 26 additions & 0 deletions services/osslifecycle/osslifecycle-redirector.tester.js
Original file line number Diff line number Diff line change
@@ -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',
})}`,
)
66 changes: 25 additions & 41 deletions services/osslifecycle/osslifecycle.service.js
Original file line number Diff line number Diff line change
@@ -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).
`
chris48s marked this conversation as resolved.
Show resolved Hide resolved

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',
}),
],
},
},
}
Expand Down Expand Up @@ -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]
Expand Down
53 changes: 32 additions & 21 deletions services/osslifecycle/osslifecycle.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,50 @@ 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',
color: 'yellow',
})

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')
Expand All @@ -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',
})
Loading