[GRASS-SVN] r73433 - grass-addons/tools/svn2git

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 26 15:00:45 PDT 2018


Author: martinl
Date: 2018-09-26 15:00:45 -0700 (Wed, 26 Sep 2018)
New Revision: 73433

Modified:
   grass-addons/tools/svn2git/rewrite.py
Log:
svn2git: rewrite - comment unused part, check of trac ticket really exists (work in progress)

Modified: grass-addons/tools/svn2git/rewrite.py
===================================================================
--- grass-addons/tools/svn2git/rewrite.py	2018-09-26 21:53:28 UTC (rev 73432)
+++ grass-addons/tools/svn2git/rewrite.py	2018-09-26 22:00:45 UTC (rev 73433)
@@ -1,61 +1,62 @@
 # Taken from https://lists.osgeo.org/pipermail/gdal-dev/2018-March/048246.html
 
 import sys
+import requests
 msg = sys.stdin.read()
 
 # Don't touch messages that reference other databases
-if msg.find('MITAB bug ') >= 0 or msg.find('Safe bug ') >= 0 or msg.find('bugzilla') >= 0 or msg.find('Bugzilla') >= 0:
-    sys.stdout.write(msg)
-    sys.exit(0)
+# if msg.find('MITAB bug ') >= 0 or msg.find('Safe bug ') >= 0 or msg.find('bugzilla') >= 0 or msg.find('Bugzilla') >= 0:
+#     sys.stdout.write(msg)
+#     sys.exit(0)
 
 oldpos = 0
 old_msg = msg
 while True:
 
-    # We already have reference to github pull requests written like
-    # 'github #1234', so skip them
-    newpos = msg.find('github #', oldpos)
-    if newpos >= 0:
-        oldpos = newpos + len('github #')
-        continue
+    # # We already have reference to github pull requests written like
+    # # 'github #1234', so skip them
+    # newpos = msg.find('github #', oldpos)
+    # if newpos >= 0:
+    #     oldpos = newpos + len('github #')
+    #     continue
 
-    # Exception...
-    newpos = msg.find('patch #1 ', oldpos)
-    if newpos >= 0:
-        oldpos = newpos + len('patch #1 ')
-        continue
+    # # Exception...
+    # newpos = msg.find('patch #1 ', oldpos)
+    # if newpos >= 0:
+    #     oldpos = newpos + len('patch #1 ')
+    #     continue
 
-    # Exception...
-    newpos = msg.find('bug 1 ', oldpos)
-    if newpos >= 0:
-        oldpos = newpos + len('bug 1 ')
-        continue
+    # # Exception...
+    # newpos = msg.find('bug 1 ', oldpos)
+    # if newpos >= 0:
+    #     oldpos = newpos + len('bug 1 ')
+    #     continue
 
-    # Fix 'bug 1234'
-    newpos = msg.find('bug ', oldpos)
-    if newpos >= 0:
-        if newpos == len(msg) - 4:
-            break
-        if not(msg[newpos+4] >= '1' and msg[newpos+4] <= '9'):
-            oldpos = newpos + 4
-            continue
+    # # Fix 'bug 1234'
+    # newpos = msg.find('bug ', oldpos)
+    # if newpos >= 0:
+    #     if newpos == len(msg) - 4:
+    #         break
+    #     if not(msg[newpos+4] >= '1' and msg[newpos+4] <= '9'):
+    #         oldpos = newpos + 4
+    #         continue
 
-        msg = msg[0:newpos] + 'https://trac.osgeo.org/grass/ticket/' + msg[newpos+4:]
-        oldpos = newpos
-        continue
+    #     msg = msg[0:newpos] + 'https://trac.osgeo.org/grass/ticket/' + msg[newpos+4:]
+    #     oldpos = newpos
+    #     continue
 
-    # Fix 'ticket 1234'
-    newpos = msg.find('ticket ', oldpos)
-    if newpos >= 0:
-        if newpos == len(msg) - 7:
-            break
-        if not(msg[newpos+7] >= '1' and msg[newpos+7] <= '9'):
-            oldpos = newpos + 7
-            continue
+    # # Fix 'ticket 1234'
+    # newpos = msg.find('ticket ', oldpos)
+    # if newpos >= 0:
+    #     if newpos == len(msg) - 7:
+    #         break
+    #     if not(msg[newpos+7] >= '1' and msg[newpos+7] <= '9'):
+    #         oldpos = newpos + 7
+    #         continue
 
-        msg = msg[0:newpos] + 'https://trac.osgeo.org/grass/ticket/' + msg[newpos+7:]
-        oldpos = newpos
-        continue
+    #     msg = msg[0:newpos] + 'https://trac.osgeo.org/grass/ticket/' + msg[newpos+7:]
+    #     oldpos = newpos
+    #     continue
 
     # Fix '#1234'
     newpos = msg.find('#', oldpos)
@@ -72,7 +73,15 @@
             oldpos = newpos + 1
             continue
 
-        msg = msg[0:newpos] + 'https://trac.osgeo.org/grass/ticket/' + msg[newpos+1:]
+        # check if ticket really exists
+        url = 'https://trac.osgeo.org/grass/ticket/' + msg[newpos+1:]
+        request = requests.get(url)
+        if request.status_code != 200:
+            # does not exist
+            oldpos = newpos + len(msg[newpos+1:])
+            continue
+
+        msg = msg[0:newpos] + url
         oldpos = newpos
         continue
 
@@ -79,8 +88,7 @@
     break
 
 if msg != old_msg:
-    f = open('/tmp/log.txt', 'a')
-    f.write('Old message was:\n' + old_msg + 'New message is:\n' + msg + '\n')
-    f.close()
+    with open('/tmp/log.txt', 'a') as f:
+        f.write('Old message was:\n' + old_msg + 'New message is:\n' + msg + '\n')
 
 sys.stdout.write(msg)



More information about the grass-commit mailing list