|
5 | 5 |
|
6 | 6 | def create_missing_tags_and_map_topics(apps, schema_editor): |
7 | 7 | """ |
8 | | - Create missing tags and map existing topics to appropriate tags |
| 8 | + Create missing tags and map existing topics to appropriate tags. |
| 9 | + Only applies to patches in active (open or in-progress) commitfests. |
9 | 10 | """ |
10 | 11 | Tag = apps.get_model("commitfest", "Tag") |
11 | 12 | Patch = apps.get_model("commitfest", "Patch") |
12 | 13 | Topic = apps.get_model("commitfest", "Topic") |
| 14 | + PatchOnCommitFest = apps.get_model("commitfest", "PatchOnCommitFest") |
| 15 | + |
| 16 | + # CommitFest status constants (matching models.py) |
| 17 | + STATUS_OPEN = 2 |
| 18 | + STATUS_INPROGRESS = 3 |
13 | 19 |
|
14 | 20 | # Create missing tags |
15 | 21 | Tag.objects.get_or_create( |
@@ -46,14 +52,23 @@ def create_missing_tags_and_map_topics(apps, schema_editor): |
46 | 52 | # 'Miscellaneous' and 'Server Features' are left untagged |
47 | 53 | } |
48 | 54 |
|
| 55 | + # Get patch IDs that are in active commitfests (open or in-progress) |
| 56 | + active_patch_ids = set( |
| 57 | + PatchOnCommitFest.objects.filter( |
| 58 | + commitfest__status__in=[STATUS_OPEN, STATUS_INPROGRESS] |
| 59 | + ).values_list("patch_id", flat=True) |
| 60 | + ) |
| 61 | + |
49 | 62 | # Apply tags to existing patches based on their topics |
50 | 63 | for topic_name, tag_name in topic_tag_mapping.items(): |
51 | 64 | try: |
52 | 65 | topic = Topic.objects.get(topic=topic_name) |
53 | 66 | tag = Tag.objects.get(name=tag_name) |
54 | 67 |
|
55 | | - # Get all patches with this topic |
56 | | - patches_with_topic = Patch.objects.filter(topic=topic) |
| 68 | + # Get patches with this topic that are in active commitfests |
| 69 | + patches_with_topic = Patch.objects.filter( |
| 70 | + topic=topic, id__in=active_patch_ids |
| 71 | + ) |
57 | 72 |
|
58 | 73 | # Add the corresponding tag to each patch |
59 | 74 | for patch in patches_with_topic: |
|
0 commit comments