Repository: readthedocs/readthedocs.org

Issue:
Link to open an issue from a failed Build with pre-filled details
There are several issues that are reported where there are missing information in the details section.

To solve this I was thinking on generating a link inside this message that could contain all the information pre-filled:

![captura de pantalla_2018-01-22_15-07-15](https://user-images.githubusercontent.com/244656/35242041-6ed4e288-ff86-11e7-9b89-c69a45505318.png)


I found that github supports _some_ query arguments in the URL but I didn't found a way to use those key/args inside the template itself.

https://help.github.com/articles/about-automation-for-issues-and-pull-requests-with-query-parameters/

I think it would be awesome if the user can just click a link and the username, project url, etc could be pre-filled automatically.


Discussion:
Could you not have the link generated with that information in the body tag? 
Yeah, _maybe_.

The template is 227 chars long, if we add the project and build link plus username I'm not sure if we are not creating a too long URL that it's not standard. I know there is a limit and I think it depends on the browser also...

https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers

We could do that since the limit is around 2000 chars.
Neat idea. We need to make sure wouldn't show on the .com though, as we don't want github issues for those issues.
What about putting this information on the header of the raw build log (see #3585)? So the user can just referrer that link or copy/paste the raw log on the issue.
Hi @humitos, May I work on this!
@bansalnitish It doesn't look like @humitos has opened a PR for this; he's only specified a need for it. I'd say go ahead! :) 
Thanks @RichardLitt!
Hi @humitos, Can you please help me in reproducing this issue!
@bansalnitish hey! What you need?

The idea is to add a link in the build page (showed when it fails) that opens an issue in this Github project.

(there is a link to the GH docs to generate that link in the description)
I got it @humitos, Thanks! I will be soon submitting a PR for the same!

Resolving patch:
diff --git a/readthedocs/builds/views.py b/readthedocs/builds/views.py
--- 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
 
 


Test patch: