1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
import assert from "node:assert";
import { describe, it } from "node:test";
import {
getGitHubBlob,
getGitHubIssues,
getGitHubRepo,
getGitHubTree,
GitHubHTTPError,
} from "./scraper.ts";
describe("GitHub scraper", () => {
describe("actions/deploy-pages repository", () => {
it("should fetch repository", async () => {
const data = await getGitHubRepo("actions", "deploy-pages");
assert.strictEqual(data.repo.owner, "actions");
assert.strictEqual(data.repo.name, "deploy-pages");
assert.strictEqual(data.branch, "main");
assert.strictEqual(data.path, "/");
assert.strictEqual(
data.info.description,
"GitHub Action to publish artifacts to GitHub Pages for deployments",
);
assert.strictEqual(data.info.website, "https://pages.github.com");
assert.strictEqual(data.info.stars?.length, 3);
assert.strictEqual(data.info.watchers?.length, 2);
assert.strictEqual(data.info.forks?.length, 3);
assert.strictEqual(data.info.numReleases, 36);
assert.ok(data.items.length > 0);
assert.ok(Object.keys(data.overviewHtml ?? {}).includes("README.md"));
});
it("should fetch tree", async () => {
const data = await getGitHubTree("actions", "deploy-pages", "main", "src");
assert.strictEqual(data.repo.owner, "actions");
assert.strictEqual(data.repo.name, "deploy-pages");
assert.strictEqual(data.branch, "main");
assert.strictEqual(data.path, "src");
assert.deepStrictEqual(data.items, [
{
name: "__tests__",
path: "src/__tests__",
contentType: "directory",
},
{
name: "internal",
path: "src/internal",
contentType: "directory",
},
{
name: "index.js",
path: "src/index.js",
contentType: "file",
},
]);
});
it("should fetch blob", async () => {
const data = await getGitHubBlob("actions", "deploy-pages", "main", "LICENSE");
assert.strictEqual(data.repo.owner, "actions");
assert.strictEqual(data.repo.name, "deploy-pages");
assert.strictEqual(data.branch, "main");
assert.strictEqual(data.path, "LICENSE");
assert.strictEqual(data.size, 1068);
assert.strictEqual(data.language, "Text");
assert.match(data.rawContent, /^MIT License\n\n/);
assert.match(data.content, /^MIT License\n\n/);
});
it("should fetch issues", async () => {
const data = await getGitHubIssues("actions", "deploy-pages");
assert.strictEqual(data.repo.owner, "actions");
assert.strictEqual(data.repo.name, "deploy-pages");
const issue402 = data.issues.find((issue) => issue.number === 402);
assert.ok(issue402);
assert.strictEqual(issue402.title, "Dry Run");
assert.strictEqual(issue402.state, "OPEN");
assert.strictEqual(issue402.createdAt, "2025-07-03T19:07:08Z");
});
});
describe("error handling", () => {
it("should throw for non-existent repository", async () => {
await assert.rejects(getGitHubRepo("nosuchowner", "nosuchrepo"), (err) => {
assert(err instanceof GitHubHTTPError, "error should be an HTTPError");
assert.strictEqual(err.status, 404);
return true;
});
});
});
});
|