aboutsummaryrefslogtreecommitdiff
path: root/src/scraper.test.ts
diff options
context:
space:
mode:
authorJoe Mou <dev@mou.fo>2026-09-03 01:37:35 -0400
committerJoe Mou <dev@mou.fo>2026-09-03 22:16:44 -0400
commita52481a3884447f94aad2d97e0407112c818a32d (patch)
treeb8edcac1bf9d8bd80bf1ac78d292fe6589eee4ec /src/scraper.test.ts
parent80be2418ff2615b454c5edf2819861f58eecf271 (diff)
Link blobs to their history and back
Nothing in a commits payload says whether the path it lists is a file or a directory: currentBlobPath, despite the name, is only the path filter, and is set for a directory just the same. GitHub's own UI cannot tell either, and points its browse button at /blob/<oid>/<path> so that the redirect resolves a file to its blob. We do the same, and the blob route already turns that redirect into one of our own tree URLs. Breadcrumbs now stay in the view they were clicked from, so walking up from a history lands in the history of each parent directory rather than in its listing. The last crumb remains the page you are already on. A path with no commits now says so rather than rendering an empty page. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R7pRKdmTvNDgT4ZXrwkbH8
Diffstat (limited to 'src/scraper.test.ts')
-rw-r--r--src/scraper.test.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/scraper.test.ts b/src/scraper.test.ts
index 2690f71..f6be2b6 100644
--- a/src/scraper.test.ts
+++ b/src/scraper.test.ts
@@ -195,6 +195,39 @@ describe("GitHub scraper", () => {
assert.ok(data.commitGroups.length > 0);
});
+ // GitHub serves a file's history from the same route as a directory's.
+ it("should fetch the history of a blob", async () => {
+ const data = await getGitHubCommits("actions", "deploy-pages", "main", "src/index.js");
+
+ assert.strictEqual(data.path, "src/index.js");
+
+ assert.ok(data.commitGroups.length > 0);
+ const commit = data.commitGroups[0].commits[0];
+ assert.strictEqual(commit.oid.length, 40);
+ assert.ok(commit.shortMessage.length > 0);
+ });
+
+ // What a history page's "Browse" link resolves to: the file as it stood at
+ // one of its commits. Nothing in a commits payload says whether the path is
+ // a file or a directory, so those links all point at the tree and rely on
+ // GitHub redirecting a file's to its blob.
+ it("should redirect a blob browsed at a commit to its blob view", async () => {
+ const oid = "b39c421b98f49d83ae50ec502c3ddfc3bf28f2c6";
+
+ await assert.rejects(getGitHubTree("actions", "deploy-pages", oid, "src/index.js"), (err) => {
+ assert(err instanceof RedirectError, "error should be a RedirectError");
+ assert.strictEqual(err.location, `/actions/deploy-pages/blob/${oid}/src/index.js`);
+ return true;
+ });
+
+ const data = await getGitHubBlob("actions", "deploy-pages", oid, "src/index.js");
+
+ assert.strictEqual(data.branch, oid);
+ assert.strictEqual(data.path, "src/index.js");
+ assert.strictEqual(data.size, "1.37 KB / 51 lines / 40 loc");
+ assert.strictEqual(data.textLines?.length, 51);
+ });
+
it("should fetch releases", async () => {
const data = await getGitHubReleases("actions", "deploy-pages");