-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrator.ts
More file actions
68 lines (50 loc) · 1.65 KB
/
migrator.ts
File metadata and controls
68 lines (50 loc) · 1.65 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
59
60
61
62
63
64
65
66
67
68
import * as log from "https://deno.land/std/log/mod.ts"
import { parse } from "https://deno.land/std/flags/mod.ts"
import { exec } from 'https://deno.land/x/execute/mod.ts'
async function run(){
try {
// d: working dir name
// b: bitbucket repo
// g: github repo
// p: public repo (optional)
// a: archive repo (optional)
let args = parse(Deno.args)
if (!args.hasOwnProperty('g') || !args.hasOwnProperty('b')) {
throw new Error('Please input all required argrements')
}
const workingDir = !args.d ? '.' : args.d
const bitbucketRepo = "git@bitbucket.org:" + args.b
const githubRepo = "git@github.com:" + args.g
log.info('Start cloning '+ bitbucketRepo)
await exec({
cmd: ['git', 'clone', '--bare', bitbucketRepo, workingDir],
})
log.info('Clone '+ bitbucketRepo + 'is finished');
let hubCreateCmd: Array<string> = ['hub', 'create', '-p', args.g]
if (args.p) {
hubCreateCmd.splice(2, 1);
}
log.info('Start creating '+ githubRepo)
const hubCreatedOutput = await exec({
cmd: hubCreateCmd,
cwd: workingDir
})
log.info('Gtihub repo is created: ' + hubCreatedOutput);
log.info('Starting: git push --mirror' + githubRepo)
await exec({
cmd: ['git', 'push', `--mirror`, githubRepo],
cwd: workingDir
})
log.info('git push --mirror ' + githubRepo + ' is finished')
if (args.a){
log.info('Start archieving repo: ' + githubRepo)
await exec({
cmd: ['hub', 'api', 'repos/'+ args.g, '--field', 'archived=true'],
cwd: workingDir
})
}
} catch (error) {
log.error(error);
}
}
run();