internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: readthedocs/readthedocs.org

Issue:
Adopting a projected as gold user fails
### How to reproduce it

1. sign up as Gold member
1. go to https://readthedocs.org/accounts/gold/subscription/
1. select the project that you want to adopt

### Expected Result

Adopts the project.

###  Actual Result

Fails with a 500.

https://sentry.io/read-the-docs/readthedocs-org/issues/587668658/

### The problem

This line

https://github.com/rtfd/readthedocs.org/blob/44e02def230b937e4eca396864de9fc81f4ef33f/readthedocs/gold/views.py#L109

cause the problem since we are receiving a "project name" and using it as "project slug".


Discussion:
@humitos I would like to work on this issue.
@dojutsu-user go ahead!

Resolving patch:
diff --git a/readthedocs/gold/forms.py b/readthedocs/gold/forms.py
--- a/readthedocs/gold/forms.py
+++ b/readthedocs/gold/forms.py
@@ -5,7 +5,10 @@
 from builtins import object
 from django import forms
 
+from django.utils.translation import ugettext_lazy as _
+
 from readthedocs.payments.forms import StripeModelForm, StripeResourceMixin
+from readthedocs.projects.models import Project
 
 from .models import LEVEL_CHOICES, GoldUser
 
@@ -88,6 +91,14 @@ def __init__(self, *args, **kwargs):
         self.projects = kwargs.pop('projects', None)
         super(GoldProjectForm, self).__init__(*args, **kwargs)
 
+    def clean_project(self):
+        project_slug = self.cleaned_data.get('project', '')
+        project_instance = Project.objects.filter(slug=project_slug)
+        if not project_instance.exists():
+            raise forms.ValidationError(_('No project found.'))
+        else:
+            return project_slug
+
     def clean(self):
         cleaned_data = super(GoldProjectForm, self).clean()
         if self.projects.count() < self.user.num_supported_projects:


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_gold.py b/readthedocs/rtd_tests/tests/test_gold.py
--- a/readthedocs/rtd_tests/tests/test_gold.py
+++ b/readthedocs/rtd_tests/tests/test_gold.py
@@ -26,6 +26,13 @@ def test_adding_projects(self):
         self.assertEqual(self.golduser.projects.count(), 1)
         self.assertEqual(resp.status_code, 302)
 
+    def test_incorrect_input_when_adding_projects(self):
+        self.assertEqual(self.golduser.projects.count(), 0)
+        incorrect_slug = 'xyz-random-incorrect-slug-xyz'
+        self.assertEqual(Project.objects.filter(slug=incorrect_slug).count(), 0)
+        resp = self.client.post(reverse('gold_projects'), data={'project': incorrect_slug})
+        self.assertFormError(resp, form='form', field='project', errors='No project found.')
+
     def test_too_many_projects(self):
         self.project2 = get(Project, slug='test2')
Repository: readthedocs/readthedocs.org

Issue:
login_required decorator is used at the end of the functions.
In the file readthedocs.org/readthedocs/profiles/views.py, `login_required` decorator is used at the end of some functions and for some other functions, it used in the form of `@login_required`, which reduces the readability of the code.


Discussion:

Resolving patch:
diff --git a/readthedocs/profiles/views.py b/readthedocs/profiles/views.py
--- a/readthedocs/profiles/views.py
+++ b/readthedocs/profiles/views.py
@@ -20,6 +20,7 @@
 from readthedocs.core.forms import UserAdvertisingForm, UserDeleteForm
 
 
+@login_required
 def edit_profile(
         request, form_class, success_url=None,
         template_name='profiles/private/edit_profile.html', extra_context=None):
