Code Duplication    Length = 44-58 lines in 2 locations

tcms/issuetracker/types.py 2 locations

@@ 281-338 (lines=58) @@
278
        return url + '/secure/CreateIssueDetails!init.jspa?' + urlencode(args, True)
279
280
281
class GitHub(IssueTrackerType):
282
    """
283
        Support for GitHub. Requires:
284
285
        :base_url: - URL to a GitHub repository for which we're going to report issues
286
        :api_password: - GitHub API token.
287
288
        .. note::
289
290
            You can leave the ``api_url`` and ``api_username`` fields blank because
291
            the integration code doesn't use them!
292
293
        .. note::
294
295
            GitHub does not support displaying multiple issues in a table format like
296
            Bugzilla and JIRA do. This means that in Test Execution Report view you will
297
            see GitHub issues listed one by one and there will not be a link to open all
298
            of them inside GitHub's interface!
299
    """
300
301
    def __init__(self, tracker):
302
        super(GitHub, self).__init__(tracker)
303
304
        # NOTE: we use an access token so only the password field is required
305
        self.rpc = github.Github(self.tracker.api_password)
306
307
    def add_testcase_to_issue(self, testcases, issue):
308
        for case in testcases:
309
            github_integration.GitHubThread(self.rpc, self.tracker, case, issue).start()
310
311
    def is_adding_testcase_to_issue_disabled(self):
312
        return not (self.tracker.base_url and self.tracker.api_password)
313
314
    def report_issue_from_testcase(self, caserun):
315
        """
316
            GitHub only supports title and body parameters
317
        """
318
        args = {
319
            'title': 'Failed test: %s' % caserun.case.summary,
320
        }
321
322
        txt = caserun.case.get_text_with_version(case_text_version=caserun.case_text_version)
323
324
        comment = "Filed from caserun %s\n\n" % caserun.get_full_url()
325
        comment += "Product:\n%s\n\n" % caserun.run.plan.product.name
326
        comment += "Component(s):\n%s\n\n" % caserun.case.component.values_list('name', flat=True)
327
        comment += "Version-Release number of selected " \
328
                   "component (if applicable):\n"
329
        comment += "%s\n\n" % caserun.build.name
330
        comment += "Steps to Reproduce: \n%s\n\n" % txt
331
        comment += "Actual results: \n<describe what happened>\n\n"
332
        args['body'] = comment
333
334
        url = self.tracker.base_url
335
        if not url.endswith('/'):
336
            url += '/'
337
338
        return url + '/issues/new?' + urlencode(args, True)
339
340
341
class Gitlab(IssueTrackerType):
@@ 341-384 (lines=44) @@
338
        return url + '/issues/new?' + urlencode(args, True)
339
340
341
class Gitlab(IssueTrackerType):
342
    """
343
        Support for Gitlab. Requires:
344
345
        :base_url: - URL to a Gitlab repository for which we're going to report issues
346
        :api_password: - Gitlab API token.
347
    """
348
349
    def __init__(self, tracker):
350
        super(Gitlab, self).__init__(tracker)
351
352
        # we use an access token so only the password field is required
353
        self.rpc = gitlab.Gitlab(self.tracker.api_url, private_token=self.tracker.api_password)
354
355
    def add_testcase_to_issue(self, testcases, issue):
356
        for case in testcases:
357
            gitlab_integration.GitlabThread(self.rpc, self.tracker, case, issue).start()
358
359
    def is_adding_testcase_to_issue_disabled(self):
360
        return not (self.tracker.base_url and self.tracker.api_password)
361
362
    def report_issue_from_testcase(self, caserun):
363
        args = {
364
            'issue[title]': 'Failed test: %s' % caserun.case.summary,
365
        }
366
367
        txt = caserun.case.get_text_with_version(case_text_version=caserun.case_text_version)
368
369
        comment = "Filed from caserun %s\n\n" % caserun.get_full_url()
370
        comment += "**Product**:\n%s\n\n" % caserun.run.plan.product.name
371
        comment += "**Component(s)**:\n%s\n\n"\
372
                   % caserun.case.component.values_list('name', flat=True)
373
        comment += "Version-Release number of selected " \
374
                   "component (if applicable):\n"
375
        comment += "%s\n\n" % caserun.build.name
376
        comment += "**Steps to Reproduce**: \n%s\n\n" % txt
377
        comment += "**Actual results**: \n<describe what happened>\n\n"
378
        args['issue[description]'] = comment
379
380
        url = self.tracker.base_url
381
        if not url.endswith('/'):
382
            url += '/'
383
384
        return url + '/issues/new?' + urlencode(args, True)
385
386
387
class LinkOnly(IssueTrackerType):