Skip to content

Commit 8b8750f

Browse files
committed
Fixed django#1724 -- Renamed "patch" to "pull request"
This follows Django ticket # 35894
1 parent 538d2e6 commit 8b8750f

4 files changed

+79
-8
lines changed
Binary file not shown.

dashboard/fixtures/dashboard_production_metrics.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"model": "dashboard.category",
1212
"pk": 2,
1313
"fields": {
14-
"name": "Patches",
14+
"name": "Pull requests",
1515
"position": 2
1616
}
1717
},
@@ -51,7 +51,7 @@
5151
"model": "dashboard.tracticketmetric",
5252
"pk": 2,
5353
"fields": {
54-
"name": "Patches needing review",
54+
"name": "PRs needing review",
5555
"slug": "patches",
5656
"category": 2,
5757
"position": 3,
@@ -67,7 +67,7 @@
6767
"model": "dashboard.tracticketmetric",
6868
"pk": 3,
6969
"fields": {
70-
"name": "Doc. patches needing review",
70+
"name": "Doc. PRs needing review",
7171
"slug": "doc-patches",
7272
"category": 2,
7373
"position": 4,
@@ -165,7 +165,7 @@
165165
"fields": {
166166
"name": "\"Easy\" tickets",
167167
"slug": "easy-tickets",
168-
"category": 2,
168+
"category": 4,
169169
"position": 1,
170170
"show_on_dashboard": true,
171171
"show_sparkline": true,

dashboard/fixtures/dashboard_test_data.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{
1111
"fields": {
1212
"position": 2,
13-
"name": "Patches"
13+
"name": "Pull requests"
1414
},
1515
"model": "dashboard.category",
1616
"pk": 2
@@ -51,7 +51,7 @@
5151
"fields": {
5252
"category": 2,
5353
"show_on_dashboard": true,
54-
"name": "Patches needing review",
54+
"name": "PRs needing review",
5555
"period": "instant",
5656
"show_sparkline": true,
5757
"query": "status=!closed&needs_better_patch=0&needs_tests=0&needs_docs=0&has_patch=1&stage=Accepted",
@@ -67,7 +67,7 @@
6767
"fields": {
6868
"category": 2,
6969
"show_on_dashboard": true,
70-
"name": "Doc. patches needing review",
70+
"name": "Doc. PRs needing review",
7171
"period": "instant",
7272
"show_sparkline": true,
7373
"query": "status=!closed&needs_better_patch=0&component=Documentation&needs_tests=0&needs_docs=0&has_patch=1&stage=Accepted",
@@ -161,7 +161,7 @@
161161
},
162162
{
163163
"fields": {
164-
"category": 2,
164+
"category": 4,
165165
"show_on_dashboard": true,
166166
"name": "\"Easy\" tickets",
167167
"period": "instant",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from django.db import migrations
2+
3+
CATEGORY_RENAMES = {
4+
# old name: new name
5+
"Patches": "Pull requests",
6+
}
7+
8+
TRACMETRIC_RENAMES = {
9+
# old name: new name
10+
"Patches needing review": "Tickets with PRs needing review",
11+
"Doc. patches needing review": "Doc. tickets with PRs needing review",
12+
}
13+
14+
CATEGORY_CHANGES = {
15+
# Metric name: (old category, new category)
16+
"\"Easy\" tickets": ("Patches", "Accepted tickets by type"),
17+
}
18+
19+
20+
def _reverse(d):
21+
"""
22+
Reverse the given dict (values become keys and vice-versa).
23+
"""
24+
return {v: k for k, v in d.items()}
25+
26+
27+
def rename(apps, schema_editor):
28+
Category = apps.get_model("dashboard", "Category")
29+
TracTicketMetric = apps.get_model("dashboard", "TracTicketMetric")
30+
31+
for metric, (old, new) in CATEGORY_CHANGES.items():
32+
new_category = Category.objects.filter(name=new).first()
33+
if not new_category:
34+
continue
35+
metrics = TracTicketMetric.objects.filter(name=metric, category__name=old)
36+
metrics.update(category=new_category)
37+
38+
for old, new in CATEGORY_RENAMES.items():
39+
Category.objects.filter(name=old).update(name=new)
40+
41+
for old, new in TRACMETRIC_RENAMES.items():
42+
TracTicketMetric.objects.filter(name=old).update(name=new)
43+
44+
45+
def rename_backwards(apps, schema_editor):
46+
Category = apps.get_model("dashboard", "Category")
47+
TracTicketMetric = apps.get_model("dashboard", "TracTicketMetric")
48+
49+
for old, new in _reverse(TRACMETRIC_RENAMES).items():
50+
TracTicketMetric.objects.filter(name=old).update(name=new)
51+
52+
for old, new in _reverse(CATEGORY_RENAMES).items():
53+
Category.objects.filter(name=old).update(name=new)
54+
55+
for metric, (new, old) in CATEGORY_CHANGES.items():
56+
new_category = Category.objects.filter(name=new).first()
57+
if not new_category:
58+
continue
59+
metrics = TracTicketMetric.objects.filter(name=metric, category__name=old)
60+
metrics.update(category=new_category)
61+
62+
63+
class Migration(migrations.Migration):
64+
65+
dependencies = [
66+
('dashboard', '0002_delete_rssfeedmetric_create_githubsearchcountmetric'),
67+
]
68+
69+
operations = [
70+
migrations.RunPython(rename, rename_backwards),
71+
]

0 commit comments

Comments
 (0)