|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import ast |
| 4 | +import json |
4 | 5 | import os |
5 | 6 | import tempfile |
6 | 7 | import time |
7 | 8 | from collections import defaultdict |
8 | 9 | from pathlib import Path |
9 | 10 | from typing import TYPE_CHECKING |
10 | 11 |
|
11 | | -import git |
12 | | - |
13 | | -from codeflash.api import cfapi |
14 | 12 | from codeflash.api.aiservice import AiServiceClient, LocalAiServiceClient |
15 | 13 | from codeflash.cli_cmds.console import console, logger, progress_bar |
16 | 14 | from codeflash.code_utils import env_utils |
17 | 15 | from codeflash.code_utils.env_utils import get_pr_number |
18 | | -from codeflash.code_utils.git_utils import get_repo_owner_and_name |
19 | 16 | from codeflash.either import is_successful |
20 | 17 | from codeflash.models.models import ValidCode |
21 | 18 | from codeflash.telemetry.posthog_cf import ph |
@@ -314,17 +311,13 @@ def run_with_args(args: Namespace) -> None: |
314 | 311 |
|
315 | 312 | def is_pr_draft() -> bool: |
316 | 313 | 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") |
320 | 315 | 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}") |
330 | 323 | return False |
0 commit comments