From 79604fc7dde7e76ddb80fab1af6f00f60b86ef89 Mon Sep 17 00:00:00 2001
From: Michael James Gratton <mike@vee.net>
Date: Mon, 16 Apr 2018 23:51:01 +1000
Subject: [PATCH] Look for imported Yorba bugs and clean up the first comment
 if found.

When Yorba moved their application hosting over to GNOME's
infrastructure for Geary, Shotwell, and other projects, the bug
import from their bug tracker produced buzilla bugs containing the
complete bug history in comment 0.

This looks for such import bugs, cleans up the text a bit to to make
it somewhat more readable, and replaces `#1`, `#2`, etc in the text
with `Comment 1`, `Comment 2`, etc so early gitlab issues don't get
spammed with huge numbers of mentions.
---
 bztogl/bztogl.py | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/bztogl/bztogl.py b/bztogl/bztogl.py
index 5bf410f..2ba2fab 100644
--- a/bztogl/bztogl.py
+++ b/bztogl/bztogl.py
@@ -110,6 +110,27 @@ def processbug(bgo, target, user_cache, bzbug):
 
         return '\n\n'.join(converted_paragraphs)
 
+    def is_yorba_import(comment):
+        body = comment['text']
+        is_yorba = (
+            'Original URL: http://redmine.yorba.org/issues/' in body and
+            'Searchable id: yorba-bug-' in body
+        )
+        if is_yorba:
+            body = re.sub(r'####\n\n#', '---\n\nComment ', body)
+            body = re.sub(
+                r'\n(Original [a-zA-Z ]+: [a-zA-Z0-9.:\/ ]+)', r'\n\1  ', body
+            )
+            body = re.sub(
+                r'\n(Searchable id: [a-zA-Z0-9-]+)', r'\n\1  ', body
+            )
+            body = re.sub(r'\n(related to [a-zA-Z]+ - )', r'\n * \1', body)
+            body = re.sub(r'\n(duplicated by [a-zA-Z]+ - )', r'\n * \1', body)
+            body = re.sub(r'\n(blocked by [a-zA-Z]+ - )', r'\n * \1', body)
+            comment['text'] = body
+
+        return is_yorba
+
     def analyze_bugzilla_comment(comment, attachment_metadata):
         body = comment['text']
 
@@ -156,8 +177,9 @@ def processbug(bgo, target, user_cache, bzbug):
     comments = bzbug.getcomments()
 
     firstcomment = None if len(comments) < 1 else comments[0]
+    is_yorba = is_yorba_import(firstcomment)
     desctext = None
-    if firstcomment['author'] == bzbug.creator:
+    if firstcomment['author'] == bzbug.creator or is_yorba:
         desctext = firstcomment['text']
         if 'attachment_id' in firstcomment:
             desctext += '\n' + migrate_attachment(firstcomment,
-- 
GitLab