in bugbot/rules/duplicate_copy_metadata.py [0:0]
def set_autofix(self, bug: dict, copied_fields: List[tuple]) -> None:
"""Set the autofix for a bug
Args:
bug: The bug to set the autofix for.
copied_fields: The list of copied fields with their values and the
bugs they were copied from (field, value, source).
"""
bug_id = str(bug["id"])
autofix: Dict[str, Any] = {}
duplicates = {id for _, _, source in copied_fields for id in source}
# NOTE: modifying the following comment template should also be
# reflected in the `get_previously_copied_fields` method.
comment = (
f"The following {utils.plural('field has', copied_fields, 'fields have')} been copied "
f"from {utils.plural('a duplicate bug', duplicates, 'duplicate bugs')}:\n\n"
"| Field | Value | Source |\n"
"| ----- | ----- | ------ |\n"
)
for field, value, source in copied_fields:
if field == "keywords":
autofix["keywords"] = {"add": [value]}
elif field == "cf_accessibility_severity":
autofix["cf_accessibility_severity"] = 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":
autofix["regressed_by"] = {"add": list(value)}
value = utils.english_list(sorted(f"bug {id}" for id in value))
else:
raise ValueError(f"Unsupported field: {field}")
field_label = FIELD_NAME_TO_LABEL[field]
source = utils.english_list(sorted(f"bug {id}" for id in source))
comment += f"| {field_label} | {value} | {source} |\n"
comment += "\n\n" + self.get_documentation()
autofix["comment"] = {"body": comment}
# The following is to reduce noise by having the bot to comme later to
# add the `regression` keyword.
if "regressed_by" in autofix and "regression" not in bug["keywords"]:
if "keywords" not in autofix:
autofix["keywords"] = {"add": ["regression"]}
else:
autofix["keywords"]["add"].append("regression")
self.autofix_changes[bug_id] = autofix