Skip to content

Commit

Permalink
[API] New method Bug.details(). Refs #117
Browse files Browse the repository at this point in the history
this method together with the underlying IssueTracker.details()
will be the foundation of how Kiwi TCMS fetches more details from
the bug tracking system.

At the moment the intention is for this information to be shown in
the UI but it can also be consumed independently via the API.

By default we're using OpenGraph protocol to collect the data that
will be shown. The details() method can be overriden for each bug
tracker that is supported and you may also override the entire class
with something you have created yourself.
  • Loading branch information
atodorov committed Aug 28, 2019
1 parent 64357bd commit 7dccb9a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions tcms/issuetracker/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions tcms/xmlrpc/api/bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 7dccb9a

Please sign in to comment.