Repository navigation
feat: oss index groups endpoint #2350
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| // Copyright (c) 2025 The Linux Foundation and each contributor. | ||
| // SPDX-License-Identifier: MIT | ||
| import { Type, type Static } from '@sinclair/typebox'; | ||
|
|
||
| import { nullableNumber } from '../schemas/common.js'; | ||
| import { HealthLabel, isHealthScore } from './overview.js'; | ||
| import { dataEnum, inRange, isCount, isString } from './security.js'; | ||
|
|
||
| // The pipes return positional tuples, so each slot is type-checked before the route names it. Project | ||
| // tuples keep the v1 health score, which the API drops, and end in the nullable v2 health fields. | ||
| export type TopCollectionTuple = [ | ||
| id: string, | ||
| count: number, | ||
| name: string, | ||
| softwareValue: number, | ||
| avgScore: number, | ||
| ]; | ||
|
|
||
| export type TopProjectTuple = [ | ||
| id: string, | ||
| count: number, | ||
| name: string, | ||
| logo: string, | ||
| softwareValue: number, | ||
| avgScore: number, | ||
| v1HealthScore: number, | ||
| description: string, | ||
| status: string, | ||
| healthScore: number | null, | ||
| healthLabel: string | null, | ||
| scaledHealthScore: number | null, | ||
| healthMaxScore: number | null, | ||
| ]; | ||
|
|
||
| // Counts and the UInt64 software value must be non-negative safe integers. The 0-1 averages use | ||
| // inRange; the dropped v1 score only needs a finite number. | ||
| const isNumber = (value: unknown) => typeof value === 'number' && Number.isFinite(value); | ||
| const isNullableNumber = (value: unknown) => value === null || isNumber(value); | ||
|
|
||
| export const isTopCollectionTuple = (value: unknown): value is TopCollectionTuple => | ||
| Array.isArray(value) && | ||
| value.length === 5 && | ||
| isString(value[0]) && | ||
| isCount(value[1]) && | ||
| isString(value[2]) && | ||
| isCount(value[3]) && | ||
| inRange(value[4], 1); | ||
|
|
||
| export const isTopProjectTuple = (value: unknown): value is TopProjectTuple => | ||
| Array.isArray(value) && | ||
| value.length >= 13 && | ||
| isString(value[0]) && | ||
| isCount(value[1]) && | ||
| isString(value[2]) && | ||
| isString(value[3]) && | ||
| isCount(value[4]) && | ||
| inRange(value[5], 1) && | ||
| isNumber(value[6]) && | ||
| isString(value[7]) && | ||
| isString(value[8]) && | ||
| isHealthScore(value[9], value[10], value[12]) && | ||
| isNullableNumber(value[11]); | ||
|
|
||
| export const TopCollection = Type.Object( | ||
| { | ||
| id: Type.String({ description: 'Identifier of the collection.' }), | ||
| count: Type.Integer({ minimum: 0, description: 'Contributors in the collection.' }), | ||
| name: Type.String({ description: 'Display name of the collection.' }), | ||
| softwareValue: Type.Integer({ minimum: 0, description: 'Software value of the collection.' }), | ||
| avgScore: Type.Number({ | ||
| minimum: 0, | ||
| maximum: 1, | ||
| description: 'Average health score of the collection, from 0 to 1.', | ||
| }), | ||
| }, | ||
| { title: 'TopCollection' }, | ||
| ); | ||
| export type TopCollection = Static<typeof TopCollection>; | ||
|
|
||
| export const TopProject = Type.Object( | ||
| { | ||
| id: Type.String({ description: 'Identifier of the project.' }), | ||
| count: Type.Integer({ minimum: 0, description: 'Contributors to the project.' }), | ||
| name: Type.String({ description: 'Display name of the project.' }), | ||
| logoUrl: Type.String({ description: 'URL of the project logo.' }), | ||
| description: Type.String({ description: 'Short description of the project.' }), | ||
| softwareValue: Type.Integer({ minimum: 0, description: 'Software value of the project.' }), | ||
| avgScore: Type.Number({ | ||
| minimum: 0, | ||
| maximum: 1, | ||
| description: 'Average score of the project, from 0 to 1.', | ||
| }), | ||
| healthScore: nullableNumber( | ||
| 'Health score, the sum of the three category scores, from 0 to `healthMaxScore`. Null when fewer than two categories have data.', | ||
| ), | ||
| healthLabel: HealthLabel, | ||
| healthMaxScore: nullableNumber( | ||
| 'Highest score the covered categories allow: 60, 65, 75 or 100. Null when unknown.', | ||
| ), | ||
| status: Type.String({ description: 'Lifecycle status of the project, for example `active`.' }), | ||
| }, | ||
| { title: 'TopProject' }, | ||
| ); | ||
| export type TopProject = Static<typeof TopProject>; | ||
|
|
||
| export const toTopCollection = ([ | ||
| id, | ||
| count, | ||
| name, | ||
| softwareValue, | ||
| avgScore, | ||
| ]: TopCollectionTuple): TopCollection => ({ id, count, name, softwareValue, avgScore }); | ||
|
|
||
| export const toTopProject = ([ | ||
| id, | ||
| count, | ||
| name, | ||
| logo, | ||
| softwareValue, | ||
| avgScore, | ||
| , | ||
| description, | ||
| status, | ||
| healthScore, | ||
| healthLabel, | ||
| , | ||
| healthMaxScore, | ||
| ]: TopProjectTuple): TopProject => ({ | ||
| id, | ||
| count, | ||
| name, | ||
| logoUrl: logo, | ||
| description, | ||
| softwareValue, | ||
| avgScore, | ||
| healthScore, | ||
| healthLabel: healthLabel as TopProject['healthLabel'], | ||
| healthMaxScore, | ||
| status, | ||
| }); | ||
|
|
||
| export const sortValues = ['totalContributors', 'softwareValue'] as const; | ||
|
|
||
| export const sortQuery = Type.Object({ | ||
| sort: Type.Optional( | ||
| dataEnum( | ||
| sortValues, | ||
| 'Orders the results, highest first. Defaults to `totalContributors`; `softwareValue` orders by software value.', | ||
| ), | ||
| ), | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Copyright (c) 2025 The Linux Foundation and each contributor. | ||
| // SPDX-License-Identifier: MIT | ||
| import type { FastifyPluginAsyncTypebox } from '@fastify/type-provider-typebox'; | ||
| import { Type } from '@sinclair/typebox'; | ||
|
|
||
| import { fetchPipe } from '../../../clients/tinybird.js'; | ||
| import { | ||
| isTopCollectionTuple, | ||
| isTopProjectTuple, | ||
| sortQuery, | ||
| TopCollection, | ||
| toTopCollection, | ||
| TopProject, | ||
| toTopProject, | ||
| type TopCollectionTuple, | ||
| type TopProjectTuple, | ||
| } from '../../../lib/oss-index.js'; | ||
| import { inRange, isCount, isString } from '../../../lib/security.js'; | ||
|
|
||
| const pipePath = '/v0/pipes/category_groups_oss_index.json'; | ||
|
|
||
| interface Row { | ||
| id: string; | ||
| name: string; | ||
| type: string; | ||
| slug: string; | ||
| totalContributors: number; | ||
| softwareValue: number; | ||
| avgScore: number; | ||
| projectCount: number; | ||
| topCollections: TopCollectionTuple[]; | ||
| topProjects: TopProjectTuple[]; | ||
| } | ||
|
|
||
| const isRow = (row: Row) => | ||
| isString(row.id) && | ||
| isString(row.name) && | ||
| isString(row.type) && | ||
| isString(row.slug) && | ||
| isCount(row.totalContributors) && | ||
| isCount(row.softwareValue) && | ||
| inRange(row.avgScore, 1) && | ||
| isCount(row.projectCount) && | ||
|
epipav marked this conversation as resolved.
|
||
| Array.isArray(row.topCollections) && | ||
| row.topCollections.every(isTopCollectionTuple) && | ||
| Array.isArray(row.topProjects) && | ||
| row.topProjects.every(isTopProjectTuple); | ||
|
|
||
| const Query = Type.Object({ | ||
| type: Type.Optional( | ||
| Type.String({ | ||
| description: 'Keeps the groups of this type, for example `vertical` or `horizontal`.', | ||
| }), | ||
| ), | ||
| ...sortQuery.properties, | ||
| }); | ||
|
|
||
| const OssIndexGroup = Type.Object( | ||
| { | ||
| id: Type.String({ description: 'Identifier of the category group.' }), | ||
| name: Type.String({ description: 'Display name of the category group.' }), | ||
| type: Type.String({ | ||
| description: 'Type of the group, for example `vertical` or `horizontal`.', | ||
| }), | ||
| slug: Type.String({ description: 'URL slug of the category group.' }), | ||
| totalContributors: Type.Integer({ minimum: 0, description: 'Contributors across the group.' }), | ||
| softwareValue: Type.Integer({ minimum: 0, description: 'Software value of the group.' }), | ||
| avgScore: Type.Number({ | ||
| minimum: 0, | ||
| maximum: 1, | ||
| description: 'Average health score of the group, from 0 to 1.', | ||
| }), | ||
| projectCount: Type.Integer({ minimum: 0, description: 'Projects in the group.' }), | ||
| topCollections: Type.Array(TopCollection, { | ||
| description: 'Leading collections of the group, ordered by contributors.', | ||
| }), | ||
| topProjects: Type.Array(TopProject, { | ||
| description: 'Leading projects of the group, ordered by contributors.', | ||
| }), | ||
| }, | ||
| { title: 'OssIndexGroup' }, | ||
| ); | ||
|
|
||
| const Groups = Type.Object({ | ||
| data: Type.Array(OssIndexGroup, { | ||
| description: 'Category groups in the requested order. Empty when none match `type`.', | ||
| }), | ||
| }); | ||
|
|
||
| const groupRoutes: FastifyPluginAsyncTypebox = async (scope) => { | ||
| scope.get( | ||
| '/oss-index/groups', | ||
| { | ||
| schema: { | ||
| tags: ['OSS Index'], | ||
| summary: 'List the OSS Index category groups', | ||
| description: | ||
| 'Returns every category group with its totals and its leading collections and projects. ' + | ||
| '`type` keeps one group type, and `sort` orders the groups by contributors or by software value.', | ||
| querystring: Query, | ||
| response: { 200: Groups }, | ||
| }, | ||
| }, | ||
| async (request) => { | ||
| const { type, sort } = request.query; | ||
| const rows = await fetchPipe<Row>( | ||
| request, | ||
| pipePath, | ||
| { type: type || undefined, orderBy: sort ?? 'totalContributors' }, | ||
| isRow, | ||
| ); | ||
| return { | ||
| data: rows.map((row) => ({ | ||
| ...row, | ||
| topCollections: row.topCollections.map(toTopCollection), | ||
| topProjects: row.topProjects.map(toTopProject), | ||
| })), | ||
| }; | ||
| }, | ||
| ); | ||
| }; | ||
|
|
||
| export default groupRoutes; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.