internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: djangopackages/djangopackages

Issue:
Change watchers to stars
e.g. "Repo Watchers"



Discussion:
Just on the templates and translation files?


Resolving patch:
diff --git a/grid/views.py b/grid/views.py
--- a/grid/views.py
+++ b/grid/views.py
@@ -68,7 +68,7 @@ def grid_detail_landscape(request, slug, template_name="grid/grid_detail2.html")
                 ('pypi_version', 'Version'),
                 ('repo', 'Repo'),
                 ('commits_over_52', 'Commits'),
-                ('repo_watchers', 'Repo watchers'),
+                ('repo_watchers', 'Stars'),
                 ('repo_forks', 'Forks'),
                 ('participant_list', 'Participants'),
                 ('license_latest', 'License')
@@ -350,7 +350,7 @@ def grid_detail(request, slug, template_name="grid/grid_detail.html"):
                 ('pypi_version', 'Version'),
                 ('repo', 'Repo'),
                 ('commits_over_52', 'Commits'),
-                ('repo_watchers', 'Repo watchers'),
+                ('repo_watchers', 'Stars'),
                 ('repo_forks', 'Forks'),
                 ('participant_list', 'Participants'),
                 ('license_latest', 'License')
diff --git a/package/models.py b/package/models.py
--- a/package/models.py
+++ b/package/models.py
@@ -54,7 +54,7 @@ class Package(BaseModel):
     category = models.ForeignKey(Category, verbose_name="Installation")
     repo_description = models.TextField(_("Repo Description"), blank=True)
     repo_url = models.URLField(_("repo URL"), help_text=repo_url_help_text, blank=True, unique=True, verify_exists=True)
-    repo_watchers = models.IntegerField(_("repo watchers"), default=0)
+    repo_watchers = models.IntegerField(_("Stars"), default=0)
     repo_forks = models.IntegerField(_("repo forks"), default=0)
     pypi_url = models.URLField(_("PyPI slug"), help_text=pypi_url_help_text, blank=True, default='', verify_exists=True)
     pypi_downloads = models.IntegerField(_("Pypi downloads"), default=0)
diff --git a/searchv2/models.py b/searchv2/models.py
--- a/searchv2/models.py
+++ b/searchv2/models.py
@@ -21,7 +21,7 @@ class SearchV2(BaseModel):
             grids
             pacakges
             categories
-            number of watchers
+            stars
             number of forks
             last repo commit
             last release on PyPI
@@ -37,7 +37,7 @@ class SearchV2(BaseModel):
     description = models.TextField(_("Repo Description"), blank=True)
     category = models.CharField(_("Category"), blank=True, max_length=50)
     absolute_url = models.CharField(_("Absolute URL"), max_length="255")
-    repo_watchers = models.IntegerField(_("repo watchers"), default=0)
+    repo_watchers = models.IntegerField(_("Stars"), default=0)
     repo_forks = models.IntegerField(_("repo forks"), default=0)
     pypi_downloads = models.IntegerField(_("Pypi downloads"), default=0)
     usage = models.IntegerField(_("Number of users"), default=0)


Test patch:
Repository: djangopackages/djangopackages

Issue:
ImportError: cannot import name 'NoArgsCommand'
When I run the `load_dev_data` django mgmt command, the following error occurs:

```
$ docker-compose -f dev.yml run django python manage.py load_dev_data
Starting djangopackages_postgres_1 ... done
Starting djangopackages_redis_1    ... done
Postgres is up - continuing...
/src/django-floppyforms/floppyforms/__init__.py:21: UserWarning: Unable to import floppyforms.gis, geometry widgets not available
  "Unable to import floppyforms.gis, geometry widgets not available")
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 206, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 40, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/core/management/commands/load_dev_data.py", line 4, in <module>
    from django.core.management.base import CommandError, NoArgsCommand
ImportError: cannot import name 'NoArgsCommand'
```


Discussion:

Resolving patch:
diff --git a/core/management/commands/load_dev_data.py b/core/management/commands/load_dev_data.py
--- a/core/management/commands/load_dev_data.py
+++ b/core/management/commands/load_dev_data.py
@@ -1,16 +1,16 @@
 from sys import stdout
+from importlib import import_module
 
 from django.conf import settings
