Skip to content

Commit a1082e6

Browse files
committed
feat: wire content scripts and styling
1 parent 135857b commit a1082e6

4 files changed

Lines changed: 76 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
dist
33
dist-ssr
44
*.local
5+
git-history.ps1

scratch/github-test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { GitHubClient, GitHubError } from '../src/github/client';
2+
3+
async function runTest() {
4+
const pat = process.env.GITHUB_PAT;
5+
const repo = process.env.GITHUB_REPO; // e.g. "username/repo"
6+
7+
if (!pat || !repo) {
8+
console.error("Please provide GITHUB_PAT and GITHUB_REPO environment variables.");
9+
process.exit(1);
10+
}
11+
12+
const client = new GitHubClient(pat, repo);
13+
const testPath = 'test-file.txt'; // Root level
14+
15+
try {
16+
console.log(`1. Testing connection to ${repo}...`);
17+
await client.testConnection();
18+
console.log("Connection successful!");
19+
20+
console.log(`\n2. Creating file at ${testPath}...`);
21+
const initialContent = "Hello CommitCode (V1) - " + Date.now();
22+
await client.putFile(testPath, initialContent, "chore: create test file");
23+
console.log("File created successfully.");
24+
25+
console.log(`\n3. Fetching file to get current SHA...`);
26+
const file = await client.getFile(testPath);
27+
console.log("File fetched. SHA:", file.sha);
28+
29+
console.log(`\n4. Updating file with correct SHA...`);
30+
const updatedContent = "Hello CommitCode (V2) - " + Date.now();
31+
await client.putFile(testPath, updatedContent, "chore: update test file", file.sha);
32+
console.log("File updated successfully.");
33+
34+
console.log(`\n5. Testing 409 Conflict handling (stale SHA)...`);
35+
try {
36+
await client.putFile(testPath, "This should fail", "chore: conflicting update", file.sha); // using the old SHA from step 3
37+
console.error("ERROR: The update should have failed with a 409 conflict, but it succeeded!");
38+
} catch (e: any) {
39+
if (e instanceof GitHubError && e.status === 409) {
40+
console.log("SUCCESS: Caught 409 Conflict error as expected!");
41+
console.log("Error message:", e.message);
42+
} else {
43+
console.error("ERROR: Expected 409 Conflict, got something else:", e);
44+
}
45+
}
46+
47+
} catch (err) {
48+
console.error("Test failed:", err);
49+
}
50+
}
51+
52+
runTest();

src/content/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { LeetCodeAdapter } from '../platforms/leetcode/adapter';
2+
3+
console.log('[CommitCode] Content script loaded on', window.location.href);
4+
5+
const adapter = new LeetCodeAdapter();
6+
adapter.startListening((problem) => {
7+
console.log('[CommitCode] Sending problem to Sync Engine:', problem);
8+
chrome.runtime.sendMessage({ type: 'SYNC_PROBLEM', problem });
9+
});

src/platforms/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ProblemRecord } from '../storage/types';
2+
3+
export interface PlatformAdapter {
4+
/**
5+
* Initializes any listeners or mutation observers needed to detect a submission.
6+
* Calls the provided callback when an accepted submission is detected.
7+
*/
8+
startListening(onSubmissionDetected: (problem: ProblemRecord) => void): void;
9+
10+
/**
11+
* Cleans up any listeners.
12+
*/
13+
stopListening(): void;
14+
}

0 commit comments

Comments
 (0)