From bdefccabdab886018f21a58a6890c8477380b0a2 Mon Sep 17 00:00:00 2001 From: Alexander Todorov Date: Mon, 28 Aug 2023 14:37:24 +0300 Subject: [PATCH] Break out a helper function --- tcms/issuetracker/base.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tcms/issuetracker/base.py b/tcms/issuetracker/base.py index 9aef02487d..58ec605353 100644 --- a/tcms/issuetracker/base.py +++ b/tcms/issuetracker/base.py @@ -6,6 +6,18 @@ RE_ENDS_IN_INT = re.compile(r"[\d]+$") +def _function_from_path(fully_qualified_dotted_path): + """ + Helper function which returns a callable object from a + fully qualified dotted path string! + """ + function_name = fully_qualified_dotted_path.split(".")[-1] + module_name = fully_qualified_dotted_path.replace(f".{function_name}", "") + + module_object = import_module(module_name) + function_object = getattr(module_object, function_name) + return function_object + class IssueTrackerType: """ @@ -136,11 +148,7 @@ def post_process_new_issue(self, new_issue, execution, user): .. versionadded:: 11.4 """ for fully_qualified_dotted_path in settings.EXTERNAL_ISSUE_POST_PROCESSORS: - function_name = fully_qualified_dotted_path.split(".")[-1] - module_name = fully_qualified_dotted_path.replace(f".{function_name}", "") - - processor_module = import_module(module_name) - processor_function = getattr(processor_module, function_name) + processor_function = _function_from_path(fully_qualified_dotted_path) processor_function(self.rpc, new_issue, execution, user) def add_testexecution_to_issue(self, executions, issue_url):