Skip to content

Commit a5eb755

Browse files
check if pr is draft or not through GITHUB_EVENT_PATH
1 parent a8f93bc commit a5eb755

File tree

2 files changed

+9
-26
lines changed

2 files changed

+9
-26
lines changed

codeflash/api/cfapi.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,3 @@ def mark_optimization_success(trace_id: str, *, is_optimization_found: bool) ->
250250
"""
251251
payload = {"trace_id": trace_id, "is_optimization_found": is_optimization_found}
252252
return make_cfapi_request(endpoint="/mark-as-success", method="POST", payload=payload)
253-
254-
255-
def get_pr_info(owner: str, repo: str, pr_number: int) -> Any: # noqa
256-
"""Get information about a pull request."""
257-
response = make_cfapi_request(
258-
endpoint=f"/get-pr-info?owner={owner}&repo={repo}&pr_number={pr_number}", method="GET"
259-
)
260-
if response.ok:
261-
return response.json()
262-
return None

codeflash/optimization/optimizer.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
from __future__ import annotations
22

33
import ast
4+
import json
45
import os
56
import tempfile
67
import time
78
from collections import defaultdict
89
from pathlib import Path
910
from typing import TYPE_CHECKING
1011

11-
import git
12-
13-
from codeflash.api import cfapi
1412
from codeflash.api.aiservice import AiServiceClient, LocalAiServiceClient
1513
from codeflash.cli_cmds.console import console, logger, progress_bar
1614
from codeflash.code_utils import env_utils
1715
from codeflash.code_utils.env_utils import get_pr_number
18-
from codeflash.code_utils.git_utils import get_repo_owner_and_name
1916
from codeflash.either import is_successful
2017
from codeflash.models.models import ValidCode
2118
from codeflash.telemetry.posthog_cf import ph
@@ -314,17 +311,13 @@ def run_with_args(args: Namespace) -> None:
314311

315312
def is_pr_draft() -> bool:
316313
try:
317-
repo = git.Repo(search_parent_directories=True)
318-
owner, repo_name = get_repo_owner_and_name(repo)
319-
314+
event_path = os.getenv("GITHUB_EVENT_PATH")
320315
pr_number = get_pr_number()
321-
if pr_number is not None:
322-
pr_info = cfapi.get_pr_info(owner, repo_name, pr_number)
323-
if pr_info is None:
324-
logger.warning(f"Could not find {owner}/{repo}#{pr_number}.")
325-
return False
326-
is_draft = pr_info["draft"]
327-
if is_draft:
328-
return True
329-
except git.exc.InvalidGitRepositoryError:
316+
if pr_number is not None and event_path:
317+
with Path(event_path).open() as f:
318+
event_data = json.load(f)
319+
return event_data["pull_request"]["draft"]
320+
return False # noqa
321+
except Exception as e:
322+
logger.warning(f"Error checking if PR is draft: {e}")
330323
return False

0 commit comments

Comments
 (0)