Cleanups
[mantis2gitlab] / m2gl.js
diff --git a/m2gl.js b/m2gl.js
index 53d9b5b..8f46ec2 100644 (file)
--- a/m2gl.js
+++ b/m2gl.js
@@ -231,7 +231,9 @@ function importIssue(mantisIssue) {
 
   return getIssue(gitLab.project.id, issueId)
       .then(function(gitLabIssue) {
-        if (gitLabIssue) {
+        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))
@@ -239,8 +241,8 @@ function importIssue(mantisIssue) {
                 console.log(("#" + gitLabIssue.iid + ": Updated successfully.").green);
               });
         } else {
-          console.log(data.title);
-          //return true; // FIXME
+          // insert
+          console.log("inserting: " + data.title + " (Issueid: " + issueId + ")");
           return insertSkippedIssues(issueId-1)
               .then(function() {
                 return insertAndCloseIssue(issueId, data, isClosed(mantisIssue));
@@ -254,34 +256,19 @@ function insertSkippedIssues(issueId) {
     return Q();
   }
 
-  //FIXME console.warn(("Skipping Missing Mantis Issue (<= #" + issueId + ") ...").yellow);
-  console.log(("Adding" + issueId + ") ...").blue);
+  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) {
@@ -291,15 +278,15 @@ 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);
   });
 }
 
@@ -327,12 +314,9 @@ function getRemainingGitLabProjectIssues(page, per_page) {
   var data = {
     page: page,
     per_page: per_page,
-    // FIXME: schnalke
-    //order_by: 'id',
     private_token: gitlabAdminPrivateToken, sudo: gitlabSudo };
 
   return rest.get(url, {data: data})
-  return rest.get(url, {data: data})
   .fail(function(err) {
     console.log(err);
   })
@@ -367,9 +351,11 @@ function getDescription(row) {
     attributes.push("Reported By: " + value);
   }
 
+/* omit ...
   if (value = row["Assigned To"]) {
     attributes.push("Assigned To: " + value);
   }
+*/
 
   if (value = row.Created) {
     attributes.push("Created: " + value);
@@ -392,11 +378,11 @@ function getDescription(row) {
   }
 
   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>>>");
 
-  //description = description.replace(/schnalke/g, "@MSchnalke");
-
   Object.keys(config.users).forEach(function(muser) {
     if (muser != "") {
         var gluser = config.users[muser].gl_username;