Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1724 -- Renamed "patch" to "pull request" #1729

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
]