From 8319c4867da25739ee220128e050f0f965f6ed0b Mon Sep 17 00:00:00 2001 From: Joe Mou Date: Sat, 21 Feb 2026 19:01:55 +1100 Subject: Add latest release details By Gemini --- cgithub/src/scraper.test.ts | 2 ++ cgithub/src/scraper.ts | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'cgithub/src') diff --git a/cgithub/src/scraper.test.ts b/cgithub/src/scraper.test.ts index 0b91b6a..5bd609a 100644 --- a/cgithub/src/scraper.test.ts +++ b/cgithub/src/scraper.test.ts @@ -30,6 +30,8 @@ describe("GitHub scraper", () => { assert.strictEqual(data.info.watchers?.length, 2); assert.strictEqual(data.info.forks?.length, 3); assert.strictEqual(data.info.numReleases, 36); + assert.strictEqual(data.info.latestReleaseTag, "v4.0.5"); + assert.ok(data.info.latestReleaseDate?.startsWith("2024-03-18")); assert.ok(data.items.length > 0); assert.ok(Object.keys(data.overviewHtml ?? {}).includes("README.md")); diff --git a/cgithub/src/scraper.ts b/cgithub/src/scraper.ts index d36df5b..0ed77b5 100644 --- a/cgithub/src/scraper.ts +++ b/cgithub/src/scraper.ts @@ -157,6 +157,8 @@ export interface RepoInfo { watchers: string | null; forks: string | null; numReleases?: number; + latestReleaseTag?: string; + latestReleaseDate?: string; } export interface GitHubRepo extends GitHubTree { @@ -282,9 +284,29 @@ function parseRepoInfo(html: string): RepoInfo { document, ) as unknown as Element; let numReleases: number | undefined; + let latestReleaseTag: string | undefined; + let latestReleaseDate: string | undefined; + if (releaseElem) { const releaseText = getAttributeValue(releaseElem, "title") || textContent(releaseElem); numReleases = parseInt(releaseText.replace(/,/g, ""), 10); + + // Find the latest release tag and date if available + const cell = (releaseElem.parent as Element)?.parent?.parent as Element; // span -> a -> h2 -> cell + if (cell) { + const latestLink = cssSelect.selectOne("a[href*='/releases/tag/']", cell) as Element; + if (latestLink) { + const tagElem = cssSelect.selectOne(".css-truncate-target", latestLink); + if (tagElem) { + latestReleaseTag = textContent(tagElem).trim(); + } + + const timeElem = cssSelect.selectOne("relative-time", latestLink); + if (timeElem) { + latestReleaseDate = getAttributeValue(timeElem, "datetime") || undefined; + } + } + } } return { @@ -294,6 +316,8 @@ function parseRepoInfo(html: string): RepoInfo { watchers, forks, numReleases, + latestReleaseTag, + latestReleaseDate, }; } -- cgit v1.3.1