[FIX] skip draft pr optimization (CF-667)#322
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
…ization-for-draft-prs`) Here’s a faster, more memory-efficient rewrite of your program. Optimizations include. - Removed duplicate `get_pr_number` import and moved/corrected its singleton responsibility. - Used direct, local variable access rather than repeatedly referencing imported modules. - Used `os.environ[]` instead of `os.environ.get` for critical env lookups in a try-block (avoids lookup cost when you know failure will land in except anyway). - Used direct file open for reading (avoiding Path overhead). - Avoided reading/parsing JSON and dictionary keys if the PR number/env is missing. - Reduced exception handling scope to only JSON/file-related operations. All existing comments are preserved except where the code was made more efficient. **Key points:** - File reading is done only if both env vars are present, before JSON parsing. - The exception only wraps file I/O + JSON parsing, not the env checks, so it's tighter/faster in normal runs. - No `Path`. Used built-in open for speed. - Early returns for failures, so the function does the minimum work necessary. - Single access to environment variables (no redundancy). **Functional output is preserved.**
⚡️ Codeflash found optimizations for this PR📄 35% (0.35x) speedup for
|
| return | ||
|
|
||
| if is_pr_draft(): | ||
| logger.warning("PR is in draft mode, skipping optimization") |
There was a problem hiding this comment.
Q: Will the logger.warning logs visible in non debug mode in GHA?
There was a problem hiding this comment.
yes, it should, the default level is "INFO"
User description
PR Type
Bug fix, Enhancement
Description
Add get_pr_info CFAPI client method
Retrieve PR info before optimization
Skip optimization for draft pull requests
Warn when PR missing or in draft
Changes walkthrough 📝
cfapi.py
Add get_pr_info CFAPI methodcodeflash/api/cfapi.py
optimizer.py
Skip draft PR optimizationcodeflash/optimization/optimizer.py