@@ -93,9 +94,6 @@ def edit_profile(
     return render(request, template_name, context=context)
 
 
-edit_profile = login_required(edit_profile)
-
-
 @login_required()
 def delete_account(request):
     form = UserDeleteForm()


Test patch:
Repository: readthedocs/readthedocs.org

Issue:
Improve unexpected error message
Many users are reporting / filling an issue in our issue tracker when this message is shown to them, which is logic because it's what the message says.

> There was a problem with Read the Docs while building your documentation. Please report this to us with your build id (1234)

Although, I think we should improve this message saying something like "if this problem persists, please report..." or something similar to that. Otherwise, sometimes it's a temporal failure and we get tons of reports.


Discussion:
I would like to take this issue.
My suggestion for the error message is this -
"There was a problem with Read The Docs while building your documentation. This might be a temporary error. We suggest you to try again. However, if this problem persists, please report to us with your build id (1234)."
> This might be a temporary error. We suggest you to try again

"try again _later_.", maybe is better.

The rest is perfect to me.

Resolving patch:
diff --git a/readthedocs/doc_builder/exceptions.py b/readthedocs/doc_builder/exceptions.py
--- a/readthedocs/doc_builder/exceptions.py
+++ b/readthedocs/doc_builder/exceptions.py
@@ -24,7 +24,9 @@ class BuildEnvironmentError(BuildEnvironmentException):
 
     GENERIC_WITH_BUILD_ID = ugettext_noop(
         'There was a problem with Read the Docs while building your documentation. '
-        'Please report this to us with your build id ({build_id}).',
+        'Please try again later. '
+        'However, if this problem persists, '
+        'please report this to us with your build id ({build_id}).',
     )
 
 


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_doc_building.py b/readthedocs/rtd_tests/tests/test_doc_building.py
--- a/readthedocs/rtd_tests/tests/test_doc_building.py
+++ b/readthedocs/rtd_tests/tests/test_doc_building.py
@@ -339,7 +339,9 @@ def test_failing_execution_with_unexpected_exception(self):
             'length': mock.ANY,
             'error': (
                 'There was a problem with Read the Docs while building your '
-                'documentation. Please report this to us with your build id (123).'
+                'documentation. Please try again later. However, if this '
+                'problem persists, please report this to us with your '
+                'build id (123).'
             ),
             'setup': '',
             'output': '',
@@ -485,9 +487,10 @@ def _inner():
             'exit_code': 1,
             'length': 0,
             'error': (
-                "There was a problem with Read the Docs while building your "
-                "documentation. Please report this to us with your build id "
-                "(123)."
+                'There was a problem with Read the Docs while building your '
+                'documentation. Please try again later. However, if this '
+                'problem persists, please report this to us with your '
+                'build id (123).'
             ),
             'setup': '',
             'output': '',
Repository: readthedocs/readthedocs.org

Issue:
Remove /embed endpoint
Similar to #4731

https://github.com/rtfd/readthedocs.org/blob/604e1fa0374a0ba1b242b88e6f242eff77b7b6c3/readthedocs/restapi/urls.py#L66-L66

Raised in https://github.com/rtfd/readthedocs.org/pull/4731/files#r222783446


Discussion:
@stsewd Will it be okay if I take this issue.
Sure

Resolving patch:
diff --git a/readthedocs/restapi/urls.py b/readthedocs/restapi/urls.py
--- a/readthedocs/restapi/urls.py
+++ b/readthedocs/restapi/urls.py
@@ -63,7 +63,6 @@
 ]
 
 function_urls = [
-    url(r'embed/', core_views.embed, name='embed'),
     url(r'docurl/', core_views.docurl, name='docurl'),
     url(r'footer_html/', footer_views.footer_html, name='footer_html'),
 ]
diff --git a/readthedocs/restapi/views/core_views.py b/readthedocs/restapi/views/core_views.py
--- a/readthedocs/restapi/views/core_views.py
+++ b/readthedocs/restapi/views/core_views.py
@@ -6,11 +6,6 @@
 from rest_framework.renderers import JSONRenderer
 from rest_framework.response import Response
 
-import json
-import requests
-
-from django.conf import settings
-from django.core.cache import cache
 from django.shortcuts import get_object_or_404
 
 from readthedocs.builds.constants import LATEST
@@ -44,50 +39,3 @@ def docurl(request):
     return Response({
         'url': make_document_url(project=project, version=version.slug, page=doc)
     })
