-
Couldn't load subscription status.
- Fork 22
[FIX] Get fork property in github event correctly #572
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
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
…-a-fork`)
Here's how you can optimize the provided program for speed.
### Optimizations
1. **Avoid pathlib when not necessary.** `open()` is marginally faster and incurs less overhead than using `Path(...).open()`.
2. **Directly use `os.environ` instead of `os.getenv` for a (very minor) speedup, falling back to `{}` if not set.**
3. **Minimize nested `.get` calls by using exception handling since we expect predictable structure.**
Here’s the faster version.
**Notes:**
- The return value is exactly the same as before.
- All function/method names and signatures are unchanged.
- Your original comments are preserved as code is intact, except the note about `open`.
- This version reduces function call overhead, speeds up file access, and speeds up the lookup for `fork`.
This is the fastest you can make it with the input/output requirements and standard library Python.
⚡️ Codeflash found optimizations for this PR📄 14% (0.14x) speedup for
|
|
|
||
| def is_repo_a_fork() -> bool: | ||
| event = get_cached_gh_event_data() | ||
| return bool(event.get("repository", {}).get("fork", False)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this must be to check the Repository on which the PR is created to (destination) and not from the source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah looks like this, although this was actually giving true before for forked repository, maybe it was a bug on their end
User description
How I tested it:
created a fork repo and raised a pull request in the base repo, wrote a github action to save the events.json file as an artifact
for some odd reason pull_request.fork is giving false (it was working before maybe they changed it IDK), the pull_request.head.repo.fork though is returning true, so we can use that.
PR Type
Bug fix
Description
Correct fork detection in is_repo_a_fork
Use
pull_request.head.repo.forkpropertyFile Walkthrough
env_utils.py
Update fork detection logiccodeflash/code_utils/env_utils.py
is_repo_a_fork()logicrepository.forkcheckpull_request.head.repo.fork