-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.js
31 lines (26 loc) · 859 Bytes
/
repo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const ch = require('child_process');
const spawn = ch.spawn;
const fs = require('fs');
const os = require('os');
async function execi(cmd){
const exe = cmd.split(' ');
return await new Promise((resolve, reject) => {
const shell = spawn(exe[0], exe.slice(1), { stdio: 'inherit' });
shell.on('close', code => {
code === 0 ? resolve(code) : reject(code);
});
});
}
class RepoManager {
constructor(problemRepo, submissionRepo) {
this.prepo = problemRepo;
this.srepo = submissionRepo;
}
async prepareWorkRepo () {
const dir = await fs.promises.mkdtemp(os.tmpdir() + '/crp-');
console.log(':: clone work repo');
await execi(`git clone -b master --depth=1 https://github.com/${this.prepo} ${dir}`);
this.pdir = dir;
}
}
module.exports = RepoManager;