This repository has been archived by the owner on Sep 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
95 lines (82 loc) · 2.8 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'use strict';
const axios = require('axios');
const log4js = require('log4js');
const logger = log4js.getLogger();
logger.level = 'trace';
const URLS = {
old: 'https://gitlab.com/api/v3',
new: 'https://beta.gitlab.com/api/v4'
}
const TOKENS = {
old: 'Get from user account in old GitLab instance',
new: 'Get from user account in old GitLab instance',
}
const generateHierarchy = () => {
var config = {
headers: { 'PRIVATE-TOKEN': TOKENS.old }
};
axios.get(`${URLS.old}/groups?per_page=100`, config)
.then(response => {
const groups = response.data;
// for each group, get it's associated projects.
groups.forEach(element => {
// logger.debug('URL: ', `${URLS.old}/groups/${element.id}?per_page=100`);
axios.get(`${URLS.old}/groups/${element.id}?per_page=100`, config)
.then(resp => {
const projects = resp.data.projects;
// logger.debug('Projects for group: ', element.name, ' response: ', projects);
// Create group.
const groupParams = {
name: element.name,
path: element.path,
parent_id: 146,
visibility: 'private',
lfs_enabled: false,
request_access_enabled: false,
};
var newConfig = {
headers: { 'PRIVATE-TOKEN': TOKENS.new}
};
// Create group structure.
axios.post(`${URLS.new}/groups`, groupParams, newConfig)
.then(resp => {
const groupData = resp.data;
logger.debug('Response from group creation: ', groupData);
// Create projects associated with the group.
projects.forEach(project => {
const projectParams = {
name: project.name,
path: project.path,
namespace_id: groupData.id,
default_branch: project.default_branch,
description: project.description,
wiki_enabled: true,
shared_runners_enabled: true,
visibility: 'private',
// import_url: project.http_url_to_repo
};
// Create projects in group.
axios.post(`${URLS.new}/projects`, projectParams, newConfig)
.then(res => {
logger.debug(`Successfully migrated Project ${project.name}: `, res.data);
})
.catch(e => {
logger.error('Error creating Project: ', e);
});
});
})
.catch(errors => {
logger.error('Error creating Group: ', errors);
});
})
.catch(err => {
logger.error(`Error getting Projects for group ${element.name}: `, err);
});
}, this);
})
.catch(error => {
logger.error(`Error getting groups for ${URLS.old}: `, error);
});
};
// Generate the GitLab Group/Project Hierarchy.
generateHierarchy();