add gitClient with repo cloning, pushing, and commits

This commit is contained in:
Tejas Srikanth 2023-03-18 17:04:22 -04:00
parent 40219368d5
commit 6505cde2db
1 changed files with 50 additions and 0 deletions

50
src/gitClient.ts Normal file
View File

@ -0,0 +1,50 @@
import { mkdtemp } from "fs";
import { tmpdir } from "os";
import { join } from "path";
const { exec } = require("child_process");
export function cloneRepo(httpAddr, callback){
mkdtemp(join(tmpdir(), 'dt-'), (err, folder) => {
if (err) throw err;
var fString = folder;
exec("git clone " + httpAddr + " " + fString, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
console.log(`stdout: ${stderr}`);
callback(fString);
return fString;
})
})
}
export function pushRepo(repoPath){
exec("git -C " + repoPath + " push", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
console.log(`stdout: ${stderr}`);
})
}
export function commitRepo(repoPath){
exec("git -C " + repoPath + " add .", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
console.log(`stdout: ${stderr}`);
exec("git -C " + repoPath + " commit -m \"generic commit message\"", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
console.log(`stdout: ${stderr}`);
})
})
}