-
-
-@decorators.api_view(['GET'])
-@decorators.permission_classes((permissions.AllowAny,))
-@decorators.renderer_classes((JSONRenderer,))
-def embed(request):
-    """
-    Embed a section of content from any Read the Docs page.
-
-    Returns headers and content that matches the queried section.
-
-    ### Arguments
-
-        * project (required)
-        * doc (required)
-        * version (default latest)
-        * section
-
-    ### Example
-
-        GET https://readthedocs.org/api/v2/embed/?project=requests&doc=index&section=User%20Guide
-
-    # Current Request
-    """
-    project = request.GET.get('project')
-    version = request.GET.get('version', LATEST)
-    doc = request.GET.get('doc')
-    section = request.GET.get('section')
-
-    if project is None or doc is None:
-        return Response({'error': 'Need project and doc'}, status=status.HTTP_400_BAD_REQUEST)
-
-    embed_cache = cache.get('embed:%s' % project)
-    if embed_cache:
-        embed = json.loads(embed_cache)
-    else:
-        try:
-            resp = requests.get(
-                '{host}/api/v1/embed/'.format(host=settings.GROK_API_HOST),
-                params={'project': project, 'version': version, 'doc': doc, 'section': section}
-            )
-            embed = resp.json()
-            cache.set('embed:%s' % project, resp.content, 1800)
-        except Exception as e:
-            return Response({'error': '%s' % e.msg}, status=status.HTTP_400_BAD_REQUEST)
-
-    return Response(embed)


Test patch:
Repository: readthedocs/readthedocs.org

Issue:
Make form for adopting a project a ChoiceField
This is the form for adopting projects for Gold Members.

