Skip to content

Commit

Permalink
Merge pull request #3683 from bansalnitish/preFilledIssue
Browse files Browse the repository at this point in the history
Added a link to open new issue with prefilled details
  • Loading branch information
ericholscher authored Jan 22, 2019
2 parents 4ee4f61 + 3ebcf90 commit 3b7ff83
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
47 changes: 47 additions & 0 deletions readthedocs/builds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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


Expand Down
9 changes: 9 additions & 0 deletions readthedocs/templates/builds/build_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ <h3>{% trans "Error" %}</h3>
data-bind="text: error">
{{ build.error }}
</p>
<p>
{% block github_issue_link %}
{% if issue_url %}
{% blocktrans trimmed with url=issue_url %}
<a href="{{ url }}">Report any build issues here</a>.
{% endblocktrans %}
{% endif %}
{% endblock %}
</p>
</div>

<div id="build-commands"
Expand Down

0 comments on commit 3b7ff83

Please sign in to comment.