mirror of
https://github.com/silvanocerza/github-gitless-sync.git
synced 2026-07-22 05:41:36 +00:00
Fix benchmark script and Obsidian mock
This commit is contained in:
parent
457a0b6d24
commit
96da957f18
2 changed files with 29 additions and 21 deletions
28
benchmark.ts
28
benchmark.ts
|
|
@ -143,14 +143,22 @@ const generateRandomFiles = (
|
|||
fs.writeFileSync(metadataFilePath, JSON.stringify(metadata), { flag: "w" });
|
||||
};
|
||||
|
||||
const cleanupRemote = async () => {
|
||||
const cleanupRemote = () => {
|
||||
const url = `git@github.com:${process.env.REPO_OWNER}/${process.env.REPO_NAME}.git`;
|
||||
const clonedDir = path.join(os.tmpdir(), "temp-clone");
|
||||
|
||||
// Remove the folder in case it already exists
|
||||
fs.rmSync(clonedDir, { recursive: true, force: true });
|
||||
|
||||
try {
|
||||
// Clone the repository
|
||||
execSync(`git clone ${url} ${clonedDir}`, { stdio: "ignore" });
|
||||
|
||||
const repoExists = fs.existsSync(clonedDir);
|
||||
if (!repoExists) {
|
||||
throw Error("Failed to clone repo");
|
||||
}
|
||||
|
||||
// Remove all files except .git
|
||||
execSync('find . -type f -not -path "./.git*" -delete', {
|
||||
stdio: "ignore",
|
||||
|
|
@ -166,16 +174,12 @@ const cleanupRemote = async () => {
|
|||
|
||||
// Push changes
|
||||
execSync("git push", { stdio: "ignore", cwd: clonedDir });
|
||||
|
||||
// Remove the folder
|
||||
fs.rm(clonedDir, { recursive: true, force: true }, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Error: ${error.message}`);
|
||||
}
|
||||
|
||||
// Remove the folder when everything is done
|
||||
fs.rmSync(clonedDir, { recursive: true, force: true });
|
||||
};
|
||||
|
||||
const BENCHMARK_DATA = [
|
||||
|
|
@ -248,7 +252,7 @@ const BENCHMARK_DATA = [
|
|||
const downloadTime = await runBenchmark(vaultRootDir);
|
||||
|
||||
// Cleanup the remote repo so it's ready for another benchmark
|
||||
await cleanupRemote();
|
||||
cleanupRemote();
|
||||
|
||||
results.push({
|
||||
data,
|
||||
|
|
@ -265,9 +269,5 @@ const BENCHMARK_DATA = [
|
|||
} catch (error) {
|
||||
console.error("Benchmark failed:", error);
|
||||
}
|
||||
fs.rm(benchmarkRootDir, { recursive: true, force: true }, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
fs.rmSync(benchmarkRootDir, { recursive: true, force: true });
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -128,11 +128,22 @@ export async function requestUrl(options: RequestUrlParam) {
|
|||
body: options.body,
|
||||
});
|
||||
|
||||
const isJsonResponse = response.headers
|
||||
.get("content-type")
|
||||
?.includes("application/json");
|
||||
|
||||
// Convert to expected Obsidian response format
|
||||
if (isJsonResponse) {
|
||||
return {
|
||||
status: response.status,
|
||||
json: await response.json(),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: response.status,
|
||||
arrayBuffer: await response.arrayBuffer(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Mock utility functions
|
||||
|
|
@ -150,6 +161,3 @@ export function base64ToArrayBuffer(base64: string): ArrayBuffer {
|
|||
|
||||
// Mock Event reference
|
||||
export type EventRef = string;
|
||||
|
||||
// Re-export the fileTypeFromBuffer function
|
||||
export { fileTypeFromBuffer } from "file-type";
|
||||
|
|
|
|||
Loading…
Reference in a new issue