Skip to content

Commit 70fd0de

Browse files
committed
Improves flavor suggestions logic
Updates flavor suggestion logic to return a list containing both new flavor suggestions and matching flavors. This change ensures that users are always presented with the option to request a new flavor, alongside any existing flavor suggestions. It also fixes an error in the footer summary when presenting new flavor suggestion.
1 parent db1533f commit 70fd0de

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

megalinter/flavor_factory.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ def check_active_linters_match_flavor(active_linters, request_id):
131131

132132
# Compare active linters with available flavors to make suggestions to improve CI performances
133133
def get_megalinter_flavor_suggestions(active_linters):
134-
flavor = get_image_flavor()
135-
if flavor != "all":
136-
return None
137134
all_flavors = get_all_flavors()
138135
matching_flavors = []
139136
for flavor_id, flavor_info in all_flavors.items():
@@ -152,19 +149,23 @@ def get_megalinter_flavor_suggestions(active_linters):
152149
"linters_number": len(flavor_info["linters"]),
153150
}
154151
matching_flavors += [matching_flavor]
155-
if len(matching_flavors) > 0:
156-
# There are matching flavors
157-
return sorted(
158-
matching_flavors, key=lambda i: (i["linters_number"], i["flavor"])
159-
)
160-
# Propose user to request a new flavor for the list of linters
152+
153+
results = []
161154

155+
# Propose user to request a new flavor for the list of linters
162156
new_flavor_linters = filter(
163157
lambda linter: linter.ignore_for_flavor_suggestions is False,
164158
active_linters,
165159
)
166160
new_flavor_linters_names = map(lambda linter: linter.name, new_flavor_linters)
167-
return ["new", new_flavor_linters_names]
161+
results += [new_flavor_linters_names]
162+
163+
if len(matching_flavors) > 0:
164+
# There are matching flavors
165+
results += sorted(
166+
matching_flavors, key=lambda i: (i["linters_number"], i["flavor"])
167+
)
168+
return results
168169

169170

170171
def are_all_repository_linters(linter_names: list[str]) -> bool:

megalinter/utils_reporter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,10 @@ def build_markdown_summary_footer(reporter_self, action_run_url=""):
208208
+ "You could have the same capabilities but better runtime performances"
209209
" if you use a MegaLinter flavor:" + os.linesep
210210
)
211+
counter = 0
211212
for suggestion in reporter_self.master.flavor_suggestions:
212-
if suggestion == "new":
213+
counter += 1
214+
if counter == 1:
213215
continue
214216
build_version = config.get(None, "BUILD_VERSION", DEFAULT_RELEASE)
215217
action_version = (

0 commit comments

Comments
 (0)