<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 libmozdata.bugzilla import Bugzilla

from auto_nag import logger
from auto_nag.bugbug_utils import get_bug_ids_classification
from auto_nag.bzcleaner import BzCleaner
from auto_nag.utils import get_config, nice_round


class Component(BzCleaner):
    def __init__(self):
        super().__init__()
        self.autofix_component = {}
        self.frequency = "daily"

    def add_custom_arguments(self, parser):
        parser.add_argument(
            "--frequency",
            help="Daily (noisy) or Hourly",
            choices=["daily", "hourly"],
            default="daily",
        )

    def parse_custom_arguments(self, args):
        self.frequency = args.frequency

    def description(self):
        return f"[Using ML] Assign a component to untriaged bugs ({self.frequency})"

    def columns(self):
        return ["id", "summary", "component", "confidence", "autofixed"]

    def sort_columns(self):
        return lambda p: (-p[3], -int(p[0]))

    def has_product_component(self):
        # Inject product and components when calling BzCleaner.get_bugs
        return True

    def get_bz_params(self, date):
        start_date, end_date = self.get_dates(date)

        bot = get_config("common", "bot_bz_mail")[0]

        return {
            "include_fields": ["id", "groups", "summary", "product", "component"],
            # Ignore bugs for which we ever modified the product or the component.
            "n1": 1,
            "f1": "product",
            "o1": "changedby",
            "v1": bot,
            "n2": 1,
            "f2": "component",
            "o2": "changedby",
            "v2": bot,
            # Ignore closed bugs.
            "bug_status": "__open__",
            # Get recent General bugs, and all Untriaged bugs.
            "j3": "OR",
            "f3": "OP",
            "j4": "AND",
            "f4": "OP",
            "f5": "component",
            "o5": "equals",
            "v5": "General",
            "f6": "creation_ts",
            "o6": "greaterthan",
            "v6": start_date,
            "f7": "CP",
            "f8": "component",
            "o8": "equals",
            "v8": "Untriaged",
            "f9": "CP",
        }

    def get_bugs(self, date="today", bug_ids=[]):
        # Retrieve the bugs with the fields defined in get_bz_params<commit_msg>Consider bugs filed in the Firefox::Foxfooding as untriaged bugs (#1268)<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 libmozdata.bugzilla import Bugzilla

from auto_nag import logger
from auto_nag.bugbug_utils import get_bug_ids_classification
from auto_nag.bzcleaner import BzCleaner
from auto_nag.utils import get_config, nice_round


class Component(BzCleaner):
    def __init__(self):
        super().__init__()
        self.autofix_component = {}
        self.frequency = "daily"

    def add_custom_arguments(self, parser):
        parser.add_argument(
            "--frequency",
            help="Daily (noisy) or Hourly",
            choices=["daily", "hourly"],
            default="daily",
        )

    def parse_custom_arguments(self, args):
        self.frequency = args.frequency

    def description(self):
        return f"[Using ML] Assign a component to untriaged bugs ({self.frequency})"

    def columns(self):
        return ["id", "summary", "component", "confidence", "autofixed"]

    def sort_columns(self):
        return lambda p: (-p[3], -int(p[0]))

    def has_product_component(self):
        # Inject product and components when calling BzCleaner.get_bugs
        return True

    def get_bz_params(self, date):
        start_date, end_date = self.get_dates(date)

        bot = get_config("common", "bot_bz_mail")[0]

        return {
            "include_fields": ["id", "groups", "summary", "product", "component"],
            # Ignore bugs for which we ever modified the product or the component.
            "n1": 1,
            "f1": "product",
            "o1": "changedby",
            "v1": bot,
            "n2": 1,
            "f2": "component",
            "o2": "changedby",
            "v2": bot,
            # Ignore closed bugs.
            "bug_status": "__open__",
            # Get recent General bugs, and all Untriaged bugs.
            "j3": "OR",
            "f3": "OP",
            "j4": "AND",
            "f4": "OP",
            "f5": "component",
            "o5": "equals",
            "v5": "General",
            "f6": "creation_ts",
            "o6": "greaterthan",
            "v6": start_date,
            "f7": "CP",
            "f8": "component",
            "o8": "anyexact",
            "v8": "Untriaged,Foxfooding",
            "f9": "CP",
        }

    def get_bugs(self, date="today", bug_ids=[]):
        # Retrieve the bugs with the fields defined in get_bz_params
{'fraction_non_alphanumeric': 0.12800620636152055, 'fraction_numerical': 0.013188518231186967, 'mean_word_length': 2.0991586538461537, 'pattern_counts': {'":': 50, '<': 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': '749647', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1542, 'n_words': 446}