diff --git a/readthedocs/builds/views.py b/readthedocs/builds/views.py index e86a673dc27..dfdee2abf97 100644 --- a/readthedocs/builds/views.py +++ b/readthedocs/builds/views.py @@ -3,6 +3,7 @@ """Views for builds app.""" import logging +import textwrap from django.contrib import messages from django.contrib.auth.decorators import login_required @@ -15,7 +16,10 @@ from django.urls import reverse from django.utils.decorators import method_decorator from django.views.generic import DetailView, ListView +from requests.utils import quote +from urllib.parse import urlparse +from readthedocs.doc_builder.exceptions import BuildEnvironmentError from readthedocs.builds.models import Build, Version from readthedocs.core.permissions import AdminPermission from readthedocs.core.utils import trigger_build @@ -104,6 +108,49 @@ class BuildDetail(BuildBase, DetailView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['project'] = self.project + + build = self.get_object() + if build.error != BuildEnvironmentError.GENERIC_WITH_BUILD_ID.format(build_id=build.pk): + # Do not suggest to open an issue if the error is not generic + return context + + scheme = ( + 'https://github.com/rtfd/readthedocs.org/issues/new' + '?title={title}{build_id}' + '&body={body}' + ) + + # TODO: we could use ``.github/ISSUE_TEMPLATE.md`` here, but we would + # need to add some variables to it which could impact in the UX when + # filling an issue from the web + body = """ + ## Details: + + * Project URL: https://readthedocs.org/projects/{project_slug}/ + * Build URL(if applicable): https://readthedocs.org{build_path} + * Read the Docs username(if applicable): {username} + + ## Expected Result + + *A description of what you wanted to happen* + + ## Actual Result + + *A description of what actually happened*""".format( + project_slug=self.project, + build_path=self.request.path, + username=self.request.user, + ) + + scheme_dict = { + 'title': quote('Build error with build id #'), + 'build_id': context['build'].id, + 'body': quote(textwrap.dedent(body)), + } + + issue_url = scheme.format(**scheme_dict) + issue_url = urlparse(issue_url).geturl() + context['issue_url'] = issue_url return context diff --git a/readthedocs/templates/builds/build_detail.html b/readthedocs/templates/builds/build_detail.html index 4aa528eaba0..09cd888923f 100644 --- a/readthedocs/templates/builds/build_detail.html +++ b/readthedocs/templates/builds/build_detail.html @@ -177,6 +177,15 @@

{% trans "Error" %}

data-bind="text: error"> {{ build.error }}

+

+ {% block github_issue_link %} + {% if issue_url %} + {% blocktrans trimmed with url=issue_url %} + Report any build issues here. + {% endblocktrans %} + {% endif %} + {% endblock %} +