From 5af89f71ef7547283dda069b93f644e02e7a40b4 Mon Sep 17 00:00:00 2001
From: Mohan Boddu <mboddu@bhujji.com>
Date: Mar 25 2020 19:18:59 +0000
Subject: [PATCH 1/2] Configurable /mnt/koji url to avoid prod vs stg


Signed-off-by: Mohan Boddu <mboddu@bhujji.com>

---

diff --git a/compose-tracker.toml b/compose-tracker.toml
index 759ffae..db0713d 100644
--- a/compose-tracker.toml
+++ b/compose-tracker.toml
@@ -41,6 +41,7 @@ routing_keys = ["org.fedoraproject.prod.pungi.compose.status.change"]
 [consumer_config]
 composes_to_skip = ["IoT"]
 ks_repo = "https://pagure.io/fedora-kickstarts"
+mnt_koji_url = 'https://kojipkgs.fedoraproject.org/'
 
 [qos]
 prefetch_size = 0
diff --git a/compose_tracker.py b/compose_tracker.py
index e89c960..2a86c8e 100755
--- a/compose_tracker.py
+++ b/compose_tracker.py
@@ -130,7 +130,7 @@ class Consumer(object):
             if r:
                 break
         if '/mnt/koji/' in line and 'See ' in line:
-            log_url = 'https://kojipkgs.fedoraproject.org/' + line.split('/mnt/koji/')[1].split()[0]
+            log_url = self.config["mnt_koji_url"] + line.split('/mnt/koji/')[1].split()[0]
             replace_log = '[' + line.split('See ')[1].split()[0] + '](' + log_url + ')'
             kojitaskline = line.replace(line.split('See ')[1].split()[0], replace_log)
         else:
diff --git a/test_consumer.py b/test_consumer.py
index 661c4cd..5123e9e 100644
--- a/test_consumer.py
+++ b/test_consumer.py
@@ -90,7 +90,7 @@ def test_consumer_settings_ignore_compose(mocker, caplog):
     mocker.patch("compose_tracker.requests")
     mocker.patch(
         "compose_tracker.fedora_messaging.config.conf",
-        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts"}},
+        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts", "mnt_koji_url": "https://kojipkgs.fedoraproject.org/"}},
     )
     con = Consumer()
     body = copy.copy(EXAMPLE_MESSAGE_BODY)
@@ -108,7 +108,7 @@ def test_consumer_settings_ignore_compose_2_values(mocker, caplog):
     mocker.patch("compose_tracker.requests")
     mocker.patch(
         "compose_tracker.fedora_messaging.config.conf",
-        {"consumer_config": {"composes_to_skip": ["IoT", "Rawhide"], "ks_repo": "https://pagure.io/fedora-kickstarts"}},
+        {"consumer_config": {"composes_to_skip": ["IoT", "Rawhide"], "ks_repo": "https://pagure.io/fedora-kickstarts", "mnt_koji_url": "https://kojipkgs.fedoraproject.org/"}},
     )
     con = Consumer()
     msg = fedora_messaging.api.Message(
@@ -173,7 +173,7 @@ def test_consumer_logfile_parsing_failures(mocker, caplog):
 
     mocker.patch(
         "compose_tracker.fedora_messaging.config.conf",
-        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts"}},
+        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts", "mnt_koji_url": "https://kojipkgs.fedoraproject.org/"}},
     )
     # mock the pungi.global.log file
     req = mocker.patch("compose_tracker.requests.get", autospec=True)
@@ -203,7 +203,7 @@ def test_adding_labels(mocker, caplog):
 
     mocker.patch(
         "compose_tracker.fedora_messaging.config.conf",
-        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts"}},
+        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts", "mnt_koji_url": "https://kojipkgs.fedoraproject.org/"}},
     )
     req = mocker.patch("compose_tracker.requests.get", autospec=True)
     text_mock = mocker.MagicMock()
@@ -231,7 +231,7 @@ def test_consumer_maintainer_pings(mocker, caplog):
 
     mocker.patch(
         "compose_tracker.fedora_messaging.config.conf",
-        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts"}},
+        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts", "mnt_koji_url": "https://kojipkgs.fedoraproject.org/"}},
     )
     # mock the pungi.global.log file
     req = mocker.patch("compose_tracker.requests.get", autospec=True)
@@ -262,7 +262,7 @@ def test_log_urls(mocker, caplog):
     
     mocker.patch(
         "compose_tracker.fedora_messaging.config.conf",
-        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts"}},
+        {"consumer_config": {"composes_to_skip": ["IoT"], "ks_repo": "https://pagure.io/fedora-kickstarts", "mnt_koji_url": "https://kojipkgs.fedoraproject.org/"}},
     )
     #mock the pungi.global.log file
     req = mocker.patch("compose_tracker.requests.get", autospec=True)

From 237db2aa8217310db7eeee9f218619969e2dd036 Mon Sep 17 00:00:00 2001
From: Mohan Boddu <mboddu@bhujji.com>
Date: Mar 30 2020 18:55:10 +0000
Subject: [PATCH 2/2] Adding links to logs (again)


Markdown code blocks doesn't support url linking, so we need to
find other alternatives.

Signed-off-by: Mohan Boddu <mboddu@bhujji.com>

---

diff --git a/compose_tracker.py b/compose_tracker.py
index 2a86c8e..8f2c609 100755
--- a/compose_tracker.py
+++ b/compose_tracker.py
@@ -131,7 +131,7 @@ class Consumer(object):
                 break
         if '/mnt/koji/' in line and 'See ' in line:
             log_url = self.config["mnt_koji_url"] + line.split('/mnt/koji/')[1].split()[0]
-            replace_log = '[' + line.split('See ')[1].split()[0] + '](' + log_url + ')'
+            replace_log = '<a href="' + log_url + '">' + line.split('See ')[1].split()[0] + '</a>'
             kojitaskline = line.replace(line.split('See ')[1].split()[0], replace_log)
         else:
             kojitaskline = line
@@ -272,7 +272,7 @@ class Consumer(object):
 
                 kojitaskline, text = self.get_supporting_text(lines[x-1:])
                 content+=f'{text}\n'
-                content+= "```\n%s\n%s\n```\n\n" % \
+                content+= "\n<pre>\n%s\n%s\n</pre>\n\n" % \
                                 (line, kojitaskline or nextline)
 
                 if self.config["ks_repo"]:
diff --git a/test_consumer.py b/test_consumer.py
index 5123e9e..169e36b 100644
--- a/test_consumer.py
+++ b/test_consumer.py
@@ -278,4 +278,4 @@ def test_log_urls(mocker, caplog):
         topic="org.fedoraproject.prod.pungi.compose.status.change", body=EXAMPLE_MESSAGE_BODY,
     )
     con.process(msg)
-    assert '[/mnt/koji/compose/rawhide/Fedora-Rawhide-20200204.n.0/logs/x86_64/Silverblue/ostree-1/runroot.log](https://kojipkgs.fedoraproject.org/compose/rawhide/Fedora-Rawhide-20200204.n.0/logs/x86_64/Silverblue/ostree-1/runroot.log)' in caplog.text
+    assert '<a href="https://kojipkgs.fedoraproject.org/compose/rawhide/Fedora-Rawhide-20200204.n.0/logs/x86_64/Silverblue/ostree-1/runroot.log">/mnt/koji/compose/rawhide/Fedora-Rawhide-20200204.n.0/logs/x86_64/Silverblue/ostree-1/runroot.log</a>' in caplog.text

