[duplicate_copy_metadata] Copy WebCompat Priority flag (#1883)

Co-authored-by: Marco Castelluccio <mcastelluccio@mozilla.com>
This commit is contained in:
Suhaib Mujahid 2023-02-17 08:37:12 -05:00 коммит произвёл GitHub
Родитель 34aab06321
Коммит e2b4f8d62f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 112 добавлений и 0 удалений

Просмотреть файл

@ -9,6 +9,7 @@ from libmozdata.bugzilla import Bugzilla
from auto_nag import utils
from auto_nag.bzcleaner import BzCleaner
from auto_nag.history import History
from auto_nag.webcompat_priority import WebcompatPriority
FIELD_NAME_TO_LABEL = {
"keywords": "Keywords",
@ -17,6 +18,7 @@ FIELD_NAME_TO_LABEL = {
"cf_performance_impact": "Performance Impact",
"regressed_by": "Regressed by",
"status": "Status",
"cf_webcompat_priority": "Webcompat Priority",
}
FIELD_LABEL_TO_NAME = {label: name for name, label in FIELD_NAME_TO_LABEL.items()}
@ -52,6 +54,7 @@ class DuplicateCopyMetadata(BzCleaner):
"status",
"regressed_by",
"is_open",
"cf_webcompat_priority",
],
bughandler=self.handle_bug,
bugdata=original_bugs,
@ -115,6 +118,39 @@ class DuplicateCopyMetadata(BzCleaner):
}
elif new_access_tag == copied_fields["whiteboard"]["value"]:
copied_fields["whiteboard"]["from"].append(dup_bug["id"])
# Webcompat Priority: copy the `cf_webcompat_priority` from duplicates
if (
bug.get("cf_webcompat_priority") == "---"
and dup_bug.get("cf_webcompat_priority")
in WebcompatPriority.NOT_EMPTY_VALUES
):
new_priority = dup_bug["cf_webcompat_priority"]
# Since the bug does not have a priority, it does not make
# sense to set it to `revisit`. Instead, we set it to `?` to
# request triage.
if new_priority == "revisit":
new_priority = "?"
if (
"cf_webcompat_priority" not in copied_fields
or WebcompatPriority(new_priority)
> WebcompatPriority(
copied_fields["cf_webcompat_priority"]["value"]
)
):
copied_fields["cf_webcompat_priority"] = {
"from": [dup_bug["id"]],
"value": new_priority,
}
elif (
new_priority == copied_fields["cf_webcompat_priority"]["value"]
):
copied_fields["cf_webcompat_priority"]["from"].append(
dup_bug["id"]
)
# Status: confirm the bug if the duplicate was confirmed
if bug["status"] == "UNCONFIRMED" and self.was_confirmed(dup_bug):
if "status" not in copied_fields:
@ -198,6 +234,8 @@ class DuplicateCopyMetadata(BzCleaner):
autofix["whiteboard"] = bug["whiteboard"] + value
elif field == "cf_performance_impact":
autofix["cf_performance_impact"] = value
elif field == "cf_webcompat_priority":
autofix["cf_webcompat_priority"] = value
elif field == "status":
autofix["status"] = value
elif field == "regressed_by":
@ -306,6 +344,7 @@ class DuplicateCopyMetadata(BzCleaner):
"cf_performance_impact",
"dupe_of",
"regressed_by",
"cf_webcompat_priority",
]
params = {
@ -318,6 +357,7 @@ class DuplicateCopyMetadata(BzCleaner):
"status_whiteboard",
"cf_performance_impact",
"regressed_by",
"cf_webcompat_priority",
],
}

Просмотреть файл

@ -0,0 +1,26 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import unittest
from auto_nag.webcompat_priority import WebcompatPriority
class TestWebcompatPriority(unittest.TestCase):
def test_logical_comparison(self):
self.assertTrue(WebcompatPriority("--") == WebcompatPriority("?"))
self.assertTrue(WebcompatPriority("--") == WebcompatPriority("revisit"))
self.assertTrue(WebcompatPriority("--") == WebcompatPriority("-"))
self.assertGreater(WebcompatPriority("P1"), WebcompatPriority("P2"))
self.assertGreater(WebcompatPriority("P2"), WebcompatPriority("P3"))
self.assertGreater(WebcompatPriority("P3"), WebcompatPriority("-"))
self.assertGreater(WebcompatPriority("P3"), WebcompatPriority("--"))
self.assertGreater(WebcompatPriority("P3"), WebcompatPriority("?"))
self.assertGreater(WebcompatPriority("P3"), WebcompatPriority("revisit"))
self.assertFalse(WebcompatPriority("--") > WebcompatPriority("-"))
self.assertFalse(WebcompatPriority("--") < WebcompatPriority("-"))
self.assertFalse(WebcompatPriority("P1") == WebcompatPriority("P2"))
self.assertFalse(WebcompatPriority("P1") < WebcompatPriority("P2"))

Просмотреть файл

@ -0,0 +1,46 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
class WebcompatPriority:
"""Webcompat priority Class
This class is to be used to compare webcompat priority values.
"""
PRIORITY_LEVELS = {"P1", "P2", "P3"}
TRIAGE_REQUIRED_VALUES = {"?", "revisit"}
EMPTY_VALUES = {"--", "-"}
NOT_EMPTY_VALUES = PRIORITY_LEVELS | TRIAGE_REQUIRED_VALUES
ACCEPTED_VALUES = NOT_EMPTY_VALUES | EMPTY_VALUES
def __init__(self, priority):
"""Constructor
prams:
severity: the severity of the bug
"""
assert priority in self.ACCEPTED_VALUES, "Invalid priority"
self._value = priority
def __bool__(self) -> bool:
return self._value in self.PRIORITY_LEVELS
def __eq__(self, other) -> bool:
return self._value == other._value or (not self and not other)
def __lt__(self, other) -> bool:
if not self and other:
return True
if self and not other or self == other:
return False
return self._value > other._value
def __str__(self) -> str:
return self._value
def __repr__(self) -> str:
return f"<WebcompatPriority( {self._value} )>"