forked from itsTeknas/GitlabBackupUtil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (44 loc) · 1.01 KB
/
index.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
let rp = require('request-promise');
let _ = require('lodash');
let tokenJson = require('./token')
const token = tokenJson.token;
let Promise = require('bluebird')
let cmd = require('node-cmd')
rp.get('https://www.gitlab.com/api/v4/groups', {
json: true,
qs: {
simple: true,
},
headers: {
'PRIVATE-TOKEN': token
}
}).then(groups => {
let gids = _.map(groups, 'id')
let pgits = [];
let promises = [];
for (let gid of gids) {
promises.push(
rp.get(`https://www.gitlab.com/api/v4/groups/${gid}/projects`, {
json: true,
qs: {
simple: true,
},
headers: {
'PRIVATE-TOKEN': token
}
}).then(projects => {
let ps = _.map(projects, 'http_url_to_repo')
for (let p of ps) {
pgits.push(p);
}
})
)
}
Promise.all(promises).then(() => {
console.log(pgits);
for (let git of pgits) {
cmd.run(`git clone ${git} backup/${git.substring(19,git.length-4)}`);
}
});
})