11import { exec } from "child_process"
22import { Request , Response } from "express"
33import { existsSync , rmdirSync } from "fs"
4+ import { promisify } from "util"
45import { v4 as uuidv4 } from "uuid"
6+
57import { insertStyleguides } from "../core/styleguides"
68import { insertDataIntoDB } from "../process/ingest/ingest"
79import { Codebase } from "../process/prepare/codebase"
@@ -14,29 +16,23 @@ import { FileProcessor } from "../process/prepare/processor/file"
1416 * @param remoteURL The url of directory which is to be colned using git clone
1517 * @returns true/false (boolean) representing the success or failure respectively
1618 */
17- function fetchCodebaseFromRemote ( dirName : string , remoteURL : string ) : boolean {
18- let success = true
19+ async function fetchCodebaseFromRemote (
20+ dirName : string ,
21+ remoteURL : string
22+ ) : Promise < boolean > {
23+ console . log ( `Fetching codebase from ${ remoteURL } to ${ dirName } ` )
24+
1925 try {
20- if ( existsSync ( dirName ) ) {
21- rmdirSync ( dirName , { recursive : true } )
22- }
26+ if ( existsSync ( dirName ) ) rmdirSync ( dirName , { recursive : true } )
2327
2428 const gitCloneCommand = `git clone ${ remoteURL } ${ dirName } `
29+ await promisify ( exec ) ( gitCloneCommand )
2530
26- exec ( gitCloneCommand , ( error , stdout , stderr ) => {
27- success = false
28-
29- if ( error ) {
30- console . error ( `Error executing command: ${ error . message } ` )
31- return
32- }
33- console . log ( `stdout: ${ stdout } ` )
34- } )
35- } catch {
36- success = false
31+ return true
32+ } catch ( e ) {
33+ console . error ( e )
34+ return false
3735 }
38-
39- return success
4036}
4137
4238/**
@@ -173,10 +169,11 @@ export async function ingestRoute(req: Request, res: Response) {
173169 let success = false
174170
175171 /* Step 1: Fetch codebase to local storage */
176- success = fetchCodebaseFromRemote (
172+ success = await fetchCodebaseFromRemote (
177173 sessionID ,
178174 "https://github.com/RocketChat/Rocket.Chat"
179175 )
176+
180177 if ( ! success )
181178 return await sendFailureResponse ( failureURL , "FETCH_FAIL" , startTime )
182179
0 commit comments