<commit_before># 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/.

from auto_nag.bzcleaner import BzCleaner


class RegressionButEnhancementTask(BzCleaner):
    def description(self):
        return (
            'Enhancement or task with the "regression", "crash" or "assertion" keyword'
        )

    def get_bz_params(self, date):
        days_lookup = self.get_config("days_lookup")
        params = {
            "resolution": ["---", "FIXED"],
            "keywords": ["regression", "crash", "assertion"],
            "keywords_type": "anywords",
            "bug_type": ["task", "enhancement"],
            "f1": "days_elapsed",
            "o1": "lessthan",
            "v1": days_lookup,
        }
        return params

    def get_autofix_change(self):
        return {"type": "defect"}


if __name__ == "__main__":
    RegressionButEnhancementTask().run()<commit_msg>[regression_but_type_enhancement_task] Justify changing the bug type (#1722)<commit_after># 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/.

from auto_nag import utils
from auto_nag.bzcleaner import BzCleaner

TARGET_KEYWORDS = ["regression", "crash", "assertion"]


class RegressionButEnhancementTask(BzCleaner):
    def description(self):
        return (
            'Enhancement or task with the "regression", "crash" or "assertion" keyword'
        )

    def get_bz_params(self, date):
        days_lookup = self.get_config("days_lookup")
        params = {
            "include_fields": ["keywords"],
            "resolution": ["---", "FIXED"],
            "keywords": TARGET_KEYWORDS,
            "keywords_type": "anywords",
            "bug_type": ["task", "enhancement"],
            "f1": "days_elapsed",
            "o1": "lessthan",
            "v1": days_lookup,
        }
        return params

    def handle_bug(self, bug, data):
        bugid = str(bug["id"])

        keywords = [
            f"`{keyword}`" for keyword in bug["keywords"] if keyword in TARGET_KEYWORDS
        ]

        self.autofix_changes[bugid] = {
            "type": "defect",
            "comment": {
                "body": (
                    f"This bug has the {utils.plural('keyword', keywords)} "
                    f"{utils.english_list(keywords)}, so its type should be defect."
                )
            },
        }

        return bug


if __name__ == "__main__":
    RegressionButEnhancementTask().run()
{'fraction_non_alphanumeric': 0.12444279346210996, 'fraction_numerical': 0.006686478454680535, 'mean_word_length': 2.296205630354957, 'pattern_counts': {'":': 21, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '370054', 'n_tokens_mistral': 846, 'n_tokens_neox': 799, 'n_words': 220}