From 0719b3e8e4f4f8add33f434ff05883b631ab5a47 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Tue, 31 Oct 2023 11:45:14 -0400 Subject: [PATCH] =?UTF-8?q?add=20labels=20like=20=E2=80=9Cnode=E2=80=9D,?= =?UTF-8?q?=20=E2=80=9Cpython=E2=80=9D=20etc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/deno.jsonc | 3 +- .github/scripts/utils/indexer.ts | 57 ++++++++++++++++++++++++++++---- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/.github/deno.jsonc b/.github/deno.jsonc index 20758006..2b6ddf6a 100644 --- a/.github/deno.jsonc +++ b/.github/deno.jsonc @@ -9,6 +9,7 @@ } }, "imports": { - "pkgx": "https://deno.land/x/libpkgx@v0.14.1/mod.ts" + "pkgx": "https://deno.land/x/libpkgx@v0.15.1/mod.ts", + "pkgx/": "https://deno.land/x/libpkgx@v0.15.1/src/" } } diff --git a/.github/scripts/utils/indexer.ts b/.github/scripts/utils/indexer.ts index 5fae5a58..19864868 100644 --- a/.github/scripts/utils/indexer.ts +++ b/.github/scripts/utils/indexer.ts @@ -5,16 +5,17 @@ interface Package { birthtime: Date, name?: string description?: string + labels?: string[] } -export async function getKettleRemoteMetadata(): Promise> { +export async function getKettleRemoteMetadata() { const headers = { Authorization: 'public' } const rsp = await fetch(`https://app.pkgx.dev/v1/packages/`, {headers}) const foo = await rsp.json() as {project: string, short_description: string}[] return foo.reduce((acc, {project, short_description}) => { acc[project] = short_description return acc - }, {}) + }, {} as Record) } const descriptions = await getKettleRemoteMetadata(); @@ -48,9 +49,14 @@ async function getPackageYmlCreationDates(): Promise { const birthtime = new Date(currentCommitDate!) const name = await get_name(line, project) - const description = descriptions[project] - rv.push({ project, birthtime, name, description }) + let description: string | undefined = descriptions[project]?.trim() + if (!description) description = undefined + + let labels: string[] | undefined = [...await get_labels(line)] + if (labels.length == 0) labels = undefined + + rv.push({ project, birthtime, name, description, labels }) } } @@ -67,6 +73,7 @@ console.log(JSON.stringify(pkgs, null, 2)); ////////////////////////////////////////////////////// import { parse } from "https://deno.land/std@0.204.0/yaml/mod.ts"; import { isArray } from "https://deno.land/x/is_what@v4.1.15/src/index.ts"; +import get_pkg_name from "https://raw.githubusercontent.com/pkgxdev/www/main/src/utils/pkg-name.ts"; async function get_name(path: string, project: string): Promise { const txt = await Deno.readTextFileSync(path) @@ -75,7 +82,45 @@ async function get_name(path: string, project: string): Promise + const deps = parse_pkgs_node(yml.dependencies) //NOTE will ignore other platforms than linux, but should be fine + + const labels = new Set(deps.compact(({ project }) => { + switch (project) { + case 'nodejs.org': + case 'npmjs.com': + return 'node' + case 'python.org': + case 'pip.pypa.io': + return 'python' + case 'ruby-lang.org': + case 'rubygems.org': + return 'ruby' + case 'rust-lang.org': + case 'rust-lang.org/cargo': + return 'rust' + } + })) + + for (const dep of parse_pkgs_node(yml.build.dependencies)) { + switch (dep.project) { + case 'rust-lang.org': + case 'rust-lang.org/cargo': + labels.add('rust') + break + case 'go.dev': + labels.add('go') + } + } + + return labels +}