.describe('f', 'The first issue # to import (Example: 123)')
.argv;
-var inputFile = __dirname + '/' + argv.input;
-var configFile = __dirname + '/' + argv.config;
+var inputFile = argv.input;
+var configFile = argv.config;
var fromIssueId = Number(argv.from||0);
var gitlabAPIURLBase = argv.gitlaburl + '/api/v4';
var gitlabProjectName = argv.project;
*/
function getConfig() {
log_progress("Reading configuration...");
- return FS.read(configFile, {encoding: 'utf8'})
+ return FS.read(configFile)
.then(function(data) {
var config = JSON.parse(data);
+
config.users = _.extend({
"": {
name: "Unknown",
var url = gitlabAPIURLBase + '/projects';
var data = { per_page: 100, private_token: gitlabAdminPrivateToken, sudo: gitlabSudo };
- return rest.get(url, {data: data}).then(function(result) {
-
+ return rest.get(url, {data: data})
+ .fail(function(err) {
+ console.log(err);
+ })
+ .then(function(result) {
gitLab.project = _.find(result, { path_with_namespace : gitlabProjectName }) || null;
if (!gitLab.project) {
var users = config.users,
gitlabUsers = gitLab.gitlabUsers;
_.forEach(users, function(user) {
- user.gl_id = (_.find(gitlabUsers, { id: user.gl_username }) || {}).id;
+ user.gl_id = (_.find(gitlabUsers, { username: user.gl_username }) || {}).id;
});
}
return getIssue(gitLab.project.id, issueId)
.then(function(gitLabIssue) {
- if (gitLabIssue) {
- return updateIssue(gitLab.project.id, issueId, _.extend({
+ //console.log(data.title + " -- " + issueId);
+ //console.log(data.title + " -- " + issueId + " -- " + gitLab.gitlabIssues[issueId]);
+ if (gitLab.gitlabIssues[issueId]) {
+ // update
+ console.log("updating: " + data.title + " (Issueid: " + issueId + ")");
+ return updateIssue(gitLab.project.id, gitLabIssue.iid, _.extend({
state_event: isClosed(mantisIssue) ? 'close' : 'reopen'
}, data))
.then(function() {
- console.log(("#" + issueId + ": Updated successfully.").green);
+ console.log(("#" + gitLabIssue.iid + ": Updated successfully.").green);
});
} else {
+ // insert
+ console.log("inserting: " + data.title + " (Issueid: " + issueId + ")");
return insertSkippedIssues(issueId-1)
.then(function() {
return insertAndCloseIssue(issueId, data, isClosed(mantisIssue));
return Q();
}
- console.warn(("Skipping Missing Mantis Issue (<= #" + issueId + ") ...").yellow);
+ //console.warn(("Skipping Missing Mantis Issue (<= #" + issueId + ") ...").yellow);
+ console.log(("Adding placeholder ...").yellow);
var data = {
- title: "--Platzhalter--",
- description: "Fehlende Bugnummer in Mantis. Wird hier ausgelassen, damit die Bugnummern in Mantis mit denen in Gitlab uebereinstimmen.",
+ title: "-- Platzhalter --",
+ description: "Diese Bugnummer war in Mantis einem anderen Projekt zugeordnet. Dieser Platzhalter sorgt dafuer, dass die Bugnummern in Mantis mit denen in Gitlab uebereinstimmen.",
sudo: gitlabSudo,
private_token: gitlabAdminPrivateToken
};
- return insertAndCloseIssue(issueId, data, true, getSkippedIssueData)
+ return insertAndCloseIssue(issueId, data, true)
.then(function() {
return insertSkippedIssues(issueId);
});
-
- function getSkippedIssueData(gitLabIssue) {
- var issueId = gitLabIssue.iid;
- var description;
- if (config.mantisUrl) {
- description = "[Mantis Issue " + issueId + "](" + config.mantisUrl + "/view.php?id=" + issueId + ")";
- } else {
- description = "Mantis Issue " + issueId;
- }
- return {
- title: "Skipped Mantis Issue " + issueId,
- description: "_Skipped " + description + "_"
- };
- }
}
function insertAndCloseIssue(issueId, data, close, custom) {
if (close) {
return closeIssue(issue, custom && custom(issue)).then(
function() {
- console.log((issueId + ': Inserted and closed successfully. #' + issue.iid).green);
+ console.log((issue.iid + ': Inserted and closed successfully. #' + issue.iid).green);
}, function(error) {
- console.warn((issueId + ': Inserted successfully but failed to close. #' + issue.iid).yellow);
+ console.warn((issue.iid + ': Inserted successfully but failed to close. #' + issue.iid).yellow);
});
}
- console.log((issueId + ': Inserted successfully. #' + issue.iid).green);
+ console.log((issue.iid + ': Inserted successfully. #' + issue.iid).green);
}, function(error) {
- console.error((issueId + ': Failed to insert.').red, error);
+ console.error((issue.iid + ': Failed to insert.').red, error);
});
}
log_progress("Fetching Project Issues from GitLab [" + (from + 1) + "-" + (from + per_page) + "]...");
var url = gitlabAPIURLBase + '/projects/' + gitLab.project.id + "/issues";
var data = {
+ page: page,
+ per_page: per_page,
// FIXME: schnalke
- //page: page,
- //per_page: per_page,
//order_by: 'id',
private_token: gitlabAdminPrivateToken, sudo: gitlabSudo };
- return rest.get(url, {data: data}).then(function(issues) {
+ return rest.get(url, {data: data})
+ .fail(function(err) {
+ console.log(err);
+ })
+ .then(function(issues) {
if(issues.length < per_page) {
return issues;
}
attributes.push("Reported By: " + value);
}
+/*
if (value = row["Assigned To"]) {
attributes.push("Assigned To: " + value);
}
+*/
if (value = row.Created) {
attributes.push("Created: " + value);
}
description = description.replace(/\\n/g, "\n");
+ description = description.replace(/\\t/g, " ");
+ description = description.replace(/``/g, '"');
+ description = description.replace(/''/g, '"');
description = description.replace(/\n *----/g, "\n>>>");
});
}
-function updateIssue(projectId, issueId, data) {
- var url = gitlabAPIURLBase + '/projects/' + projectId + '/issues/' + issueId;
+function updateIssue(projectId, issueIId, data) {
+ var url = gitlabAPIURLBase + '/projects/' + projectId + '/issues/' + issueIId;
return rest.put(url, {data: data})
.then(null, function(error) {
}
function closeIssue(issue, custom) {
- var url = gitlabAPIURLBase + '/projects/' + issue.project_id + '/issues/' + issue.id;
+ var url = gitlabAPIURLBase + '/projects/' + issue.project_id + '/issues/' + issue.iid;
var data = _.extend({
state_event: 'close',
private_token: gitlabAdminPrivateToken,