Skip to content

Commit a57d282

Browse files
authored
chore: improve log message for build checks (#718)
This PR improves the log messages for build checks. Signed-off-by: behnazh-w <behnaz.hassanshahi@oracle.com>
1 parent f17cd4f commit a57d282

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

src/macaron/slsa_analyzer/checks/build_as_code_check.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
257257
if isinstance(ci_service, unparsed_ci):
258258
if tool.ci_deploy_kws[ci_service.name]:
259259
deploy_kw, config_name = ci_service.has_kws_in_config(
260-
tool.ci_deploy_kws[ci_service.name], repo_path=ctx.component.repository.fs_path
260+
tool.ci_deploy_kws[ci_service.name],
261+
build_tool_name=tool.name,
262+
repo_path=ctx.component.repository.fs_path,
261263
)
262264
if not config_name:
263265
break

src/macaron/slsa_analyzer/checks/build_service_check.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ def run_check(self, ctx: AnalyzeContext) -> CheckResultData:
172172
if isinstance(ci_service, unparsed_ci):
173173
if tool.ci_build_kws[ci_service.name]:
174174
build_kw, config_name = ci_service.has_kws_in_config(
175-
tool.ci_build_kws[ci_service.name], repo_path=ctx.component.repository.fs_path
175+
tool.ci_build_kws[ci_service.name],
176+
build_tool_name=tool.name,
177+
repo_path=ctx.component.repository.fs_path,
176178
)
177179
if not config_name:
178180
break

src/macaron/slsa_analyzer/ci_service/base_ci_service.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def build_call_graph(self, repo_path: str, macaron_path: str = "") -> CallGraph:
109109
"""
110110
raise NotImplementedError
111111

112-
def has_kws_in_config(self, kws: list, repo_path: str) -> tuple[str, str]:
112+
def has_kws_in_config(self, kws: list, build_tool_name: str, repo_path: str) -> tuple[str, str]:
113113
"""Check the content of all config files in a repository for any build keywords.
114114
115115
For now, it only checks the file content directly.
@@ -118,6 +118,8 @@ def has_kws_in_config(self, kws: list, repo_path: str) -> tuple[str, str]:
118118
----------
119119
kws : list
120120
The list of keywords to check.
121+
build_tool_name: str
122+
The name of the target build tool.
121123
repo_path : str
122124
The path to the target repo.
123125
@@ -137,14 +139,15 @@ def has_kws_in_config(self, kws: list, repo_path: str) -> tuple[str, str]:
137139
for index, line in enumerate(file):
138140
if any((keyword := kw) in line for kw in kws):
139141
logger.info(
140-
'Found build command %s at line %s in %s: "%s"',
142+
'Found build command %s for %s at line %s in %s: "%s"',
141143
keyword,
144+
build_tool_name,
142145
index,
143146
config,
144147
line.strip(),
145148
)
146149
return keyword, config
147-
logger.info("No build command found in %s", file_path)
150+
logger.info("No build command found for %s in %s", build_tool_name, file_path)
148151
return "", ""
149152
except FileNotFoundError as error:
150153
logger.debug(error)

tests/slsa_analyzer/ci_service/test_base_ci_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023 - 2023, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2023 - 2024, Oracle and/or its affiliates. All rights reserved.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.
33

44
"""This module tests the base CI service."""
@@ -46,4 +46,4 @@ def test_has_kws_in_config(entry_conf: list[str], kws: list[str], repo_path: str
4646
"""Test has keywords in config check."""
4747
base_ci_service = BaseCIService("base") # type: ignore
4848
base_ci_service.entry_conf = entry_conf
49-
assert base_ci_service.has_kws_in_config(kws=kws, repo_path=repo_path) == expect
49+
assert base_ci_service.has_kws_in_config(kws=kws, build_tool_name="foo", repo_path=repo_path) == expect

0 commit comments

Comments
 (0)