# Imports
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.template import loader
from .base import ErrorHandler
from .compat import Github
# Exports
__all__ = (
"GitHub",
)
# Classes
[docs]class GitHub(ErrorHandler):
required_settings = [
# "SUPERDJANGO_ERROR_CAPTURE_GITHUB_LOGIN",
"SUPERDJANGO_ERROR_CAPTURE_GITHUB_REPO",
"SUPERDJANGO_ERROR_CAPTURE_GITHUB_TOKEN",
]
[docs] def __init__(self):
"""Check for presence of PyGithub."""
if Github is None:
raise ImproperlyConfigured("The PyGithub package is required to use the GitHub backend: Use "
"pip install PyGithub")
super().__init__()
[docs] def handle(self, report):
"""Post an error to GitHub issues."""
body = self._parse_template("errors/github_body.txt")
title = self._parse_template("errors/github_title.txt")
github = Github(settings.SUPERDJANGO_ERROR_CAPTURE_GITHUB_TOKEN)
repo = github.get_repo(settings.SUPERDJANGO_ERROR_CAPTURE_GITHUB_REPO)
issue = repo.create_issue(body=body, title=title)
issue_url = "https://github.com/%s/issues#issue/" % settings.SUPERDJANGO_ERROR_CAPTURE_GITHUB_REPO
return {
'issue_url': issue_url + str(issue.id)
}