diff --git a/requirements/base.txt b/requirements/base.txt index 196b6607d1..6adf0340e0 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -9,3 +9,4 @@ django-simple-history==2.7.3 jira==2.0.0 Markdown==3.1.1 python-redmine==2.2.1 +topicaxis-opengraph==0.5 diff --git a/tcms/issuetracker/types.py b/tcms/issuetracker/types.py index 3f6fafe53c..9bac1f9b20 100644 --- a/tcms/issuetracker/types.py +++ b/tcms/issuetracker/types.py @@ -17,6 +17,7 @@ import redminelib from django.conf import settings +from opengraph.opengraph import OpenGraph from tcms.issuetracker import bugzilla_integration from tcms.issuetracker import jira_integration @@ -63,6 +64,21 @@ def bug_id_from_url(cls, url): """ return int(RE_ENDS_IN_INT.search(url.strip()).group(0)) + def details(self, url): + """ + Returns bug details to be used later. By default this method + returns OpenGraph metadata (dict) which is shown in the UI as tooltips. + You can override this method to provide different information. + """ + result = OpenGraph(url, scrape=True) + + # remove data which we don't need + for key in ['_url', 'url', 'scrape', 'type']: + if key in result: + del result[key] + + return result + def _report_comment(self, execution): # pylint: disable=no-self-use """ Returns the comment which is used in the original defect report. diff --git a/tcms/xmlrpc/api/bug.py b/tcms/xmlrpc/api/bug.py index 17e7ea5a7b..1293eb85e1 100644 --- a/tcms/xmlrpc/api/bug.py +++ b/tcms/xmlrpc/api/bug.py @@ -6,13 +6,33 @@ from tcms.testcases.models import BugSystem from tcms.testruns.models import TestExecution from tcms.issuetracker.types import IssueTrackerType +from tcms.xmlrpc.api.utils import tracker_from_url __all__ = ( + 'details', 'report', ) +@rpc_method(name='Bug.details') +def details(url): + """ + .. function:: XML-RPC Bug.details(url) + + Returns details about bug at the given URL address. This method is + used when generating additional information which is shown in the UI. + + :param url: URL address + :type url: str + :return: Detailed information about this URL. Depends on the underlying + issue tracker. + :rtype: dict + """ + tracker = tracker_from_url(url) + return tracker.details(url) + + @rpc_method(name='Bug.report') def report(execution_id, tracker_id): """