From 53237b7ad7088ff828c012eec19633ed6d063940 Mon Sep 17 00:00:00 2001
From: Marco Clemencic <marco.clemencic@cern.ch>
Date: Fri, 22 Feb 2019 09:58:43 +0100
Subject: [PATCH] Fix corner case in checkout log enhancement

---
 python/LbNightlyTools/HTMLUtils.py | 32 ++++++++++++++++++------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/python/LbNightlyTools/HTMLUtils.py b/python/LbNightlyTools/HTMLUtils.py
index 30584d69..656db79a 100644
--- a/python/LbNightlyTools/HTMLUtils.py
+++ b/python/LbNightlyTools/HTMLUtils.py
@@ -438,19 +438,25 @@ class AddGitlabLinks(object):
             re.sub function to add links to MRs
             '''
             from LbNightlyTools.Utils import getMRTitle
-            title = getMRTitle(matchobj.group(1), int(matchobj.group(2)))
-            if title:
-                title = cgi.escape(title, quote=True)
-                if not isinstance(title, unicode):
-                    title = title.decode('utf-8', 'replace')
-                return (u'<a href="https://gitlab.cern.ch/{0}/'
-                        u'merge_requests/{1}" data-toggle="tooltip" '
-                        u'title="{title}" target="_blank">{0}!{1}</a>'
-                        ).format(*matchobj.groups(), title=title)
-            else:
-                return (u'<a href="https://gitlab.cern.ch/{0}/'
-                        u'merge_requests/{1}" target="_blank">{0}!{1}</a>'
-                        ).format(*matchobj.groups())
+            from gitlab import GitlabGetError
+            try:
+                title = getMRTitle(matchobj.group(1), int(matchobj.group(2)))
+                if title:
+                    title = cgi.escape(title, quote=True)
+                    if not isinstance(title, unicode):
+                        title = title.decode('utf-8', 'replace')
+                    return (u'<a href="https://gitlab.cern.ch/{0}/'
+                            u'merge_requests/{1}" data-toggle="tooltip" '
+                            u'title="{title}" target="_blank">{0}!{1}</a>'
+                            ).format(*matchobj.groups(), title=title)
+                else:
+                    return (u'<a href="https://gitlab.cern.ch/{0}/'
+                            u'merge_requests/{1}" target="_blank">{0}!{1}</a>'
+                            ).format(*matchobj.groups())
+            except GitlabGetError:
+                # the group/project!id match is invalid (e.g. no project found)
+                # do not replace
+                return matchobj.group(0)
 
         self._mr_link_repl = mr_link_repl
 
-- 
GitLab