![screenshot from 2018-10-18 11-29-40](https://user-images.githubusercontent.com/29149191/47134225-9a130f80-d2c9-11e8-8c40-22a3e22dc002.png)

Currently the input field does not specify any idea about what to enter.
Although, the project's slug is need to be enter, but it is written nowhere which creates confusion and the user ends up entering the project's name which gives an error.

This issue was discussed in the comments [#427135794](https://github.com/rtfd/readthedocs.org/pull/4721#issuecomment-427135794), [#427137725](https://github.com/rtfd/readthedocs.org/pull/4721#issuecomment-427137725) and [#427139109](https://github.com/rtfd/readthedocs.org/pull/4721#issuecomment-427139109)


Discussion:
@stsewd Will adding the `help_text` would be enough?

![screenshot from 2018-10-18 12-09-43](https://user-images.githubusercontent.com/29149191/47135702-f7f62600-d2ce-11e8-80cf-156558c4dcd6.png)


That field should probably be a `ChoiceField` where the user can only select the available options (I'm assuming that the User can only adopt projects where he is a maintainer --but I'm not 100% sure, you will need to check the code to know that)
https://github.com/rtfd/readthedocs.org/blob/df85fefc5f59c7a00bcc1ffe23965efe75e8c895/readthedocs/gold/views.py#L108-L110

@humitos from the code, it seems that the user can adopt **any** project.
Mmm... OK. It doesn't make too much sense to me, since it's a weird case to want to support a project that you are not involved to.

So, if we want to keep this behavior, my solution of the `ChoiceField` doesn't fit here.

Another different approach, that we don't have in any other place I think, would be to use a field with autocomplete --not sure if we want that, though. Probably, no.

I'd say that for now, the `help_text` is the first step, but it doesn't solve the whole problem anyway.
@humitos yeahh, `help_text` won't solve whole problem, but it atleast gives the idea/hint that the project's name is not to be entered here.

Resolving patch:
diff --git a/readthedocs/gold/forms.py b/readthedocs/gold/forms.py
--- a/readthedocs/gold/forms.py
+++ b/readthedocs/gold/forms.py
@@ -81,6 +81,7 @@ def get_subscription(self):
 class GoldProjectForm(forms.Form):
     project = forms.CharField(
         required=True,
+        help_text='Enter the project\'s slug'
     )
 
     def __init__(self, *args, **kwargs):


Test patch:
Repository: readthedocs/readthedocs.org

Issue:
Return 404 at SubdomainMiddleware level if project doesn't exist
While deploying .com we found that `SubdomainMiddleware` doesn't check the existence of the project that it's injecting at `request.slug`.

So, any middleware that relies on this to do some extra work, will probably do something like `Project.objects.get(slug=request.slug)` and will fail.

We workarounded it by adding `try/except` block in the middleware that uses this, but we should probably just raise a 404 inside the `SubdomainMiddleware` itself instead of continue with the flow.

Code: https://github.com/rtfd/readthedocs.org/blob/74bbb3ac23b6b06a70517bc1b301961db6821e32/readthedocs/core/middleware.py#L72


Discussion:
@humitos I would like to take this issue up.
If I'm not wrong, you probably want something like this

```python3
# Checking if the project exist or not
from django.shortcuts import get_object_or_404
get_object_or_404(Project, slug=subdomain)

request.subdomain = True
request.slug = subdomain
request.urlconf = SUBDOMAIN_URLCONF
return None
```

With `get_object_or_404`, it will show error and does not go further.
@dojutsu-user since this is a code that it's executed a lot, retrieving the whole Project object it may be overkilling since we not going to use that data anyway. You may just need to check if the project does exist with `.exists()` and using an if in this case.

Resolving patch:
diff --git a/readthedocs/core/middleware.py b/readthedocs/core/middleware.py
--- a/readthedocs/core/middleware.py
+++ b/readthedocs/core/middleware.py
@@ -69,6 +69,8 @@ def process_request(self, request):
                 # Support ports during local dev
                 public_domain in host or public_domain in full_host
             ):
+                if not Project.objects.filter(slug=subdomain).exists():
+                    raise Http404(_('Project not found'))
                 request.subdomain = True
                 request.slug = subdomain
                 request.urlconf = SUBDOMAIN_URLCONF


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_middleware.py b/readthedocs/rtd_tests/tests/test_middleware.py
--- a/readthedocs/rtd_tests/tests/test_middleware.py
+++ b/readthedocs/rtd_tests/tests/test_middleware.py
@@ -47,6 +47,13 @@ def test_proper_subdomain(self):
         self.assertEqual(request.urlconf, self.urlconf_subdomain)
         self.assertEqual(request.slug, 'pip')
 
+    @override_settings(PRODUCTION_DOMAIN='readthedocs.org')
+    def test_wrong_subdomain(self):
+        http_host = 'xyz-wrong-sub-domain-xyz.readthedocs.org'
+        request = self.factory.get(self.url, HTTP_HOST=http_host)
+        with self.assertRaises(Http404):
+            self.middleware.process_request(request)
+
     @override_settings(PRODUCTION_DOMAIN='readthedocs.org')
     def test_restore_urlconf_after_request(self):
         """
Repository: readthedocs/readthedocs.org

Issue:
Locally hosted RTD instance doesn't allow git file:/// URLs
## Details
I installed a local RTD instance according to the Installation guide and imported test project. Now, I want to import my git project manually, 
## Expected Result

I expected that the instance should accept all valid Git URLs.

## Actual Result

When I enter file:///.../../x.git URL, the manual import page shows "Invalid scheme for URL" error. I checked that I can clone this URL from a terminal.



Discussion:
Makes sense to me. It should be easy to grep for the git logic we use for Git urls, and then to extend that to match this protocol. Would you be interested in helping with a PR? 
Yes, I can help with a PR. Let me look at the code...

sob., 5 maj 2018, 00:34 użytkownik Richard Littauer <
notifications@github.com> napisał:

> Makes sense to me. It should be easy to grep for the git logic we use for
> Git urls, and then to extend that to match this protocol. Would you be
> interested in helping with a PR?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/rtfd/readthedocs.org/issues/4061#issuecomment-386751897>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AJfmUSSktUPlqpUQhCXyaxOHrWxDzcBaks5tvNd1gaJpZM4TzPy_>
> .
>

These are disallowed on readthedocs.org for security reasons. If the work here gets completed it should probably be an option that is disabled by default.
`git file:///` URLs only make sense on local rtd instances, when the instance is on the same machine as a Git repo. They certainly are a security risk on public-facing servers.
However, many people have their local repos on a development machine and may want to install a local instance and generate a set of docs. Currently, after installation of a new instance, it's impossible to manually import a project without exposing the repo on the net, which is a hassle and and also a security risk. I think this use case may be common enough to justify an install option which unblocks ` git file:///` URLs during the installation. As @davidfischer points out, this option should be disabled by default.
I'm re labelling this since it's not a bug in RTD but a feature that is useful for local RTD installation. Marking as Community Effort.

Resolving patch:
diff --git a/readthedocs/projects/validators.py b/readthedocs/projects/validators.py
--- a/readthedocs/projects/validators.py
+++ b/readthedocs/projects/validators.py
@@ -62,9 +62,12 @@ def __call__(self, value):
         allow_private_repos = getattr(settings, 'ALLOW_PRIVATE_REPOS', False)
         public_schemes = ['https', 'http', 'git', 'ftps', 'ftp']
         private_schemes = ['ssh', 'ssh+git']
+        local_schemes = ['file']
         valid_schemes = public_schemes
         if allow_private_repos:
             valid_schemes += private_schemes
+        if getattr(settings, 'DEBUG'):  # allow `file://` urls in dev
+            valid_schemes += local_schemes
         url = urlparse(value)
 
         # Malicious characters go first


Test patch:
Repository: readthedocs/readthedocs.org

Issue:
Find out where/why rtd activates a version after building it
Not sure how to classify this issue, but we kind of need to figure out why are we activating a version after building it, it may be a bug or it is by design.

Raised in https://github.com/rtfd/readthedocs.org/pull/4733#issuecomment-430012283


Discussion:
I think I found it

https://github.com/rtfd/readthedocs.org/blob/a4291d17728b8df6b7a9ce57537c5d620416e485/readthedocs/projects/tasks.py#L605-L610

/cc @humitos 

Still not sure why we do that :man_shrugging: 
@stsewd good work!

First of all, I think we don't need to send the `active=True` in that PATCH.

On the other hand, I come up with some questions:

* why we would build a version that it's not active?
* in case we want to build a version that it's not active, why we would like to mark it as active after building it?

@agjohnson @ericholscher you may remember some use case for this. Otherwise, I think we can remove the `active` argument from the PATCH.

Also, we should confirm that removing this we still can work around #4001.
I'm lost on the two points above as well. I'd say we don't want to build it at all if its inactive, and we certainly shouldn't be changing active=True.

Perhaps this was a case to catch the initial import of a project? When the `latest` version is maybe not active yet? Just guessing at this...
I tested this locally, removing active from the patch works, and it doesn't break things like the first import, as we create the latest and stable with `active=True`

https://github.com/rtfd/readthedocs.org/blob/dfc8fc9eba8dc9caae171ca0b3e8f6a71594e088/readthedocs/builds/managers.py#L37-L59

The only parts where we are triggering builds on inactive versions are: on webhooks (fix in #4733), and when triggering manually a build (from django shell?).

If we want to move the check to trigger build, we need to refactor the other places, and we lose the ability to build inactive versions
In my opinion, I think that removing it from the `PATCH` is ok.

I don't think we want to move the check of the inactive version inside the `trigger_build` function. Do you have a different opinion?
> Do you have a different opinion?

Nope, same. Also, that is easier than touching the rest of the code p:

Resolving patch:
diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py
--- a/readthedocs/projects/tasks.py
+++ b/readthedocs/projects/tasks.py
@@ -605,7 +605,6 @@ def update_app_instances(self, html=False, localmedia=False, search=False,
             if html:
                 version = api_v2.version(self.version.pk)
                 version.patch({
-                    'active': True,
                     'built': True,
                 })
         except HttpClientError:


Test patch:
Repository: readthedocs/readthedocs.org

Issue:
Confusing error message to end user
In https://github.com/rtfd/readthedocs.org/issues/4071#issuecomment-405939492 I realized that we are saying that we have a problem parsing the YAML file but the problem is in fact in one of the options set from the web admin dashboard.

Example:

![captura de pantalla_2018-07-18_10-57-36](https://user-images.githubusercontent.com/244656/42886232-647bedbc-8a79-11e8-8aca-fe2430139fe0.png)

There is no `requirements_file` entry in the YAML file (https://github.com/geopandas/geopandas/blob/master/readthedocs.yml) but it exists under the `Admin -> Advanced Settings` field form.

We need to improve this error to something more user-friendly that expresses the real error. It's not an error on parsing the YAML file. The file was parsed properly, but the problem is with one of the values from one of the fields.


Discussion:
Previously we weren't checking for the requirements file of the web admin, so an error would happen in the install requirements step. I think we can catch this cases when doing https://github.com/rtfd/readthedocs.org/issues/4388
This message comes from https://github.com/rtfd/readthedocs.org/blob/67dfae9de7be81af92bd88453427424111a6168f/readthedocs/projects/tasks.py#L424-L424, we should change to be more generic like _Problem in your project configuration_.

Resolving patch:
diff --git a/readthedocs/doc_builder/exceptions.py b/readthedocs/doc_builder/exceptions.py
--- a/readthedocs/doc_builder/exceptions.py
+++ b/readthedocs/doc_builder/exceptions.py
@@ -43,7 +43,7 @@ class ProjectBuildsSkippedError(BuildEnvironmentError):
 
 class YAMLParseError(BuildEnvironmentError):
     GENERIC_WITH_PARSE_EXCEPTION = ugettext_noop(
-        'Problem parsing YAML configuration. {exception}',
+        'Problem in your project\'s configuration. {exception}',
     )
 
 


Test patch: