diff --git a/README.md b/README.md index 33119f7..2372865 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@

- Repos listed on DevStream + Repos listed on DevStream PR checks License: CC0 - GitHub Discussions - Website - OpenSSF Scorecard + GitHub Discussions + Website + OpenSSF Scorecard

Awesome lists rot. That link someone merged in 2019 is still sitting there, long after the repo's last commit, and the star count beside it only tells you who got excited once. DevStream checks a repo before it lands and again every week. Then it ranks what survives by Likes, one per account. diff --git a/site/src/lib/embeds.ts b/site/src/lib/embeds.ts index b1a91c5..2121fb9 100644 --- a/site/src/lib/embeds.ts +++ b/site/src/lib/embeds.ts @@ -12,7 +12,7 @@ const W = 720; const ROW = 44; const TOP = 76; -const esc = (v: unknown) => +export const esc = (v: unknown) => String(v) .replace(/&/g, "&") .replace(/ ({ message: `${live.length} ${live.length === 1 ? "repo" : "repos"}`, color: BRAND_HEX, }); + +// shortcut: widths are estimated at 6.6px a character, not measured; fine for short ASCII labels. +export function flatBadge(label: string, message: string, color: string): string { + const lw = Math.round(label.length * 6.6 + 10); + const rw = Math.round(message.length * 6.6 + 10); + const w = lw + rw; + const t = (x: number, s: string) => + `${esc(s)}`; + return ( + `` + + `${esc(label)}: ${esc(message)}` + + `` + + `` + + `${t(lw / 2, label)}${t(lw + rw / 2, message)}` + ); +} diff --git a/site/src/pages/badge.svg.ts b/site/src/pages/badge.svg.ts new file mode 100644 index 0000000..f9b3e48 --- /dev/null +++ b/site/src/pages/badge.svg.ts @@ -0,0 +1,9 @@ +import { loadAll, liveList } from "../lib/data.ts"; +import { badge, flatBadge } from "../lib/embeds.ts"; + +export function GET() { + const b = badge(liveList(loadAll().entries)); + return new Response(flatBadge(b.label, b.message, b.color), { + headers: { "Content-Type": "image/svg+xml; charset=utf-8" }, + }); +} diff --git a/site/src/pages/scorecard.svg.ts b/site/src/pages/scorecard.svg.ts new file mode 100644 index 0000000..af1954b --- /dev/null +++ b/site/src/pages/scorecard.svg.ts @@ -0,0 +1,21 @@ +import { flatBadge } from "../lib/embeds.ts"; + +const URL_ = "https://api.scorecard.dev/projects/github.com/devstreamhq/devstream"; + +export async function GET() { + let msg = "pending"; + let color = "#9f9f9f"; + try { + const res = await fetch(URL_, { signal: AbortSignal.timeout(10_000) }); + const score = (await res.json())?.score; + if (res.ok && typeof score === "number" && Number.isFinite(score)) { + msg = score.toFixed(1); + color = score >= 7 ? "#4c1" : score >= 4 ? "#dfb317" : "#e05d44"; + } + } catch { + // Never fail the build over a badge. + } + return new Response(flatBadge("openssf scorecard", msg, color), { + headers: { "Content-Type": "image/svg+xml; charset=utf-8" }, + }); +} diff --git a/site/tests/badges.test.mjs b/site/tests/badges.test.mjs new file mode 100644 index 0000000..37ba1e0 --- /dev/null +++ b/site/tests/badges.test.mjs @@ -0,0 +1,58 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { flatBadge } from "../src/lib/embeds.ts"; +import { GET as listed } from "../src/pages/badge.svg.ts"; +import { GET as scorecard } from "../src/pages/scorecard.svg.ts"; + +const realFetch = globalThis.fetch; +const mock = (fn) => (globalThis.fetch = fn); +const json = (body, ok = true) => async () => ({ ok, json: async () => body }); +const text = async (r) => r.text(); +const checks = (svg) => { + assert.ok(!/