Skip to content

Commit 447edb3

Browse files
authored
Merge pull request #1316 from okorach:fix-rule-filters
Fix rule filtering
2 parents 3764f92 + e92a001 commit 447edb3

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

cli/rules_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def main() -> int:
7676
params = {}
7777
if options.LANGUAGES in kwargs:
7878
params = {"languages": util.list_to_csv(kwargs[options.LANGUAGES])}
79-
rule_list = rules.get_list(endpoint=endpoint, **params)
79+
rule_list = rules.get_list(endpoint=endpoint, use_cache=False, **params)
8080

8181
try:
8282
if fmt == "csv":

sonar/rules.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ def count(endpoint: platform.Platform, **params) -> int:
249249
return json.loads(endpoint.get(Rule.SEARCH_API, params={**params, "ps": 1}).text)["total"]
250250

251251

252-
def get_list(endpoint: platform.Platform, **params) -> dict[str, Rule]:
252+
def get_list(endpoint: platform.Platform, use_cache: bool = True, **params) -> dict[str, Rule]:
253253
"""Returns a list of rules corresponding to certain csearch filters"""
254-
if len(_OBJECTS) < 100:
254+
if not use_cache or params or len(_OBJECTS) < 100:
255255
return search(endpoint, include_external="false", **params)
256256
return _OBJECTS
257257

@@ -276,7 +276,7 @@ def export(endpoint: platform.Platform, export_settings: types.ConfigSettings, k
276276
log.info("Exporting rules")
277277
full = export_settings.get("FULL_EXPORT", False)
278278
rule_list, other_rules, instantiated_rules, extended_rules = {}, {}, {}, {}
279-
for rule_key, rule in get_list(endpoint=endpoint).items():
279+
for rule_key, rule in get_list(endpoint=endpoint, use_cache=False).items():
280280
rule_export = rule.export(full)
281281
if rule.template_key is not None:
282282
instantiated_rules[rule_key] = rule_export
@@ -310,7 +310,7 @@ def import_config(endpoint: platform.Platform, config_data: types.ObjectJsonRepr
310310
if endpoint.is_sonarcloud():
311311
raise exceptions.UnsupportedOperation("Can't import rules in SonarCloud")
312312
log.info("Importing customized (custom tags, extended description) rules")
313-
get_list(endpoint=endpoint)
313+
get_list(endpoint=endpoint, use_cache=False)
314314
for key, custom in config_data["rules"].get("extended", {}).items():
315315
try:
316316
rule = Rule.get_object(endpoint, key)
@@ -320,8 +320,6 @@ def import_config(endpoint: platform.Platform, config_data: types.ObjectJsonRepr
320320
rule.set_description(custom.get("description", ""))
321321
rule.set_tags(utilities.csv_to_list(custom.get("tags", None)))
322322

323-
log.debug("get_list from import")
324-
get_list(endpoint=endpoint, templates=True)
325323
log.info("Importing custom rules (instantiated from rule templates)")
326324
for key, instantiation_data in config_data["rules"].get("instantiated", {}).items():
327325
try:

0 commit comments

Comments
 (0)