Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

feat: add GitHub-to-GraphPatch transformer (issues→intent, PRs→decision, commits→doc)

riley0227f7034a6e5daf
diff --git a/ix-cli/src/cli/__tests__/github-transform.test.ts b/ix-cli/src/cli/__tests__/github-transform.test.ts
new file mode 100644
index 00000000..232bb36f
--- /dev/null
+++ b/ix-cli/src/cli/__tests__/github-transform.test.ts
@@ -0,0 +1,66 @@
+import { describe, it, expect } from "vitest";
+
+describe("GitHub transform", () => {
+ it("creates deterministic node IDs from URIs", async () => {
+ const { deterministicId } = await import("../github/transform.js");
+ const id1 = deterministicId("github://owner/repo/issues/1");
+ const id2 = deterministicId("github://owner/repo/issues/1");
+ const id3 = deterministicId("github://owner/repo/issues/2");
+ expect(id1).toBe(id2);
+ expect(id1).not.toBe(id3);
+ expect(id1).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
+ });
+
+ it("transforms an issue into UpsertNode ops", async () => {
+ const { transformIssue } = await import("../github/transform.js");
+ const ops = transformIssue(
+ { owner: "acme", repo: "app" },
+ {
+ number: 42, title: "Fix login bug", body: "Login fails on mobile",
+ state: "open", user: { login: "alice" }, labels: [{ name: "bug" }],
+ created_at: "2026-01-01T00:00:00Z", updated_at: "2026-01-02T00:00:00Z",
+ html_url: "https://github.com/acme/app/issues/42", comments: 0,
+ }
+ );
+ expect(ops.length).toBeGreaterThanOrEqual(1);
+ const upsert = ops.find((op: any) => op.type === "UpsertNode");
+ expect(upsert).toBeDefined();
+ expect(upsert!.kind).toBe("intent");
+ expect(upsert!.name).toBe("Fix login bug");
+ });
+
+ it("transforms a PR into UpsertNode ops with decision kind", async () => {
+ const { transformPR } = await import("../github/transform.js");
+ const ops = transformPR(
+ { owner: "acme", repo: "app" },
+ {
+ number: 10, title: "Add auth flow", body: "Implements OAuth",
+ state: "closed", merged_at: "2026-01-05T00:00:00Z",
+ user: { login: "bob" }, base: { ref: "main" }, head: { ref: "feature/auth" },
+ created_at: "2026-01-03T00:00:00Z", updated_at: "2026-01-05T00:00:00Z",
+ html_url: "https://github.com/acme/app/pull/10", changed_files: 5,
+ }
+ );
+ const upsert = ops.find((op: any) => op.type === "UpsertNode");
+ expect(upsert).toBeDefined();
+ expect(upsert!.kind).toBe("decision");
+ expect(upsert!.name).toBe("Add auth flow");
+ });
+
+ it("transforms a commit into UpsertNode ops with doc kind", async () => {
+ const { transformCommit } = await import("../github/transform.js");
+ const ops = transformCommit(
+ { owner: "acme", repo: "app" },
+ {
+ sha: "abc123def456",
+ commit: { message: "fix: resolve null pointer", author: { name: "carol", date: "2026-01-04T00:00:00Z" } },
+ html_url: "https://github.com/acme/app/commit/abc123def456",
+ files: [{ filename: "src/auth.ts", status: "modified" }],
+ }
+ );
+ const upsert = ops.find((op: any) => op.type === "UpsertNode");
+ expect(upsert).toBeDefined();
+ expect(upsert!.kind).toBe("doc");
+ expect(upsert!.name).toContain("fix: resolve null pointer");
+ });
+});
diff --git a/ix-cli/src/cli/github/transform.ts b/ix-cli/src/cli/github/transform.ts
new file mode 100644
index 00000000..d2955ad9
--- /dev/null
+++ b/ix-cli/src/cli/github/transform.ts
@@ -0,0 +1,174 @@
+import { createHash } from "node:crypto";
+import type { PatchOp } from "../../client/types.js";
+import type { GitHubRepo, GitHubIssue, GitHubPR, GitHubCommit, GitHubComment } from "./fetch.js";
+
+/** Generate a deterministic UUID-like ID from a string. */
+export function deterministicId(input: string): string {
+ const hash = createHash("sha256").update(input).digest("hex");
+ return [
+ hash.slice(0, 8),
+ hash.slice(8, 12),
+ hash.slice(12, 16),
+ hash.slice(16, 20),
+ hash.slice(20, 32),
+ ].join("-");
+}
+
+function truncate(s: string | null | undefined, max: number): string {
+ if (!s) return "";
+ return s.length > max ? s.slice(0, max) + "..." : s;
+}
+
+export function transformIssue(repo: GitHubRepo, issue: GitHubIssue): PatchOp[] {
+ const uri = `github://${repo.owner}/${repo.repo}/issues/${issue.number}`;
+ const nodeId = deterministicId(uri);
+ return [
+ {
+ type: "UpsertNode",
+ id: nodeId,
+ kind: "intent",
+ name: issue.title,
+ attrs: {
+ number: issue.number,
+ url: issue.html_url,
+ author: issue.user?.login ?? "unknown",
+ labels: issue.labels.map(l => l.name),
+ state: issue.state,
+ created_at: issue.created_at,
+ body: truncate(issue.body, 2000),
+ source_uri: uri,
+ },
+ },
+ ];
+}
+
+export function transformIssueComment(
+ repo: GitHubRepo, issueNumber: number, comment: GitHubComment
+): PatchOp[] {
+ const parentUri = `github://${repo.owner}/${repo.repo}/issues/${issueNumber}`;
+ const commentUri = `${parentUri}/comments/${comment.id}`;
+ const parentId = deterministicId(parentUri);
+ const commentId = deterministicId(commentUri);
+ const edgeId = deterministicId(`${parentUri}:CONTAINS:${commentUri}`);
+ return [
+ {
+ type: "UpsertNode",
+ id: commentId,
+ kind: "doc",
+ name: `Issue #${issueNumber} comment by ${comment.user?.login ?? "unknown"}`,
+ attrs: {
+ url: comment.html_url,
+ author: comment.user?.login ?? "unknown",
+ created_at: comment.created_at,
+ body: truncate(comment.body, 2000),
+ source_uri: commentUri,
+ },
+ },
+ {
+ type: "UpsertEdge",
+ id: edgeId,
+ src: parentId,
+ dst: commentId,
+ predicate: "CONTAINS",
+ attrs: {},
+ },
+ ];
+}
+
+export function transformPR(repo: GitHubRepo, pr: GitHubPR): PatchOp[] {
+ const uri = `github://${repo.owner}/${repo.repo}/pull/${pr.number}`;
+ const nodeId = deterministicId(uri);
+ return [
+ {
+ type: "UpsertNode",
+ id: nodeId,
+ kind: "decision",
+ name: pr.title,
+ attrs: {
+ number: pr.number,
+ url: pr.html_url,
+ author: pr.user?.login ?? "unknown",
+ state: pr.state,
+ merged: !!pr.merged_at,
+ base_branch: pr.base.ref,
+ head_branch: pr.head.ref,
+ created_at: pr.created_at,
+ changed_files_count: pr.changed_files,
+ body: truncate(pr.body, 2000),
+ rationale: truncate(pr.body, 500),
+ source_uri: uri,
+ },
+ },
+ ];
+}
+
+export function transformPRComment(
+ repo: GitHubRepo, prNumber: number, comment: GitHubComment
+): PatchOp[] {
+ const parentUri = `github://${repo.owner}/${repo.repo}/pull/${prNumber}`;
+ const commentUri = `${parentUri}/comments/${comment.id}`;
+ const parentId = deterministicId(parentUri);
+ const commentId = deterministicId(commentUri);
+ const edgeId = deterministicId(`${parentUri}:CONTAINS:${commentUri}`);
+ return [
+ {
+ type: "UpsertNode",
+ id: commentId,
+ kind: "doc",
+ name: `PR #${prNumber} review by ${comment.user?.login ?? "unknown"}`,
+ attrs: {
+ url: comment.html_url,
+ author: comment.user?.login ?? "unknown",
+ created_at: comment.created_at,
+ body: truncate(comment.body, 2000),
+ source_uri: commentUri,
+ },
+ },
+ {
+ type: "UpsertEdge",
+ id: edgeId,
+ src: parentId,
+ dst: commentId,
+ predicate: "CONTAINS",
+ attrs: {},
+ },
+ ];
+}
+
+export function transformCommit(repo: GitHubRepo, commit: GitHubCommit): PatchOp[] {
+ const uri = `github://${repo.owner}/${repo.repo}/commit/${commit.sha}`;
+ const nodeId = deterministicId(uri);
+ const message = commit.commit.message.split("\n")[0];
+ const ops: PatchOp[] = [
+ {
+ type: "UpsertNode",
+ id: nodeId,
+ kind: "doc",
+ name: message,
+ attrs: {
+ sha: commit.sha,
+ url: commit.html_url,
+ author: commit.commit.author?.name ?? "unknown",
+ created_at: commit.commit.author?.date,
+ message: truncate(commit.commit.message, 2000),
+ changed_files: commit.files?.map(f => f.filename) ?? [],
+ source_uri: uri,
+ },
+ },
+ ];
+ if (commit.files) {
+ for (const file of commit.files) {
+ const fileNodeId = deterministicId(`${repo.owner}/${repo.repo}::${file.filename}`);
+ const edgeId = deterministicId(`${uri}:REFERENCES:${file.filename}`);
+ ops.push({
+ type: "UpsertEdge",
+ id: edgeId,
+ src: nodeId,
+ dst: fileNodeId,
+ predicate: "REFERENCES",
+ attrs: { change_type: file.status },
+ });
+ }
+ }
+ return ops;
+}