Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 0 additions & 1 deletion .github/workflows/codeflash-optimize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
CODEFLASH_AIS_SERVER: prod
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
CODEFLASH_PR_NUMBER: ${{ github.event.number }}
COLUMNS: 110
steps:
- name: 🛎️ Checkout
Expand Down
1 change: 0 additions & 1 deletion codeflash/cli_cmds/workflows/codeflash-optimize.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
runs-on: ubuntu-latest
env:
CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
CODEFLASH_PR_NUMBER: ${{ github.event.number }}
{{ working_directory }}
steps:
- name: 🛎️ Checkout
Expand Down
32 changes: 17 additions & 15 deletions codeflash/code_utils/env_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,22 @@ def ensure_codeflash_api_key() -> bool:

@lru_cache(maxsize=1)
def get_pr_number() -> Optional[int]:
event_data = get_cached_gh_event_data()
pr_number = event_data.get("number")
if pr_number:
return int(pr_number)

pr_number = os.environ.get("CODEFLASH_PR_NUMBER")
if not pr_number:
return None
return int(pr_number)
if pr_number:
return int(pr_number)
return None


def ensure_pr_number() -> bool:
if not get_pr_number():
msg = (
"CODEFLASH_PR_NUMBER not found in environment variables; make sure the Github Action is setting this so "
"Codeflash can comment on the right PR"
"Codeflash couldn't detect your pull request number. Are you running Codeflash within a GitHub Action?"
"If not, please set the CODEFLASH_PR_NUMBER environment variable to ensure Codeflash can comment on the correct PR."
)
raise OSError(msg)
return True
Expand All @@ -96,22 +101,19 @@ def is_end_to_end() -> bool:


@lru_cache(maxsize=1)
def is_repo_a_fork() -> bool:
event = get_cached_gh_event_data()
if event is None:
return False
return bool(event["repository"]["fork"])


@lru_cache(maxsize=1)
def get_cached_gh_event_data() -> dict[str, Any] | None:
def get_cached_gh_event_data() -> dict[str, Any]:
event_path = os.getenv("GITHUB_EVENT_PATH")
if not event_path:
return None
return {}
with Path(event_path).open() as f:
return json.load(f) # type: ignore # noqa


def is_repo_a_fork() -> bool:
event = get_cached_gh_event_data()
return bool(event.get("repository", {}).get("fork", False))


@lru_cache(maxsize=1)
def is_LSP_enabled() -> bool:
return console.quiet
1 change: 0 additions & 1 deletion docs/docs/getting-started/codeflash-github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ jobs:
runs-on: ubuntu-latest
env:
CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
CODEFLASH_PR_NUMBER: ${{ github.event.number }}
steps:
- uses: actions/checkout@v4
with:
Expand Down
Loading