summaryrefslogtreecommitdiff
path: root/cgithub/src/scraper.ts
diff options
context:
space:
mode:
authorJoe Mou <dev@mou.fo>2026-01-28 22:41:00 -0500
committerJoe Mou <dev@mou.fo>2026-01-28 23:03:09 -0500
commit94fcda59a064b5e8952d1bccb6b9a153c39acda1 (patch)
tree849ac2b7f33f62f774d145856eaee5267e3593ae /cgithub/src/scraper.ts
parent631bc70d94cd12d0432cca1a220a3642eea6976a (diff)
Commits list
Diffstat (limited to 'cgithub/src/scraper.ts')
-rw-r--r--cgithub/src/scraper.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/cgithub/src/scraper.ts b/cgithub/src/scraper.ts
index e58402a..71d0e3e 100644
--- a/cgithub/src/scraper.ts
+++ b/cgithub/src/scraper.ts
@@ -54,6 +54,26 @@ interface IssueIndexPageQuery {
type StylingDirective = [number, number, string];
+interface Commit {
+ oid: string;
+ url: string;
+ authoredDate: string;
+ committedDate: string;
+ shortMessage: string;
+ bodyMessageHtml: string;
+ authors: {
+ login: string;
+ displayName: string;
+ avatarUrl: string;
+ path: string;
+ }[];
+}
+
+export interface CommitGroup {
+ title: string;
+ commits: Commit[];
+}
+
interface RawPayload {
repo: {
ownerLogin: string;
@@ -82,6 +102,7 @@ interface RawPayload {
overview?: {
overviewFiles?: OverviewFile[];
};
+ commitGroups?: CommitGroup[];
// Actually there may be other query types.
preloadedQueries?: IssueIndexPageQuery[];
}
@@ -159,6 +180,10 @@ export interface GitHubIssues extends GitHubCommon {
issues: Issue[];
}
+export interface GitHubCommits extends GitHubNav {
+ commitGroups: CommitGroup[];
+}
+
async function fetchGitHubPage(path: string): Promise<string> {
// GitHub throttles/blocks requests without realistic browser headers.
// These headers make the request appear as a standard browser visit.
@@ -350,3 +375,31 @@ export async function getGitHubIssues(owner: string, repo: string): Promise<GitH
issues,
};
}
+
+export async function getGitHubCommits(
+ owner: string,
+ repo: string,
+ branch: string,
+ path: string,
+): Promise<GitHubCommits> {
+ const urlPath = path
+ ? `${owner}/${repo}/commits/${branch}/${path}`
+ : `${owner}/${repo}/commits/${branch}`;
+ const html = await fetchGitHubPage(urlPath);
+
+ const payload = parsePayload(html, "react-app.embeddedData", ["payload"]);
+
+ if (payload?.commitGroups === undefined) {
+ throw new Error("Could not find commit history in embedded JSON");
+ }
+
+ return {
+ repo: {
+ owner,
+ name: repo,
+ },
+ branch,
+ path,
+ commitGroups: payload.commitGroups,
+ };
+}