-from django.core.management.base import CommandError, NoArgsCommand
-from django.utils.importlib import import_module
+from django.core.management.base import BaseCommand
 from django.utils.module_loading import module_has_submodule
 
 
-class Command(NoArgsCommand):
-    
+class Command(BaseCommand):
+
     help = "Import development data for local dev"
-    
-    def handle(self, *args, **options): 
+
+    def handle(self, *args, **options):
         print("Commencing dev data import", file=stdout)
 
         for app in settings.INSTALLED_APPS:


Test patch:
Repository: djangopackages/djangopackages

Issue:
🐛  AssertionError /api/v4/grids/
This is coming from sentry: 

```
("Creating a ModelSerializer without either the 'fields' attribute or the 'exclude' attribute has been deprecated since 3.3.0, and is now disallowed. Add an explicit fields = '__all__' to the GridSerializer serializer.",)
```




Discussion:

Resolving patch:
diff --git a/apiv4/serializers.py b/apiv4/serializers.py
--- a/apiv4/serializers.py
+++ b/apiv4/serializers.py
@@ -11,12 +11,24 @@
 from package.models import Package, Category
 from searchv2.models import SearchV2
 
+
 class GridSerializer(serializers.ModelSerializer):
     packages = serializers.HyperlinkedRelatedField(many=True, view_name='apiv4:package-detail', read_only=True)
 
     class Meta:
+        fields = [
+            "title",
+            "slug",
+            "description",
+            "is_locked",
+            "packages",
+            "header",
+            "created",
+            "modified",
+        ]
         model = Grid
 
+
 class PackageSerializer(serializers.HyperlinkedModelSerializer):
     # 'Source' is attached to the model attribute
     participants = serializers.ListField(source='participant_list')
@@ -124,4 +136,13 @@ class Meta:
 class CategorySerializer(serializers.ModelSerializer):
 
     class Meta:
+        fields = [
+            "title",
+            "slug",
+            "description",
+            "title_plural",
+            "show_pypi",
+            "created",
+            "modified",
+        ]
         model = Category


Test patch:
Repository: djangopackages/djangopackages

Issue:
🔌  Add a feature flipper
Judging from our grids, https://github.com/django-waffle/django-waffle is probably not a bad way to go. 


Discussion:

Resolving patch:
diff --git a/settings/base.py b/settings/base.py
--- a/settings/base.py
+++ b/settings/base.py
@@ -78,6 +78,7 @@
     "django.contrib.messages.middleware.MessageMiddleware",
     "django.middleware.clickjacking.XFrameOptionsMiddleware",
     "dj_pagination.middleware.PaginationMiddleware",
+    "waffle.middleware.WaffleMiddleware",
 ]
 
 TEMPLATES = [
@@ -149,12 +150,12 @@
     "crispy_forms",
     "dj_pagination",
     "django_extensions",
-    "reversion",
-    "webstack_django_sorting",
-    # "django_modeler",
-    "social_django",
     "floppyforms",
     "rest_framework",
+    "reversion",
+    "social_django",
+    "waffle",
+    "webstack_django_sorting",
 ]
 
 INSTALLED_APPS = PREREQ_APPS + PROJECT_APPS


Test patch:
Repository: djangopackages/djangopackages

Issue:
🔢  Add some type of SemVer/CalVer versioning scheme to the project
It's easier to troubleshoot if we can track a version through from testing through production. 

My goto these days is CalVer, but I'm open to suggestions/changing this later. 


