diff --git a/python/LbNightlyTools/HTMLUtils.py b/python/LbNightlyTools/HTMLUtils.py index 30584d69e23335ba4721e3222670fee27486175f..656db79a459f8272f46f4964ee548835d99730a3 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