@@ -4,6 +4,8 @@ import * as obsidianMocks from "./mock-obsidian";
44import * as os from "os" ;
55import * as path from "path" ;
66import * as crypto from "crypto" ;
7+ import { execSync } from "child_process" ;
8+
79const proxyquireNonStrict = proxyquire . noCallThru ( ) ;
810
911const LoggerModule = proxyquireNonStrict ( "./src/logger" , {
@@ -164,35 +166,37 @@ const generateRandomFiles = (
164166} ;
165167
166168const cleanupRemote = async ( ) => {
167- const owner = process . env . REPO_OWNER ;
168- const repo = process . env . REPO_NAME ;
169- const branch = process . env . REPO_BRANCH ;
170- const headers = {
171- Accept : "application/vnd.github+json" ,
172- Authorization : `Bearer ${ process . env . GITHUB_TOKEN } ` ,
173- "X-GitHub-Api-Version" : "2022-11-28" ,
174- } ;
169+ const url = `[email protected] :${ process . env . REPO_OWNER } /${ process . env . REPO_NAME } .git` ; 170+ const clonedDir = path . join ( os . tmpdir ( ) , "temp-clone" ) ;
171+
175172 try {
176- // Get the manifest SHA
177- const contentResponse = await obsidianMocks . requestUrl ( {
178- url : `https://api.github.com/repos/${ owner } /${ repo } /contents/.obsidian/github-sync-metadata.json?ref=${ branch } ` ,
179- headers : headers ,
173+ // Clone the repository
174+ execSync ( `git clone ${ url } ${ clonedDir } ` , { stdio : "ignore" } ) ;
175+
176+ // Remove all files except .git
177+ execSync ( 'find . -type f -not -path "./.git*" -delete' , {
178+ stdio : "ignore" ,
179+ cwd : clonedDir ,
180180 } ) ;
181181
182- // Delete manifest
183- await obsidianMocks . requestUrl ( {
184- url : `https://api.github.com/repos/${ owner } /${ repo } /contents/.obsidian/github-sync-metadata.json` ,
185- method : "DELETE" ,
186- headers : headers ,
187- body : JSON . stringify ( {
188- message : "Cleanup" ,
189- sha : contentResponse . json . sha ,
190- branch : branch ,
191- } ) ,
182+ // Commit empty state
183+ execSync ( "git add -A" , { stdio : "ignore" , cwd : clonedDir } ) ;
184+ execSync ( 'git commit -m "Cleanup"' , {
185+ stdio : "ignore" ,
186+ cwd : clonedDir ,
187+ } ) ;
188+
189+ // Push changes
190+ execSync ( "git push" , { stdio : "ignore" , cwd : clonedDir } ) ;
191+
192+ // Remove the folder
193+ fs . rm ( clonedDir , { recursive : true , force : true } , ( err ) => {
194+ if ( err ) {
195+ throw err ;
196+ }
192197 } ) ;
193- console . log ( "Remote repository cleaned up successfully" ) ;
194198 } catch ( error ) {
195- console . error ( "Failed to clean up remote repository:" , error ) ;
199+ console . error ( `Error: ${ error . message } ` ) ;
196200 }
197201} ;
198202
0 commit comments