Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Imports
3from django.conf import settings
4from django.core.exceptions import ImproperlyConfigured
5from django.template import loader
6from .base import ErrorHandler
7from .compat import BitbucketClient
9# Exports
11__all__ = (
12 "Bitbucket",
13)
15# Classes
18class Bitbucket(ErrorHandler):
20 required_settings = [
21 "SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_EMAIL",
22 "SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_OWNER",
23 "SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_PASSWORD",
24 "SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_REPO",
25 ]
27 def __init__(self):
28 """Check for presence of bitbucket-python."""
29 if BitbucketClient is None:
30 raise ImproperlyConfigured("The Bitbucket package is required to use the Bitbucket backend: Use "
31 "pip install bitbucket-python")
33 super().__init__()
35 def handle(self, report):
36 """Post an error to Bitbucket issues."""
37 body = self._parse_template("errors/bitbucket_body.txt")
38 title = self._parse_template("errors/bitbucket_title.txt")
40 client = BitbucketClient(
41 settings.SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_EMAIL,
42 settings.SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_PASSWORD,
43 settings.SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_OWNER
44 )
46 # https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/
47 # %7Bworkspace%7D/%7Brepo_slug%7D/issues/%7Bissue_id%7D
49 # TODO: No idea if this is the data expected by bitbucket API to create an issue.
50 data = {
51 'description': body,
52 'title': title,
53 }
54 response = client.create_issue(settings.SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_REPO, data)
56 # TODO: No idea if this is how to acquire the ID or the URL is correct. What about jira issues?
57 issue_id = response['id']
58 issue_url = "https://bitbucket.org/%s/%s/issues/%s/" % (
59 settings.SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_OWNER,
60 settings.SUPERDJANGO_ERROR_CAPTURE_BITBUCKET_REPO,
61 issue_id
62 )
64 return {
65 'issue_url': issue_url
66 }