add gitClient with repo cloning, pushing, and commits
This commit is contained in:
parent
40219368d5
commit
6505cde2db
|
@ -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}`);
|
||||
})
|
||||
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue