Skip to content
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
2 changes: 2 additions & 0 deletions codeflash/cli_cmds/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def parse_args() -> Namespace:
type=str,
help="Path to the directory of the project, where all the pytest-benchmark tests are located.",
)
parser.add_argument("--no-draft", default=False, action="store_true", help="Skip optimization for draft PRs")

args: Namespace = parser.parse_args()
return process_and_validate_cmd_args(args)

Expand Down
21 changes: 21 additions & 0 deletions codeflash/optimization/optimizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import ast
import json
import os
import tempfile
import time
Expand Down Expand Up @@ -86,6 +87,11 @@ def run(self) -> None:
return
if not env_utils.check_formatter_installed(self.args.formatter_cmds):
return

if self.args.no_draft and is_pr_draft():
logger.warning("PR is in draft mode, skipping optimization")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Will the logger.warning logs visible in non debug mode in GHA?

Copy link
Contributor Author

@mohammedahmed18 mohammedahmed18 Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it should, the default level is "INFO"

return

function_optimizer = None
file_to_funcs_to_optimize: dict[Path, list[FunctionToOptimize]]
num_optimizable_functions: int
Expand Down Expand Up @@ -301,3 +307,18 @@ def run_with_args(args: Namespace) -> None:
optimizer.cleanup_temporary_paths()

raise SystemExit from None


def is_pr_draft() -> bool:
"""Check if the PR is draft. in the github action context."""
try:
event_path = os.getenv("GITHUB_EVENT_PATH")
pr_number = get_pr_number()
if pr_number is not None and event_path:
with Path(event_path).open() as f:
event_data = json.load(f)
return bool(event_data["pull_request"]["draft"])
return False # noqa
except Exception as e:
logger.warning(f"Error checking if PR is draft: {e}")
return False
Loading