forked from finos/git-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpullRemote.ts
More file actions
58 lines (45 loc) · 1.33 KB
/
pullRemote.ts
File metadata and controls
58 lines (45 loc) · 1.33 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Action, Step } from '../../actions';
import fs from 'fs';
import git from 'isomorphic-git';
import gitHttpClient from 'isomorphic-git/http/node';
const dir = './.remote';
const exec = async (req: any, action: Action): Promise<Action> => {
const step = new Step('pullRemote');
try {
action.proxyGitPath = `${dir}/${action.timestamp}`;
step.log(`Creating folder ${action.proxyGitPath}`);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
if (!fs.existsSync(action.proxyGitPath)) {
fs.mkdirSync(action.proxyGitPath, 0o755);
}
const cmd = `git clone ${action.url}`;
step.log(`Executing ${cmd}`);
const authHeader = req.headers?.authorization;
const [username, password] = Buffer.from(authHeader.split(' ')[1], 'base64')
.toString()
.split(':');
await git.clone({
fs,
http: gitHttpClient,
url: action.url,
onAuth: () => ({
username,
password,
}),
dir: `${action.proxyGitPath}/${action.repoName}`,
});
console.log('Clone Success: ', action.url);
step.log(`Completed ${cmd}`);
step.setContent(`Completed ${cmd}`);
} catch (e: any) {
step.setError(e.toString('utf-8'));
throw e;
} finally {
action.addStep(step);
}
return action;
};
exec.displayName = 'pullRemote.exec';
export { exec };