Switch to API v4; plus additional stuff
authormarkus schnalke <meillo@marmaro.de>
Wed, 13 Feb 2019 12:07:00 +0000 (13:07 +0100)
committermarkus schnalke <meillo@marmaro.de>
Sun, 2 Jan 2022 09:35:48 +0000 (10:35 +0100)
m2gl.js [changed mode: 0755->0644]

diff --git a/m2gl.js b/m2gl.js
old mode 100755 (executable)
new mode 100644 (file)
index 67c0a3b..5211b8f
--- a/m2gl.js
+++ b/m2gl.js
@@ -29,7 +29,7 @@ var argv = require('optimist')
 var inputFile = __dirname + '/' + argv.input;
 var configFile = __dirname + '/' + argv.config;
 var fromIssueId = Number(argv.from||0);
-var gitlabAPIURLBase = argv.gitlaburl + '/api/v3';
+var gitlabAPIURLBase = argv.gitlaburl + '/api/v4';
 var gitlabProjectName = argv.project;
 var gitlabAdminPrivateToken = argv.token;
 var gitlabSudo = argv.sudo;
@@ -38,6 +38,7 @@ var config = {};
 var gitLab = {};
 var promise = getConfig()
         .then(readMantisIssues)
+        .then((JSON.stringify(gitLab.mantisIssues)))
         .then(getGitLabProject)
         .then(getGitLabProjectMembers)
         .then(mapGitLabUserIds)
@@ -83,7 +84,7 @@ function readMantisIssues() {
     var rows = [];
     var dfd = Q.defer();
 
-    csv().from(data, {delimiter: ',', escape: '"', columns: true})
+    csv().from(data, {delimiter: '\t', quote: '~', escape: '~', columns: true})
         .on('record', function(row, index) { rows.push(row) })
         .on('end', function(error, data) {
           dfd.resolve(rows);
@@ -227,7 +228,7 @@ function importIssue(mantisIssue) {
   return getIssue(gitLab.project.id, issueId)
       .then(function(gitLabIssue) {
         if (gitLabIssue) {
-          return updateIssue(gitLab.project.id, gitLabIssue.id, _.extend({
+          return updateIssue(gitLab.project.id, issueId, _.extend({
             state_event: isClosed(mantisIssue) ? 'close' : 'reopen'
           }, data))
               .then(function() {
@@ -243,14 +244,15 @@ function importIssue(mantisIssue) {
 }
 
 function insertSkippedIssues(issueId) {
-  if (gitLab.gitlabIssues[issueId]) {
+  if (issueId < 1 || gitLab.gitlabIssues[issueId]) {
     return Q();
   }
 
   console.warn(("Skipping Missing Mantis Issue (<= #" + issueId + ") ...").yellow);
 
   var data = {
-    title: "Skipped Mantis Issue",
+    title: "--Platzhalter--",
+    description: "Fehlende Bugnummer in Mantis. Wird hier ausgelassen, damit die Bugnummern in Mantis mit denen in Gitlab uebereinstimmen.",
     sudo: gitlabSudo,
     private_token: gitlabAdminPrivateToken
   };
@@ -316,9 +318,10 @@ function getRemainingGitLabProjectIssues(page, per_page) {
   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,
-    order_by: 'id',
+    // 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) {
@@ -376,6 +379,20 @@ function getDescription(row) {
     description += "\n\n" + value.split("$$$$").join("\n\n")
   }
 
+  description = description.replace(/\\n/g, "\n");
+
+  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;
+        var re = new RegExp(muser, "g");
+        description = description.replace(re, "@" + gluser);
+    }
+  });
+
   return description;
 }
 
@@ -453,4 +470,4 @@ function closeIssue(issue, custom) {
 
 function log_progress(message) {
   console.log(message.grey);
-}
\ No newline at end of file
+}