Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit: Fix get current working directory #373

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion github_app_geo_project/module/audit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ async def _snyk_test(
message.title = "Snyk test JSON output"
_LOGGER.debug(message)
else:
_LOGGER.error("Snyk test JSON returned nothing on project %s branch %s", os.getcwd(), branch)
_LOGGER.error(
"Snyk test JSON returned nothing on project %s branch %s", module_utils.get_cwd(), branch
)

test_json = json.loads(test_json_str) if test_json_str else []

Expand Down
14 changes: 13 additions & 1 deletion github_app_geo_project/module/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,18 @@ def ansi_proc_message(
return AnsiProcessMessage.from_process(proc)


def get_cwd() -> str | None:
"""
Get the current working directory.

Did not raise an exception if it does not exist, return None instead.
"""
try:
return os.getcwd()
except FileNotFoundError:
return None


async def run_timeout(
command: list[str],
env: dict[str, str] | None,
Expand Down Expand Up @@ -490,7 +502,7 @@ async def run_timeout(
async with asyncio.timeout(timeout):
async_proc = await asyncio.create_subprocess_exec(
*command,
cwd=cwd or os.getcwd(),
cwd=cwd or get_cwd(),
env=env,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
Expand Down
Loading