mirror of
https://github.com/ivabus/pantry
synced 2024-11-22 08:25:07 +03:00
add labels like “node”, “python” etc.
This commit is contained in:
parent
0d356a783a
commit
0719b3e8e4
2 changed files with 53 additions and 7 deletions
3
.github/deno.jsonc
vendored
3
.github/deno.jsonc
vendored
|
@ -9,6 +9,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"imports": {
|
"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/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
57
.github/scripts/utils/indexer.ts
vendored
57
.github/scripts/utils/indexer.ts
vendored
|
@ -5,16 +5,17 @@ interface Package {
|
||||||
birthtime: Date,
|
birthtime: Date,
|
||||||
name?: string
|
name?: string
|
||||||
description?: string
|
description?: string
|
||||||
|
labels?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getKettleRemoteMetadata(): Promise<Record<string, string>> {
|
export async function getKettleRemoteMetadata() {
|
||||||
const headers = { Authorization: 'public' }
|
const headers = { Authorization: 'public' }
|
||||||
const rsp = await fetch(`https://app.pkgx.dev/v1/packages/`, {headers})
|
const rsp = await fetch(`https://app.pkgx.dev/v1/packages/`, {headers})
|
||||||
const foo = await rsp.json() as {project: string, short_description: string}[]
|
const foo = await rsp.json() as {project: string, short_description: string}[]
|
||||||
return foo.reduce((acc, {project, short_description}) => {
|
return foo.reduce((acc, {project, short_description}) => {
|
||||||
acc[project] = short_description
|
acc[project] = short_description
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {} as Record<string, string>)
|
||||||
}
|
}
|
||||||
|
|
||||||
const descriptions = await getKettleRemoteMetadata();
|
const descriptions = await getKettleRemoteMetadata();
|
||||||
|
@ -48,9 +49,14 @@ async function getPackageYmlCreationDates(): Promise<Package[]> {
|
||||||
|
|
||||||
const birthtime = new Date(currentCommitDate!)
|
const birthtime = new Date(currentCommitDate!)
|
||||||
const name = await get_name(line, project)
|
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 { 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 { 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<string | undefined> {
|
async function get_name(path: string, project: string): Promise<string | undefined> {
|
||||||
const txt = await Deno.readTextFileSync(path)
|
const txt = await Deno.readTextFileSync(path)
|
||||||
|
@ -75,7 +82,45 @@ async function get_name(path: string, project: string): Promise<string | undefin
|
||||||
return yml['display-name']
|
return yml['display-name']
|
||||||
} else if (isArray(yml.provides) && yml.provides.length == 1) {
|
} else if (isArray(yml.provides) && yml.provides.length == 1) {
|
||||||
return yml.provides[0].slice(4)
|
return yml.provides[0].slice(4)
|
||||||
} else if (project.startsWith("github.com")) {
|
} else {
|
||||||
return project.slice(11)
|
return get_pkg_name(project)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import { parse_pkgs_node } from "pkgx/hooks/usePantry.ts"
|
||||||
|
|
||||||
|
async function get_labels(path: string) {
|
||||||
|
const txt = await Deno.readTextFileSync(path)
|
||||||
|
const yml = await parse(txt) as Record<string, any>
|
||||||
|
const deps = parse_pkgs_node(yml.dependencies) //NOTE will ignore other platforms than linux, but should be fine
|
||||||
|
|
||||||
|
const labels = new Set<string>(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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue