Skip to content

Commit

Permalink
Audit: Fix get current working directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jun 16, 2024
1 parent 214e153 commit c7ed7ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit c7ed7ff

Please sign in to comment.