Discussion:
I think CalVer is the right choice. Maybe `YYYY.MM.DD.01` (or `YYYY.MM.DD.001`) where `01` (or `001`) is today's deployment counter. 
I don't know if there is any library to manage the version that supports this nor how difficult it is to implement it.
The last time I checked [bumpver](https://pypi.org/project/bumpver/), checked the feature boxed fairly well. 

`YYYY.MM.INC1` is kind of appealing because it's PEP440 compatible (even though this grid is wrong https://github.com/mbarkhau/bumpver#pattern-examples)

You can talk me into going with day, but seeing we deployed 35 times in August with a two "." pattern is appealing too. 
`YYYY.MM.INC1` also works well

Resolving patch:
diff --git a/core/__init__.py b/core/__init__.py
--- a/core/__init__.py
+++ b/core/__init__.py
@@ -0,0 +1 @@
+__version__ = "2021.8.1"
diff --git a/urls.py b/urls.py
--- a/urls.py
+++ b/urls.py
@@ -5,12 +5,16 @@
 from django.urls import path, re_path
 from django.views.generic.base import TemplateView
 
+from core import __version__
 from core.apiv1 import apiv1_gone
 from homepage.views import homepage, error_404_view, error_500_view, health_check_view, SitemapView
 from package.views import category, python3_list
 from profiles.views import LogoutView
 
-admin.autodiscover()
+admin_header = f"Django Packages v{__version__}"
+# admin.site.enable_nav_sidebar = False  # disabled until Django 3.x
+admin.site.site_header = admin_header
+admin.site.site_title = admin_header
 
 urlpatterns = [
 


Test patch:
Repository: djangopackages/djangopackages

Issue:
📄  Create Funding page to outline where funding goes and options 
I think having a static page linked from the footer would make a lot of sense to provide links for funding past and present maintainers. 


Discussion:

Resolving patch:
diff --git a/urls.py b/urls.py
--- a/urls.py
+++ b/urls.py
@@ -45,7 +45,8 @@
     path('open/', OpenView.as_view(), name="open"),
     path('syndication/', TemplateView.as_view(template_name='pages/syndication.html'), name="syndication"),
     path('help/', TemplateView.as_view(template_name='pages/help.html'), name="help"),
-    re_path(r"^sitemap\.xml$", SitemapView.as_view(), name="sitemap"),
+    path("funding/", TemplateView.as_view(template_name='pages/funding.html'), name="funding"),
+    path("sitemap.xml", SitemapView.as_view(), name="sitemap"),
 
     # new apps
     path('search/', include("searchv2.urls")),


Test patch:
Repository: djangopackages/djangopackages

Issue:
Incorrect PyPI URLs on some packages
**Describe the bug**
Some packages have a PyPI URL in the form of `http://pypi.python.org/pypi/https://pypi.org/project/...` for example:
https://djangopackages.org/packages/p/wagtail-grapple/
https://djangopackages.org/packages/p/wagtail-2fa/

**Additional context**
We use the API to pull in Wagtail packages and display on https://wagtail.io/packages/

Originally reported on https://github.com/wagtail/wagtail.io/issues/118



Discussion:

Resolving patch:
diff --git a/package/models.py b/package/models.py
--- a/package/models.py
+++ b/package/models.py
@@ -97,7 +97,14 @@ def pypi_name(self):
         if not self.pypi_url.strip():
             return ""
 
-        name = self.pypi_url.replace("http://pypi.python.org/pypi/", "")
+        name = self.pypi_url
+
+        if "http://pypi.python.org/pypi/" in name:
+            name = name.replace("http://pypi.python.org/pypi/", "")
+
+        if "https://pypi.python.org/pypi/" in name:
+            name = name.replace("https://pypi.python.org/pypi/", "")
+
         if "/" in name:
             return name[:name.index("/")]
         return name


Test patch:
Repository: djangopackages/djangopackages

Issue:
Incorrect PyPI URLs on some packages
**Describe the bug**
Some packages have a PyPI URL in the form of `http://pypi.python.org/pypi/https://pypi.org/project/...` for example:
https://djangopackages.org/packages/p/wagtail-grapple/
https://djangopackages.org/packages/p/wagtail-2fa/

**Additional context**
We use the API to pull in Wagtail packages and display on https://wagtail.io/packages/

Originally reported on https://github.com/wagtail/wagtail.io/issues/118



Discussion:
@zerolab thank you for the report. This should be patched now both in #725 and in 06bf99a59ed325ab2dcf39fd39115b21949a92f1 

I suspect I'll have to do a cleanup script or something to fix these. I'll double-check tomorrow. We need to refactor more of the pypi logic to add some validation. 

It's also pretty neat to see Wagtail is using this data. I have looked at it a few dozen times and I never realized it before :) 
I'm also noticing the pypi history isn't being fetched. More for tomorrow. 
Ah, thank you so much for the swift fix and response 🌟 ❤️
I'm still seeing issues in a few categories, but I didn't have the headspace to poke around at the database. I will have a fix Friday or this weekend though with a better default for pypi too since I noticed we are hitting a redirect. 

Resolving patch:
diff --git a/package/management/commands/pypi_find_missing.py b/package/management/commands/pypi_find_missing.py
new file mode 100644
--- /dev/null
+++ b/package/management/commands/pypi_find_missing.py
@@ -0,0 +1,24 @@
+import djclick as click
+import logging
+
+from django.db.models import Q
+
+from package.models import Package
+
+logger = logging.getLogger(__name__)
+
+
+@click.command()
+def command():
+    total_empty_packages = Package.objects.filter(
+        ~Q(pypi_url__startswith="http")
+    ).count()
+    total_packages = Package.objects.all().count()
+    packages = Package.objects.filter(~Q(pypi_url__startswith="http") & ~Q(pypi_url=""))
+
+    click.echo(f"total_packages: {total_packages}")
+    click.echo(f"total_empty_packages: {total_empty_packages}")
+    click.echo(f"packages needing fixed: {packages.count()}")
+
+    for package in packages:
+        click.echo(f"- {package.pypi_url}")


Test patch:
Repository: djangopackages/djangopackages

Issue:
Re-add grid id in the API output
Before the rounds of updates and #639, the API was returning the Grid id.

We are using the id for creating or updating a Grid entry on wagtail.io -- https://github.com/wagtail/wagtail.io/blob/master/wagtailio/packages/views.py#L16, but that is now failing with an integrity error since `id` is None (https://github.com/wagtail/wagtail.io/issues/119)

Happy to submit a PR


Discussion:

Resolving patch:
diff --git a/apiv4/serializers.py b/apiv4/serializers.py
--- a/apiv4/serializers.py
+++ b/apiv4/serializers.py
@@ -17,6 +17,7 @@ class GridSerializer(serializers.ModelSerializer):
 
     class Meta:
         fields = [
+            "id",
             "title",
             "slug",
             "description",
@@ -138,6 +139,7 @@ class Meta:
 class CategorySerializer(serializers.ModelSerializer):
     class Meta:
         fields = [
+            "id",
             "title",
             "slug",
             "description",


Test patch:
Repository: djangopackages/djangopackages

Issue:
Incorrect `license` on package pages
**Describe the bug**
The `license` shown on package pages has started to show as `UNKNOWN` even where a licence was previously available. See [here](https://djangopackages.org/packages/p/django-axes/) and [here](https://djangopackages.org/packages/p/django_coverage_plugin/)

**To Reproduce**
Steps to reproduce the behavior:
1. Go to https://djangopackages.org/packages/p/django-axes/
2. Scroll down to Releases
3. See license in table is `UNKNOWN`

**Expected behavior**
Show the correct license

**Additional context**
I am sorry I've not had time to do a deep dive at this stage, but thought it best to log this now before I forget! However I noticed that there were recent commits in this area (e.g. https://github.com/djangopackages/djangopackages/commit/8bad61f4729818a923d903c40e8b49b75f854148 ) so suspect that is probably related. 


Discussion:
Good catch. I'll write up a test later and work on a fix when I get time. 

It looks like we have `licenses = [ MIT License, MIT License, MIT License]` in the new field that we want to move over to, but it looks like there is some leakage there too. 

Resolving patch:
diff --git a/package/models.py b/package/models.py
--- a/package/models.py
+++ b/package/models.py
@@ -274,14 +274,10 @@ def fetch_pypi_data(self, *args, **kwargs):
                     if license or "UNKNOWN" == license.upper():
                         for classifier in info["classifiers"]:
                             if classifier.startswith("License"):
-                                licenses[index] = classifier.strip().replace(
-                                    "License ::", ""
-                                )
-                                licenses[index] = licenses[index].replace(
-                                    "OSI Approved :: ", ""
-                                )
+                                licenses[index] = classifier.split("::")[-1].strip()
                                 break
 
+                version.license = licenses[0]
                 version.licenses = licenses
 
             # version stuff


Test patch:
Repository: djangopackages/djangopackages

Issue:
Incorrect `license` on package pages
**Describe the bug**
The `license` shown on package pages has started to show as `UNKNOWN` even where a licence was previously available. See [here](https://djangopackages.org/packages/p/django-axes/) and [here](https://djangopackages.org/packages/p/django_coverage_plugin/)

**To Reproduce**
Steps to reproduce the behavior:
1. Go to https://djangopackages.org/packages/p/django-axes/
2. Scroll down to Releases
3. See license in table is `UNKNOWN`

**Expected behavior**
Show the correct license

**Additional context**
I am sorry I've not had time to do a deep dive at this stage, but thought it best to log this now before I forget! However I noticed that there were recent commits in this area (e.g. https://github.com/djangopackages/djangopackages/commit/8bad61f4729818a923d903c40e8b49b75f854148 ) so suspect that is probably related. 


Discussion:
Good catch. I'll write up a test later and work on a fix when I get time. 

It looks like we have `licenses = [ MIT License, MIT License, MIT License]` in the new field that we want to move over to, but it looks like there is some leakage there too. 
I'm going to leave hit open, but I have a partial fix based on our license refactor. It needs a little more work (hopefully not a night during a week night) to see it through though. 

<img width="881" alt="Screen Shot 2021-10-28 at 10 17 08 PM" src="https://user-images.githubusercontent.com/50527/139370034-7820fcc2-c74c-4ae0-b60c-827f567e4f19.png">


Resolving patch:
diff --git a/package/models.py b/package/models.py
--- a/package/models.py
+++ b/package/models.py
@@ -269,7 +269,7 @@ def fetch_pypi_data(self, *args, **kwargs):
 
             # add to versions
             if "license" in info and info["license"]:
-                licenses = list(info["license"])
+                licenses = [info["license"]]
                 for index, license in enumerate(licenses):
                     if license or "UNKNOWN" == license.upper():
                         for classifier in info["classifiers"]:
@@ -277,8 +277,8 @@ def fetch_pypi_data(self, *args, **kwargs):
                                 licenses[index] = classifier.split("::")[-1].strip()
                                 break
 
-                version.license = licenses[0]
                 version.licenses = licenses
+                version.license = licenses[0]
 
             # version stuff
             try:


Test patch:
Repository: djangopackages/djangopackages

Issue:
Clean up migrated projects
I did some manual cleanup Friday night (mostly jazzband projects) to get a better understanding of how to fix GitHub projects which have been renamed or migrated.

Some of this is needed for #761 and to start addressing failed project sin our logs. 


Discussion:

Resolving patch:
diff --git a/package/management/commands/cleanup_github_projects.py b/package/management/commands/cleanup_github_projects.py
new file mode 100644
--- /dev/null
+++ b/package/management/commands/cleanup_github_projects.py
@@ -0,0 +1,55 @@
+import djclick as click
+import requests
+
+from package.models import Package
+
+
+@click.command()
+@click.option("--limit", default=None)
+def command(limit):
+    # fix non-https links
+    packages = Package.objects.filter(repo_url__startswith="http://github.com")
+    if packages.exists():
+        click.secho(
+            f"Found {packages.count()} GitHub Packages that need to be migrated",
+            fg="yellow",
+        )
+        for package in packages:
+            click.echo(f"    migrating {package.repo_url}")
+            package.repo_url = package.repo_url.replace(
+                "http://github.com", "https://github.com"
+            )
+            try:
+                package.save()
+            except Exception as e:
+                click.secho(f"{e}", fg="red")
+                # TODO: write migration code...
+
+    packages = Package.objects.filter(repo_url__startswith="https://github.com")
+
+    if limit:
+        packages = packages[0:limit]
+
+    if packages.exists():
+        click.secho(
+            f"Found {packages.count()} GitHub Packages to be scanned",
+            fg="yellow",
+        )
+        for package in packages:
+            response = requests.get(package.repo_url)
+            history = response.history
+            if len(history):
+                new_packages = Package.objects.filter(repo_url__startswith=response.url)
+                if new_packages.exists():
+                    found_pks = new_packages.values_list("pk", flat=True)
+                    click.echo(f"    found {found_pks}")
+
+                else:
+                    click.echo(f"    migrating {package.repo_url} => {response.url}")
+                    package.repo_url = response.url
+                    # TODO: Make a note about migrating the account...
+                    package.save()
+
+                # package.date_deprecated
+                # package.deprecated_by
+                # package.deprecates_package


Test patch: