Skip to content

Commit

Permalink
Fixed #1724 -- Renamed "patch" to "pull request"
Browse files Browse the repository at this point in the history
This follows Django ticket # 35894
  • Loading branch information
bmispelon committed Nov 13, 2024
1 parent 538d2e6 commit 8b8750f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
Binary file modified dashboard/fixtures/dashboard_example_data.json.gz
Binary file not shown.
8 changes: 4 additions & 4 deletions dashboard/fixtures/dashboard_production_metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"model": "dashboard.category",
"pk": 2,
"fields": {
"name": "Patches",
"name": "Pull requests",
"position": 2
}
},
Expand Down Expand Up @@ -51,7 +51,7 @@
"model": "dashboard.tracticketmetric",
"pk": 2,
"fields": {
"name": "Patches needing review",
"name": "PRs needing review",
"slug": "patches",
"category": 2,
"position": 3,
Expand All @@ -67,7 +67,7 @@
"model": "dashboard.tracticketmetric",
"pk": 3,
"fields": {
"name": "Doc. patches needing review",
"name": "Doc. PRs needing review",
"slug": "doc-patches",
"category": 2,
"position": 4,
Expand Down Expand Up @@ -165,7 +165,7 @@
"fields": {
"name": "\"Easy\" tickets",
"slug": "easy-tickets",
"category": 2,
"category": 4,
"position": 1,
"show_on_dashboard": true,
"show_sparkline": true,
Expand Down
8 changes: 4 additions & 4 deletions dashboard/fixtures/dashboard_test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
"fields": {
"position": 2,
"name": "Patches"
"name": "Pull requests"
},
"model": "dashboard.category",
"pk": 2
Expand Down Expand Up @@ -51,7 +51,7 @@
"fields": {
"category": 2,
"show_on_dashboard": true,
"name": "Patches needing review",
"name": "PRs needing review",
"period": "instant",
"show_sparkline": true,
"query": "status=!closed&needs_better_patch=0&needs_tests=0&needs_docs=0&has_patch=1&stage=Accepted",
Expand All @@ -67,7 +67,7 @@
"fields": {
"category": 2,
"show_on_dashboard": true,
"name": "Doc. patches needing review",
"name": "Doc. PRs needing review",
"period": "instant",
"show_sparkline": true,
"query": "status=!closed&needs_better_patch=0&component=Documentation&needs_tests=0&needs_docs=0&has_patch=1&stage=Accepted",
Expand Down Expand Up @@ -161,7 +161,7 @@
},
{
"fields": {
"category": 2,
"category": 4,
"show_on_dashboard": true,
"name": "\"Easy\" tickets",
"period": "instant",
Expand Down
71 changes: 71 additions & 0 deletions dashboard/migrations/0003_rename_patch_to_pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from django.db import migrations

CATEGORY_RENAMES = {
# old name: new name
"Patches": "Pull requests",
}

TRACMETRIC_RENAMES = {
# old name: new name
"Patches needing review": "Tickets with PRs needing review",
"Doc. patches needing review": "Doc. tickets with PRs needing review",
}

CATEGORY_CHANGES = {
# Metric name: (old category, new category)
"\"Easy\" tickets": ("Patches", "Accepted tickets by type"),
}


def _reverse(d):
"""
Reverse the given dict (values become keys and vice-versa).
"""
return {v: k for k, v in d.items()}


def rename(apps, schema_editor):
Category = apps.get_model("dashboard", "Category")
TracTicketMetric = apps.get_model("dashboard", "TracTicketMetric")

for metric, (old, new) in CATEGORY_CHANGES.items():
new_category = Category.objects.filter(name=new).first()
if not new_category:
continue
metrics = TracTicketMetric.objects.filter(name=metric, category__name=old)
metrics.update(category=new_category)

for old, new in CATEGORY_RENAMES.items():
Category.objects.filter(name=old).update(name=new)

for old, new in TRACMETRIC_RENAMES.items():
TracTicketMetric.objects.filter(name=old).update(name=new)


def rename_backwards(apps, schema_editor):
Category = apps.get_model("dashboard", "Category")
TracTicketMetric = apps.get_model("dashboard", "TracTicketMetric")

for old, new in _reverse(TRACMETRIC_RENAMES).items():
TracTicketMetric.objects.filter(name=old).update(name=new)

for old, new in _reverse(CATEGORY_RENAMES).items():
Category.objects.filter(name=old).update(name=new)

for metric, (new, old) in CATEGORY_CHANGES.items():
new_category = Category.objects.filter(name=new).first()
if not new_category:
continue
metrics = TracTicketMetric.objects.filter(name=metric, category__name=old)
metrics.update(category=new_category)


class Migration(migrations.Migration):

dependencies = [
('dashboard', '0002_delete_rssfeedmetric_create_githubsearchcountmetric'),
]

operations = [
migrations.RunPython(rename, rename_backwards),
]

0 comments on commit 8b8750f

Please sign in to comment.