Skip to content
Closed
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
11 changes: 8 additions & 3 deletions codeflash/code_utils/env_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,21 @@ def is_end_to_end() -> bool:

@lru_cache(maxsize=1)
def get_cached_gh_event_data() -> dict[str, Any]:
event_path = os.getenv("GITHUB_EVENT_PATH")
event_path = os.environ.get("GITHUB_EVENT_PATH")
if not event_path:
return {}
with Path(event_path).open() as f:
# Use built-in open for less overhead
with open(event_path) as f:
return json.load(f) # type: ignore # noqa


def is_repo_a_fork() -> bool:
event = get_cached_gh_event_data()
return bool(event.get("pull_request", {}).get("head", {}).get("repo", {}).get("fork", False))
try:
# Access nested keys directly for speed; fallback to False
return bool(event["pull_request"]["head"]["repo"]["fork"])
except (KeyError, TypeError):
return False


@lru_cache(maxsize=1)
Expand Down
Loading