Skip to content

Commit

Permalink
feature: 1-click bug report for Gitlab. Refs #479
Browse files Browse the repository at this point in the history
Gitlab needs only title & description to open a new issue so we
do this automatically and also add the LinkReference to the TE
itself. UI still needs to be refreshed to reflect the new issue!
  • Loading branch information
atodorov committed May 22, 2020
1 parent ecc1bd6 commit d722607
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
26 changes: 22 additions & 4 deletions tcms/issuetracker/tests/test_gitlab_ee.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
import unittest

from tcms.core.contrib.linkreference.models import LinkReference
from tcms.issuetracker.types import Gitlab
from tcms.rpc.tests.utils import APITestCase
from tcms.testcases.models import BugSystem
Expand Down Expand Up @@ -90,13 +91,30 @@ def test_auto_update_bugtracker(self):
"TE-%d: %s" % (self.execution_1.pk, self.execution_1.case.summary)]:
self.assertIn(expected_string, last_comment.body)

def test_report_issue_from_test_execution_falls_back_to_query_params(self):
def test_report_issue_from_test_execution_1click_works(self):
# simulate user clicking the 'Report bug' button in TE widget, TR page
result = self.rpc_client.Bug.report(self.execution_1.pk, self.integration.bug_system.pk)
self.assertEqual(result['rc'], 0)
self.assertIn(self.integration.bug_system.base_url, result['response'])
self.assertIn('issues/new', result['response'])
self.assertIn('/-/issues/', result['response'])

# assert that the result looks like valid URL parameters
self.assertIn('?issue%5Btitle%5D=Failed+test', result['response'])
self.assertIn('&issue%5Bdescription%5D=Filed+from+execution', result['response'])
new_issue_id = self.integration.bug_id_from_url(result['response'])
gl_project = self.integration.rpc.projects.get(self.integration.repo_slug())
issue = gl_project.issues.get(new_issue_id)

self.assertEqual("Failed test: %s" % self.execution_1.case.summary, issue.title)
for expected_string in [
"Filed from execution %s" % self.execution_1.get_full_url(),
self.execution_1.run.plan.product.name,
self.execution_1.case.component.name,
"Steps to reproduce",
self.execution_1.case.text]:
self.assertIn(expected_string, issue.description)

# verify that LR has been added to TE
self.assertTrue(LinkReference.objects.filter(
execution=self.execution_1,
url=result['response'],
is_defect=True,
).exists())
23 changes: 13 additions & 10 deletions tcms/issuetracker/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,19 @@ def is_adding_testcase_to_issue_disabled(self):
return not (self.bug_system.api_url and self.bug_system.api_password)

def report_issue_from_testexecution(self, execution, user):
args = {
'issue[title]': 'Failed test: %s' % execution.case.summary,
'issue[description]': self._report_comment(execution),
}

url = self.bug_system.base_url
if not url.endswith('/'):
url += '/'

return url + '/issues/new?' + urlencode(args, True)
project = self.rpc.projects.get(self.repo_slug())
new_issue = project.issues.create({
'title': 'Failed test: %s' % execution.case.summary,
'description': self._report_comment(execution),
})

# and also add a link reference that will be shown in the UI
LinkReference.objects.get_or_create(
execution=execution,
url=new_issue.attributes['web_url'],
is_defect=True,
)
return new_issue.attributes['web_url']


class Redmine(IssueTrackerType):
Expand Down

0 comments on commit d722607

Please sign in to comment.