mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 04:21:52 +00:00
fix(github_actions): resolve CodeQL warnings for return type mismatches
Fixed two CodeQL static analysis warnings: 1. _extract_workflow_file_from_location: Changed return type from str to str | None to match actual behavior where None is returned in error cases 2. _clone_repository: Added unreachable return statement after sys.exit(1) to satisfy static analysis requirements All tests pass after these changes.
This commit is contained in:
@@ -126,7 +126,9 @@ class GithubActionsProvider(Provider):
|
||||
"""GitHub Actions provider doesn't need a session since it uses zizmor directly"""
|
||||
return None
|
||||
|
||||
def _should_exclude_workflow(self, workflow_file: str, exclude_patterns: list[str]) -> bool:
|
||||
def _should_exclude_workflow(
|
||||
self, workflow_file: str, exclude_patterns: list[str]
|
||||
) -> bool:
|
||||
"""
|
||||
Check if a workflow file should be excluded based on exclude patterns.
|
||||
|
||||
@@ -146,23 +148,28 @@ class GithubActionsProvider(Provider):
|
||||
|
||||
# Get just the filename from the path
|
||||
from os.path import basename
|
||||
|
||||
filename = basename(workflow_file)
|
||||
|
||||
# Check if the pattern matches either the full path or just the filename
|
||||
for pattern in exclude_patterns:
|
||||
# Try matching against full path first
|
||||
if fnmatch(workflow_file, pattern):
|
||||
logger.debug(f"Excluding workflow {workflow_file} (matches full path pattern: {pattern})")
|
||||
logger.debug(
|
||||
f"Excluding workflow {workflow_file} (matches full path pattern: {pattern})"
|
||||
)
|
||||
return True
|
||||
|
||||
# Also try matching against just the filename for convenience
|
||||
if fnmatch(filename, pattern):
|
||||
logger.debug(f"Excluding workflow {workflow_file} (matches filename pattern: {pattern})")
|
||||
logger.debug(
|
||||
f"Excluding workflow {workflow_file} (matches filename pattern: {pattern})"
|
||||
)
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def _extract_workflow_file_from_location(self, location: dict) -> str:
|
||||
def _extract_workflow_file_from_location(self, location: dict) -> str | None:
|
||||
"""
|
||||
Extract the workflow file path from a location object.
|
||||
Supports zizmor v1.x+ JSON format.
|
||||
@@ -355,6 +362,7 @@ class GithubActionsProvider(Provider):
|
||||
f"{error.__class__.__name__}:{error.__traceback__.tb_lineno} -- {error}"
|
||||
)
|
||||
sys.exit(1)
|
||||
return "" # Unreachable, but satisfies static analysis
|
||||
|
||||
def run(self) -> List[CheckReportGithubAction]:
|
||||
temp_dir = None
|
||||
@@ -470,7 +478,9 @@ class GithubActionsProvider(Provider):
|
||||
)
|
||||
if workflow_file:
|
||||
# Check if this workflow should be excluded
|
||||
if self._should_exclude_workflow(workflow_file, exclude_workflows):
|
||||
if self._should_exclude_workflow(
|
||||
workflow_file, exclude_workflows
|
||||
):
|
||||
continue
|
||||
|
||||
report = self._process_zizmor_finding(
|
||||
|
||||
Reference in New Issue
Block a user