Skip to content

Commit 422a994

Browse files
committed
Replace the word "tool" with "rule"
1 parent 3bdec41 commit 422a994

20 files changed

+169
-169
lines changed

.github/workflows/wiki.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ jobs:
1919
with:
2020
python-version: 3.9
2121

22-
- name: Check tools on the wiki page
22+
- name: Check rules on the wiki page
2323
run: python scripts/check_rules_on_wiki.py -ci

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*~
44
.DS_Store
55
configs/*
6-
!configs/tools.json
6+
!configs/rules.json
77
!configs/rm.json
88
!configs/team_managers.json
99
models/

bugbot/bzcleaner.py

+30-30
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323

2424
class TooManyChangesError(Exception):
25-
"""Exception raised when the tool is trying to apply too many changes"""
25+
"""Exception raised when the rule is trying to apply too many changes"""
2626

2727
def __init__(self, bugs, changes, max_changes):
28-
message = f"The tool has been aborted because it was attempting to apply changes on {len(changes)} bugs. Max is {max_changes}."
28+
message = f"The rule has been aborted because it was attempting to apply changes on {len(changes)} bugs. Max is {max_changes}."
2929
super().__init__(message)
3030
self.bugs = bugs
3131
self.changes = changes
@@ -43,15 +43,15 @@ class BzCleaner(object):
4343
no_bugmail: If `True`, a token for an account that does not trigger
4444
bugmail will be used when performing `PUT` actions on Bugzilla.
4545
normal_changes_max: The maximum number of changes that could be made in
46-
a normal situation. If exceeded, the tool will fail.
46+
a normal situation. If exceeded, the rule will fail.
4747
"""
4848

4949
no_bugmail: bool = False
5050
normal_changes_max: int = 50
5151

5252
def __init__(self):
5353
super(BzCleaner, self).__init__()
54-
self._set_tool_name()
54+
self._set_rule_name()
5555
self.apply_autofix = True
5656
self.has_autofix = False
5757
self.autofix_changes = {}
@@ -62,16 +62,16 @@ def __init__(self):
6262
self.cache = Cache(self.name(), self.max_days_in_cache())
6363
self.test_mode = utils.get_config("common", "test", False)
6464
self.versions = None
65-
logger.info("Run tool {}".format(self.get_tool_path()))
65+
logger.info("Run rule {}".format(self.get_rule_path()))
6666

67-
def _set_tool_name(self):
67+
def _set_rule_name(self):
6868
module = sys.modules[self.__class__.__module__]
6969
base = os.path.dirname(__file__)
70-
scripts = os.path.join(base, "scripts")
71-
self.__tool_path__ = os.path.relpath(module.__file__, scripts)
70+
rules = os.path.join(base, "rules")
71+
self.__rule_path__ = os.path.relpath(module.__file__, rules)
7272
name = os.path.basename(module.__file__)
7373
name = os.path.splitext(name)[0]
74-
self.__tool_name__ = name
74+
self.__rule_name__ = name
7575

7676
def init_versions(self):
7777
self.versions = utils.get_checked_versions()
@@ -86,12 +86,12 @@ def description(self):
8686
return ""
8787

8888
def name(self):
89-
"""Get the tool name"""
90-
return self.__tool_name__
89+
"""Get the rule name"""
90+
return self.__rule_name__
9191

92-
def get_tool_path(self):
93-
"""Get the tool path"""
94-
return self.__tool_path__
92+
def get_rule_path(self):
93+
"""Get the rule path"""
94+
return self.__rule_path__
9595

9696
def needinfo_template_name(self):
9797
"""Get the txt template filename"""
@@ -117,7 +117,7 @@ def ignore_date(self):
117117
return False
118118

119119
def must_run(self, date):
120-
"""Check if the tool must run for this date"""
120+
"""Check if the rule must run for this date"""
121121
days = self.get_config("must_run", None)
122122
if not days:
123123
return True
@@ -129,7 +129,7 @@ def must_run(self, date):
129129
return False
130130

131131
def has_enough_data(self):
132-
"""Check if the tool has enough data to run"""
132+
"""Check if the rule has enough data to run"""
133133
if self.versions is None:
134134
# init_versions() has never been called
135135
return True
@@ -166,7 +166,7 @@ def exclude_no_action_bugs(self):
166166
needinfo got ignored due to exceeding the limit). This is applied only
167167
when using the `add_prioritized_action()` method.
168168
169-
Returning `False` could be useful if we want to list all actions the tool
169+
Returning `False` could be useful if we want to list all actions the rule
170170
would do if it had no limits.
171171
"""
172172
return True
@@ -491,7 +491,7 @@ def get_list_bugs(self, bugs):
491491

492492
def get_documentation(self):
493493
return "For more information, please visit [BugBot documentation](https://wiki.mozilla.org/Release_Management/autonag#{}).".format(
494-
self.get_tool_path().replace("/", ".2F")
494+
self.get_rule_path().replace("/", ".2F")
495495
)
496496

497497
def has_bot_set_ni(self, bug):
@@ -613,7 +613,7 @@ def autofix(self, bugs):
613613

614614
@staticmethod
615615
def apply_changes_on_bugzilla(
616-
tool_name: str,
616+
rule_name: str,
617617
new_changes: Dict[str, dict],
618618
no_bugmail: bool = False,
619619
is_dryrun: bool = True,
@@ -622,7 +622,7 @@ def apply_changes_on_bugzilla(
622622
"""Apply changes on Bugzilla
623623
624624
Args:
625-
tool_name: the name of the tool that is performing the changes.
625+
rule_name: the name of the rule that is performing the changes.
626626
new_changes: the changes that will be performed. The dictionary key
627627
should be the bug ID.
628628
no_bugmail: If True, an account that doesn't trigger bugmail will be
@@ -651,12 +651,12 @@ def apply_changes_on_bugzilla(
651651
time.sleep(1)
652652
else:
653653
added = True
654-
db.BugChange.add(tool_name, bugid, extra=db_extra.get(bugid, ""))
654+
db.BugChange.add(rule_name, bugid, extra=db_extra.get(bugid, ""))
655655
break
656656
if not added:
657657
logger.error(
658658
"%s: Cannot put data for bug %s (change => %s): %s",
659-
tool_name,
659+
rule_name,
660660
bugid,
661661
ch,
662662
failures,
@@ -720,7 +720,7 @@ def _send_alert_about_too_many_changes(self, err: TooManyChangesError):
720720
changes=err.changes.items(),
721721
changes_size=len(err.changes),
722722
normal_changes_max=self.normal_changes_max,
723-
tool_name=self.name(),
723+
rule_name=self.name(),
724724
https_proxy=os.environ.get("https_proxy"),
725725
enumerate=enumerate,
726726
table_attrs=self.get_config("table_attrs"),
@@ -755,7 +755,7 @@ def send_email(self, date="today"):
755755
return
756756

757757
if not self.has_enough_data():
758-
logger.info("The tool {} hasn't enough data to run".format(self.name()))
758+
logger.info("The rule {} hasn't enough data to run".format(self.name()))
759759
return
760760

761761
login_info = utils.get_login_info()
@@ -775,7 +775,7 @@ def send_email(self, date="today"):
775775
dryrun=self.dryrun,
776776
)
777777
except Exception:
778-
logger.exception("Tool {}".format(self.name()))
778+
logger.exception("Rule {}".format(self.name()))
779779
status = "Failure"
780780

781781
db.Email.add(self.name(), receivers, "global", status)
@@ -810,7 +810,7 @@ def get_args_parser(self):
810810
dest="is_limited",
811811
action="store_false",
812812
default=True,
813-
help=f"If the flag is not passed, the tool will be limited to touch a maximum of {self.normal_changes_max} bugs",
813+
help=f"If the flag is not passed, the rule will be limited to touch a maximum of {self.normal_changes_max} bugs",
814814
)
815815

816816
if not self.ignore_date():
@@ -828,7 +828,7 @@ def get_args_parser(self):
828828
return parser
829829

830830
def run(self):
831-
"""Run the tool"""
831+
"""Run the rule"""
832832
args = self.get_args_parser().parse_args()
833833
self.parse_custom_arguments(args)
834834
date = "" if self.ignore_date() else args.date
@@ -838,9 +838,9 @@ def run(self):
838838
try:
839839
self.send_email(date=date)
840840
self.terminate()
841-
logger.info("Tool {} has finished.".format(self.get_tool_path()))
841+
logger.info("Rule {} has finished.".format(self.get_rule_path()))
842842
except TooManyChangesError as err:
843843
self._send_alert_about_too_many_changes(err)
844-
logger.exception("Tool %s", self.name())
844+
logger.exception("Rule %s", self.name())
845845
except Exception:
846-
logger.exception("Tool {}".format(self.name()))
846+
logger.exception("Rule {}".format(self.name()))

bugbot/multi_autofixers.py

+35-35
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010
from bugbot.bzcleaner import BzCleaner
1111
from bugbot.nag_me import Nag
1212

13-
ToolsChanges = Dict[Type[BzCleaner], Any]
13+
RulesChanges = Dict[Type[BzCleaner], Any]
1414

1515

16-
class UnexpectedToolsError(Exception):
17-
"""Unexpected tools appear in merge function"""
16+
class UnexpectedRulesError(Exception):
17+
"""Unexpected rules appear in merge function"""
1818

19-
def __init__(self, tools: Iterable[Type[BzCleaner]]) -> None:
19+
def __init__(self, rules: Iterable[Type[BzCleaner]]) -> None:
2020
"""Constructor
2121
2222
Args:
23-
tools: the tools that change the same field.
23+
rules: the rules that change the same field.
2424
"""
2525
super().__init__()
26-
self.tools = tools
26+
self.rules = rules
2727

2828
def __str__(self):
2929
return (
3030
"Error: merge function does not support merge fields "
31-
f"from '{utils.english_list([tool.__name__ for tool in self.tools])}'"
31+
f"from '{utils.english_list([rule.__name__ for rule in self.rules])}'"
3232
)
3333

3434

@@ -49,37 +49,37 @@ def __str__(self):
4949

5050

5151
class MultiAutoFixers:
52-
"Merge changes from multiple tools and apply them to Bugzilla at once"
52+
"Merge changes from multiple rules and apply them to Bugzilla at once"
5353

5454
def __init__(
55-
self, *tools: BzCleaner, **merge_functions: Callable[[ToolsChanges], dict]
55+
self, *rules: BzCleaner, **merge_functions: Callable[[RulesChanges], dict]
5656
):
5757
"""Constructor
5858
5959
Args:
60-
*tools: tools to merge their changes.
60+
*rules: rules to merge their changes.
6161
**merge_functions: functions to merge field values when multiple
62-
tools are changing the same field. The key should be the field
62+
rules are changing the same field. The key should be the field
6363
name.
6464
"""
6565
super().__init__()
66-
for tool in tools:
67-
if isinstance(tool, Nag):
66+
for rule in rules:
67+
if isinstance(rule, Nag):
6868
logger.warning(
6969
"%s implements Nag, however, nag emails will not be merged",
70-
type(tool),
70+
type(rule),
7171
)
72-
self.tools = tools
72+
self.rules = rules
7373
self.merge_functions = merge_functions
7474
self.is_dryrun: bool = True
7575

7676
def description(self):
77-
"""Return a description of the tool"""
78-
return "Grouped changes for the following tools: " + self.name()
77+
"""Return a description of the rule"""
78+
return "Grouped changes for the following rules: " + self.name()
7979

8080
def name(self):
81-
"""Return the name of the tool"""
82-
return utils.english_list([tool.name() for tool in self.tools])
81+
"""Return the name of the rule"""
82+
return utils.english_list([rule.name() for rule in self.rules])
8383

8484
def get_args_parser(self):
8585
"""Get the arguments from the command line"""
@@ -97,34 +97,34 @@ def get_args_parser(self):
9797
return parser
9898

9999
def run(self):
100-
"""Run the tool"""
100+
"""Run the rule"""
101101
args = self.get_args_parser().parse_args()
102102
self.is_dryrun = args.dryrun
103103

104-
for tool in self.tools:
105-
tool.apply_autofix = False
106-
tool.run()
104+
for rule in self.rules:
105+
rule.apply_autofix = False
106+
rule.run()
107107

108-
new_changes = self._merge_changes_from_tools()
109-
no_bugmail = all(tool.no_bugmail for tool in self.tools)
108+
new_changes = self._merge_changes_from_rules()
109+
no_bugmail = all(rule.no_bugmail for rule in self.rules)
110110

111111
BzCleaner.apply_changes_on_bugzilla(
112112
self.name(), new_changes, no_bugmail, self.is_dryrun, db_extra={}
113113
)
114114

115-
def _merge_changes_from_tools(self) -> Dict[str, dict]:
115+
def _merge_changes_from_rules(self) -> Dict[str, dict]:
116116
all_changes: Dict[str, dict] = defaultdict(dict)
117-
for tool in self.tools:
118-
for bugid, changes in tool.autofix_changes.items():
119-
all_changes[bugid][tool.__class__] = changes
117+
for rule in self.rules:
118+
for bugid, changes in rule.autofix_changes.items():
119+
all_changes[bugid][rule.__class__] = changes
120120

121-
for bugid, tools in all_changes.items():
121+
for bugid, rules in all_changes.items():
122122
merged_changes = {}
123123

124124
common_fields = (
125125
field
126126
for field, count in Counter(
127-
field for changes in tools.values() for field in changes.keys()
127+
field for changes in rules.values() for field in changes.keys()
128128
).items()
129129
if count > 1
130130
)
@@ -133,13 +133,13 @@ def _merge_changes_from_tools(self) -> Dict[str, dict]:
133133
if field not in self.merge_functions:
134134
raise MissingMergeFunctionError(field)
135135

136-
tools_with_common_field = {
137-
tool: changes for tool, changes in tools.items() if field in changes
136+
rules_with_common_field = {
137+
rule: changes for rule, changes in rules.items() if field in changes
138138
}
139139
merged_changes[field] = self.merge_functions[field](
140-
tools_with_common_field
140+
rules_with_common_field
141141
)
142142

143-
all_changes[bugid] = dict(ChainMap(merged_changes, *tools.values()))
143+
all_changes[bugid] = dict(ChainMap(merged_changes, *rules.values()))
144144

145145
return all_changes

bugbot/nag_me.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def send_mails(self, title, dryrun=False):
185185
dryrun=dryrun,
186186
)
187187
except Exception:
188-
logger.exception("Tool {}".format(self.name()))
188+
logger.exception("Rule {}".format(self.name()))
189189
status = "Failure"
190190

191191
db.Email.add(self.name(), receivers, "individual", status)

bugbot/round_robin_fallback.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ def check_people(date, dryrun=False):
4949
try:
5050
check_people(args.date, dryrun=args.dryrun)
5151
except Exception:
52-
logger.exception("Tool round_robin_fallback")
52+
logger.exception("Rule round_robin_fallback")

bugbot/rules/fuzz_blockers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def get_mail_to_auto_ni(self, bug):
4343

4444
@staticmethod
4545
def _is_commented(bug: dict) -> bool:
46-
"""Get whether the bug has a previous comment by this tool"""
46+
"""Get whether the bug has a previous comment by this rule"""
4747
for comment in reversed(bug["comments"]):
4848
if comment["creator"] == History.BOT and comment["raw_text"].startswith(
4949
"This bug prevents fuzzing from making progress"

0 commit comments

Comments
 (0)