Skip to content

Commit

Permalink
chore: fix pull issue (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
nully0x authored Nov 26, 2024
1 parent 258a408 commit ab878bd
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions src/utils/testRepoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class TestRepoManager {
private repoDir: string | null = null;

private constructor() {
// Initialize repoDir to a fixed location
this.repoDir = path.join(os.tmpdir(), "hxckr-test-repo");
}

Expand All @@ -26,50 +25,40 @@ export class TestRepoManager {

private async initializeRepo(): Promise<void> {
try {
// Check if directory exists
const exists = await fs
.access(this.repoDir!)
await fs.mkdir(this.repoDir!, { recursive: true });
const isGitRepo = await fs
.access(path.join(this.repoDir!, ".git"))
.then(() => true)
.catch(() => false);

if (!exists) {
// First time: Clone the repository
await fs.mkdir(this.repoDir!, { recursive: true });
if (!isGitRepo) {
await execAsync(
`git clone -b ${TEST_REPO_CONFIG.branch} ${TEST_REPO_CONFIG.repoUrl} ${this.repoDir}`,
);
logger.info("Test repository cloned successfully");
} else {
await execAsync(`cd ${this.repoDir} && git pull`);
logger.info("Test repository updated successfully");
}
} catch (error) {
logger.error("Error initializing test repository", { error });
throw error;
}
}

private async updateRepo(): Promise<void> {
try {
await execAsync(`cd ${this.repoDir} && git pull --rebase`);
logger.info("Test repository updated successfully");
} catch (error) {
logger.error("Error updating test repository", { error });
throw error;
}
}

public static getTestExtension(language: string): string {
const extensions: Record<string, string> = {
typescript: ".test.ts",
rust: ".test.rs",
python: "_test.py",
// Add more languages as needed
};
return extensions[language] || ".test";
}

private async ensureRepoUpdated(): Promise<string> {
try {
// Initialize repo if it doesn't exist
await this.initializeRepo();

return this.repoDir!;
} catch (error) {
logger.error("Error ensuring repo is updated", { error });
Expand All @@ -92,7 +81,9 @@ export class TestRepoManager {
);

try {
return await fs.readFile(testPath, "utf-8");
const content = await fs.readFile(testPath, "utf-8");
logger.info("Test content retrieved successfully");
return content;
} catch (error) {
logger.error("Error reading test file", {
testPath,
Expand All @@ -105,11 +96,10 @@ export class TestRepoManager {
}
}

// We don't need cleanup anymore since we're keeping the repo
// But we might want a method to force update
public async forceUpdate(): Promise<void> {
try {
await this.updateRepo();
await execAsync(`cd ${this.repoDir} && git pull`);
logger.info("Test repository force updated successfully");
} catch (error) {
logger.error("Error forcing update", { error });
throw error;
Expand Down

0 comments on commit ab878bd

Please sign in to comment.