From 315d4494603b02252966770452e676fd63a67021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Csord=C3=A1s?= Date: Thu, 14 Oct 2021 14:01:52 +0200 Subject: [PATCH] [server] Fix getting git commit url It is possible that a git commit url regex contains a group, which is optional, so the value can be None. In this case when replacing the group name with the value in the url will fail, because None can't be used in replace. For this reason if the value is None, we will skip it from the replacement. --- web/server/codechecker_server/api/report_server.py | 3 ++- web/server/tests/unit/test_git_commit_url.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/web/server/codechecker_server/api/report_server.py b/web/server/codechecker_server/api/report_server.py index 2dbd57aa49..12430ff928 100644 --- a/web/server/codechecker_server/api/report_server.py +++ b/web/server/codechecker_server/api/report_server.py @@ -978,7 +978,8 @@ def get_commit_url( if m: url = git_commit_url["url"] for key, value in m.groupdict().items(): - url = url.replace(f"${key}", value) + if value is not None: + url = url.replace(f"${key}", value) return url diff --git a/web/server/tests/unit/test_git_commit_url.py b/web/server/tests/unit/test_git_commit_url.py index a702097e55..7f923cb94d 100644 --- a/web/server/tests/unit/test_git_commit_url.py +++ b/web/server/tests/unit/test_git_commit_url.py @@ -40,6 +40,13 @@ def test_gerrit_url(self): 'https://user@gerrit.ericsson.se/a/team/proj.git', self.__git_commit_urls)) + self.assertEqual( + "https://gerrit.ericsson.se/" + "gitweb?p=team/proj.git;a=commit;h=$commit", + get_commit_url( + 'https://gerrit.ericsson.se/a/team/proj.git', + self.__git_commit_urls)) + def test_bitbucket_url(self): """ Get commit url for a bitbucket repository. """ self.assertEqual(