Skip to content

Commit 9df0c9d

Browse files
committed
first work (throws error: [Error: Empty value for parameter 'user': undefined])
1 parent 31c6b3a commit 9df0c9d

File tree

4 files changed

+231
-0
lines changed

4 files changed

+231
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ build/Release
2525
# Dependency directory
2626
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
2727
node_modules
28+
29+
# ignore settings.json
30+
settings.json

index.js

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
var GitHubApi = require("github");
2+
var Gitlab = require('gitlab');
3+
var async = require('async');
4+
5+
var settings = require('./settings.json');
6+
console.log(settings);
7+
8+
var gitlab = Gitlab({
9+
url: settings.gitlab.url,
10+
token: settings.gitlab.token
11+
});
12+
13+
if (settings.gitlab.projectID === null) {
14+
gitlab.projects.all(function(projects) {
15+
projects = projects.sort(function(a, b) {
16+
return a.id - b.id;
17+
});
18+
for (var i = 0; i < projects.length; i++) {
19+
console.log(projects[i].id, projects[i].description, projects[i].name);
20+
}
21+
console.log('\n\n');
22+
console.log('Select which project ID should be transported to github. Edit the settings.json accordingly. (gitlab.projectID)');
23+
console.log('\n\n');
24+
});
25+
} else {
26+
// user has choosen a project
27+
28+
29+
var github = new GitHubApi({
30+
// required
31+
version: "3.0.0",
32+
// optional
33+
debug: true,
34+
protocol: "https",
35+
host: "api.github.com",
36+
pathPrefix: "",
37+
timeout: 5000,
38+
headers: {
39+
"user-agent": "node-gitlab-2-github" // GitHub is happy with a unique user agent
40+
}
41+
});
42+
github.authenticate({
43+
type: "basic",
44+
username: settings.github.username,
45+
password: settings.github.password
46+
});
47+
48+
49+
50+
51+
52+
// TODO check whether user has created all milestones on github
53+
54+
gitlab.projects.milestones.list(settings.gitlab.projectID, function(data) {
55+
data = data.sort(function(a, b) {
56+
return a.id - b.id;
57+
});
58+
github.issues.getAllMilestones({
59+
user: settings.github.username,
60+
repo: settings.github.repo
61+
}, function(err, milestoneDataOpen) {
62+
github.issues.getAllMilestones({
63+
user: settings.github.username,
64+
repo: settings.github.repo,
65+
state: 'closed'
66+
}, function(err, milestoneDataClosed) {
67+
milestoneData = milestoneDataClosed.concat(milestoneDataOpen);
68+
milestoneDataMapped = milestoneData.map(function(item) {
69+
return item.title;
70+
});
71+
72+
console.log('\n\n\n\n\n\n\n>>>>');
73+
console.log(milestoneDataMapped);
74+
console.log('\n\n\n\n\n\n\n');
75+
console.log(milestoneDataClosed[0]);
76+
77+
console.log('\n\n\n\n\n\n\n');
78+
async.each(data, function(item, cb) {
79+
if (milestoneDataMapped.indexOf(item.title) < 0) {
80+
console.log('Creating new Milestone', item.title);
81+
createMilestone(item, function(err, createMilestoneData) {
82+
console.log(createMilestoneData);
83+
cb(err);
84+
});
85+
} else {
86+
cb(err);
87+
}
88+
}, function(err) {
89+
if (err) return console.log(err);
90+
// all milestones are created
91+
createAllIssuesAndComments(milestoneData);
92+
93+
94+
}); // async
95+
96+
}); // closed Issues
97+
}); // opend issues
98+
}); // gitlab list milestones
99+
}
100+
101+
102+
function createAllIssuesAndComments(milestoneData) {
103+
// select all issues and comments from this project
104+
gitlab.projects.issues.list(settings.gitlab.projectID, function(issueData) {
105+
// look whether issue is already created
106+
console.log('length:', issueData.length)
107+
108+
// console.log('~', issueData);
109+
async.eachSeries(issueData, function(item, cb) {
110+
console.log(settings.github.username);
111+
var props = {
112+
user: settings.github.username,
113+
repo: settings.github.repo,
114+
title: item.title,
115+
body: item.description
116+
};
117+
if(item.assignee && item.assignee.username == settings.github.username){
118+
props.assignee = item.assignee.username;
119+
}
120+
if (item.milestone) {
121+
var title = findMileStoneforTitle(milestoneData, item.milestone.title)
122+
if (title !== null) {
123+
props.milestone = title;
124+
} else {
125+
// don't import issues where milestone got deleted
126+
return cb();
127+
}
128+
}
129+
console.log('props:', props);
130+
github.issues.create({
131+
props
132+
}, function(err, data) {
133+
console.log('errData' , err, data);
134+
if (!err) {
135+
createAllIssueComments(settings.gitlab.projectID, item.id, data, cb);
136+
} else {
137+
cb(err);
138+
}
139+
});
140+
}, function(err) {
141+
console.log('error with issueData:', err);
142+
});
143+
144+
})
145+
}
146+
147+
function findMileStoneforTitle(milestoneData, title) {
148+
for (var i = milestoneData.length - 1; i >= 0; i--) {
149+
if (milestoneData[i].title == title) {
150+
console.log(milestoneData[i].number);
151+
return milestoneData[i].number;
152+
}
153+
}
154+
return null;
155+
}
156+
157+
function createAllIssueComments(projectID, issueID, newIssueData, cb) {
158+
// get all comments add them to the comment
159+
gitlab.issues.notes.all(projectID, issueID, function(data) {
160+
if (data.length) {
161+
for (var i = data.length - 1; i >= 0; i--) {
162+
163+
github.issues.createComment({
164+
user: settings.github.username,
165+
repo: settings.github.repo,
166+
number: newIssueData.number,
167+
body: data[i].body
168+
}, cb)
169+
}
170+
}
171+
})
172+
}
173+
174+
175+
function createMilestone(data, cb) {
176+
github.issues.createMilestone({
177+
username: settings.github.username,
178+
repo: settings.github.repo,
179+
title: data.title,
180+
description: data.description,
181+
state: (data.state === 'active') ? 'open' : 'closed',
182+
due_on: data.due_date + 'T00:00:00Z'
183+
}, cb);
184+
}

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "gitlab-2-github",
3+
"version": "0.0.1",
4+
"description": "Migrate Issues, Wiki from gitlab to github",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/piceaTech/node-gitlab-2-github.git"
12+
},
13+
"keywords": [
14+
"github",
15+
"gitlab",
16+
"import",
17+
"export",
18+
"issue",
19+
"issues"
20+
],
21+
"author": "Spruce, <dev@spruce.de>",
22+
"license": "MIT",
23+
"bugs": {
24+
"url": "https://github.com/piceaTech/node-gitlab-2-github/issues"
25+
},
26+
"homepage": "https://github.com/piceaTech/node-gitlab-2-github#readme",
27+
"dependencies": {
28+
"async": "^1.4.0",
29+
"github": "^0.2.4",
30+
"gitlab": "^1.3.0"
31+
}
32+
}

sample_settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"gitlab": {
3+
"url": "http://gitlab.mycompany.com/",
4+
"token": "{{gitlab private token}}",
5+
"projectID": null
6+
},
7+
"github": {
8+
"username": "{{username}}",
9+
"password": "{{password}}",
10+
"repo": "{{repo}}"
11+
}
12+
}

0 commit comments

Comments
 (0)