From 89410a5f64666ff40acc992245897f8a0e53ba2c Mon Sep 17 00:00:00 2001 From: mohammed Date: Fri, 20 Jun 2025 18:28:08 +0300 Subject: [PATCH 01/11] get pr number from gh action event json file, fallback to old behaviour --- .github/workflows/codeflash-optimize.yaml | 1 - .../cli_cmds/workflows/codeflash-optimize.yaml | 1 - codeflash/code_utils/env_utils.py | 18 ++++++++++++++++-- .../codeflash-github-actions.md | 1 - 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeflash-optimize.yaml b/.github/workflows/codeflash-optimize.yaml index 3c35017fb..46349e1a5 100644 --- a/.github/workflows/codeflash-optimize.yaml +++ b/.github/workflows/codeflash-optimize.yaml @@ -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 diff --git a/codeflash/cli_cmds/workflows/codeflash-optimize.yaml b/codeflash/cli_cmds/workflows/codeflash-optimize.yaml index ccf2ec382..a080d53d4 100644 --- a/codeflash/cli_cmds/workflows/codeflash-optimize.yaml +++ b/codeflash/cli_cmds/workflows/codeflash-optimize.yaml @@ -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 diff --git a/codeflash/code_utils/env_utils.py b/codeflash/code_utils/env_utils.py index adca67df8..f7f618493 100644 --- a/codeflash/code_utils/env_utils.py +++ b/codeflash/code_utils/env_utils.py @@ -1,5 +1,6 @@ from __future__ import annotations +import json import os import tempfile from functools import lru_cache @@ -64,6 +65,10 @@ def ensure_codeflash_api_key() -> bool: @lru_cache(maxsize=1) def get_pr_number() -> Optional[int]: + event_data = get_cached_gh_event_data() + gh_pr_number = event_data["number"] + if gh_pr_number is not None: + return int(gh_pr_number) pr_number = os.environ.get("CODEFLASH_PR_NUMBER") if not pr_number: return None @@ -73,8 +78,8 @@ def get_pr_number() -> Optional[int]: 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 @@ -83,3 +88,12 @@ def ensure_pr_number() -> bool: @lru_cache(maxsize=1) def is_end_to_end() -> bool: return bool(os.environ.get("CODEFLASH_END_TO_END")) + + +@lru_cache(maxsize=1) +def get_cached_gh_event_data() -> dict[str,]: + event_path = os.getenv("GITHUB_EVENT_PATH") + if not event_path: + return {} + with Path(event_path).open() as f: + return json.load(f) diff --git a/docs/docs/getting-started/codeflash-github-actions.md b/docs/docs/getting-started/codeflash-github-actions.md index 7f9574dfb..177979ed8 100644 --- a/docs/docs/getting-started/codeflash-github-actions.md +++ b/docs/docs/getting-started/codeflash-github-actions.md @@ -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: From b9e8b715b4d8270fc3a4fab481f4d4bb00f8be64 Mon Sep 17 00:00:00 2001 From: mohammed Date: Mon, 23 Jun 2025 16:42:09 +0300 Subject: [PATCH 02/11] fix mypy lint error --- codeflash/code_utils/env_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codeflash/code_utils/env_utils.py b/codeflash/code_utils/env_utils.py index f7f618493..3b370440c 100644 --- a/codeflash/code_utils/env_utils.py +++ b/codeflash/code_utils/env_utils.py @@ -5,7 +5,7 @@ import tempfile from functools import lru_cache from pathlib import Path -from typing import Optional +from typing import Any, Optional from codeflash.cli_cmds.console import logger from codeflash.code_utils.code_utils import exit_with_message @@ -91,7 +91,7 @@ def is_end_to_end() -> bool: @lru_cache(maxsize=1) -def get_cached_gh_event_data() -> dict[str,]: +def get_cached_gh_event_data() -> dict[str, Any]: event_path = os.getenv("GITHUB_EVENT_PATH") if not event_path: return {} From ad36ad34a72a96bb882b7b71eb37094cc4b8bafa Mon Sep 17 00:00:00 2001 From: mohammed Date: Mon, 23 Jun 2025 16:51:17 +0300 Subject: [PATCH 03/11] skip returning any --- codeflash/code_utils/env_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/code_utils/env_utils.py b/codeflash/code_utils/env_utils.py index 3b370440c..8f5da6359 100644 --- a/codeflash/code_utils/env_utils.py +++ b/codeflash/code_utils/env_utils.py @@ -96,4 +96,4 @@ def get_cached_gh_event_data() -> dict[str, Any]: if not event_path: return {} with Path(event_path).open() as f: - return json.load(f) + return json.load(f) # type: ignore # noqa From a5b5bf1c323ad8644b58ccb2d0c0bfd0b5adb5cb Mon Sep 17 00:00:00 2001 From: mohammed Date: Sun, 29 Jun 2025 03:51:40 +0300 Subject: [PATCH 04/11] fix: null safety --- codeflash/code_utils/env_utils.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/codeflash/code_utils/env_utils.py b/codeflash/code_utils/env_utils.py index 0ea7fae51..d8b01a557 100644 --- a/codeflash/code_utils/env_utils.py +++ b/codeflash/code_utils/env_utils.py @@ -75,13 +75,14 @@ def ensure_codeflash_api_key() -> bool: @lru_cache(maxsize=1) def get_pr_number() -> Optional[int]: event_data = get_cached_gh_event_data() - gh_pr_number = event_data["number"] - if gh_pr_number is not None: - return int(gh_pr_number) + 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: @@ -110,9 +111,7 @@ def get_cached_gh_event_data() -> dict[str, Any]: def is_repo_a_fork() -> bool: event = get_cached_gh_event_data() - if event is None: - return False - return bool(event["repository"]["fork"]) + return bool(event.get("repository", {}).get("fork", False)) @lru_cache(maxsize=1) From f8255fbfd4d4f82efb1f91dec3a9754381789484 Mon Sep 17 00:00:00 2001 From: mohammed Date: Fri, 4 Jul 2025 15:45:39 +0300 Subject: [PATCH 05/11] fix: unit tests --- codeflash/result/critic.py | 12 ++++++++---- tests/test_critic.py | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/codeflash/result/critic.py b/codeflash/result/critic.py index 6702b7bb4..e158fd07a 100644 --- a/codeflash/result/critic.py +++ b/codeflash/result/critic.py @@ -26,7 +26,10 @@ def performance_gain(*, original_runtime_ns: int, optimized_runtime_ns: int) -> def speedup_critic( - candidate_result: OptimizedCandidateResult, original_code_runtime: int, best_runtime_until_now: int + candidate_result: OptimizedCandidateResult, + original_code_runtime: int, + best_runtime_until_now: int, + disable_gh_action_noise: bool | None = None, ) -> bool: """Take in a correct optimized Test Result and decide if the optimization should actually be surfaced to the user. @@ -35,10 +38,11 @@ def speedup_critic( when the original runtime is less than 10 microseconds, and becomes MIN_IMPROVEMENT_THRESHOLD for any higher runtime. The noise floor is doubled when benchmarking on a (noisy) GitHub Action virtual instance, also we want to be more confident there. """ - in_github_actions_mode = bool(env_utils.get_pr_number()) noise_floor = 3 * MIN_IMPROVEMENT_THRESHOLD if original_code_runtime < 10000 else MIN_IMPROVEMENT_THRESHOLD - if in_github_actions_mode: - noise_floor = noise_floor * 2 # Increase the noise floor in GitHub Actions mode + if not disable_gh_action_noise: + in_github_actions_mode = bool(env_utils.get_pr_number()) + if in_github_actions_mode: + noise_floor = noise_floor * 2 # Increase the noise floor in GitHub Actions mode perf_gain = performance_gain( original_runtime_ns=original_code_runtime, optimized_runtime_ns=candidate_result.best_test_runtime diff --git a/tests/test_critic.py b/tests/test_critic.py index 569c2badb..49dfdfd64 100644 --- a/tests/test_critic.py +++ b/tests/test_critic.py @@ -41,7 +41,7 @@ def test_speedup_critic() -> None: total_candidate_timing=12, ) - assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now) # 20% improvement + assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, True) # 20% improvement candidate_result = OptimizedCandidateResult( max_loop_count=5, @@ -52,7 +52,7 @@ def test_speedup_critic() -> None: optimization_candidate_index=0, ) - assert not speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now) # 6% improvement + assert not speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, True) # 6% improvement original_code_runtime = 100000 best_runtime_until_now = 100000 @@ -66,7 +66,7 @@ def test_speedup_critic() -> None: optimization_candidate_index=0, ) - assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now) # 6% improvement + assert speedup_critic(candidate_result, original_code_runtime, best_runtime_until_now, True) # 6% improvement def test_generated_test_critic() -> None: From 25cce0e065cc97b5b17a0977f96749a418ec9f74 Mon Sep 17 00:00:00 2001 From: mohammed Date: Fri, 4 Jul 2025 15:48:43 +0300 Subject: [PATCH 06/11] linting --- codeflash/result/critic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codeflash/result/critic.py b/codeflash/result/critic.py index e158fd07a..dd8b5a564 100644 --- a/codeflash/result/critic.py +++ b/codeflash/result/critic.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional from codeflash.cli_cmds.console import logger from codeflash.code_utils import env_utils @@ -29,7 +29,7 @@ def speedup_critic( candidate_result: OptimizedCandidateResult, original_code_runtime: int, best_runtime_until_now: int, - disable_gh_action_noise: bool | None = None, + disable_gh_action_noise: Optional[bool] = None, ) -> bool: """Take in a correct optimized Test Result and decide if the optimization should actually be surfaced to the user. From 23b2bdc0287c6cf1dfd563926121cf3d819278b5 Mon Sep 17 00:00:00 2001 From: mohammed Date: Fri, 4 Jul 2025 16:13:07 +0300 Subject: [PATCH 07/11] tests for gh event path --- codeflash/code_utils/env_utils.py | 13 +- tests/test_github_event_path.py | 529 ++++++++++++++++++++++++++++++ 2 files changed, 531 insertions(+), 11 deletions(-) create mode 100644 tests/test_github_event_path.py diff --git a/codeflash/code_utils/env_utils.py b/codeflash/code_utils/env_utils.py index ea7cba76f..2c8ca22a1 100644 --- a/codeflash/code_utils/env_utils.py +++ b/codeflash/code_utils/env_utils.py @@ -127,14 +127,5 @@ def is_LSP_enabled() -> bool: 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 + event = get_cached_gh_event_data() + return bool(event.get("pull_request", {}).get("draft", False)) diff --git a/tests/test_github_event_path.py b/tests/test_github_event_path.py new file mode 100644 index 000000000..131dcd294 --- /dev/null +++ b/tests/test_github_event_path.py @@ -0,0 +1,529 @@ +import pytest +from pathlib import Path +from codeflash.code_utils import env_utils +import json +import os + +pr_event_file = '''{ + "action": "opened", + "number": 10, + "pull_request": { + "_links": { + "comments": { + "href": "https://api.github.com/repos/codeflash-ai/sample/issues/10/comments" + }, + "commits": { + "href": "https://api.github.com/repos/codeflash-ai/sample/pulls/10/commits" + }, + "html": { + "href": "https://github.com/codeflash-ai/sample/pull/10" + }, + "issue": { + "href": "https://api.github.com/repos/codeflash-ai/sample/issues/10" + }, + "review_comment": { + "href": "https://api.github.com/repos/codeflash-ai/sample/pulls/comments{/number}" + }, + "review_comments": { + "href": "https://api.github.com/repos/codeflash-ai/sample/pulls/10/comments" + }, + "self": { + "href": "https://api.github.com/repos/codeflash-ai/sample/pulls/10" + }, + "statuses": { + "href": "https://api.github.com/repos/codeflash-ai/sample/statuses/5ebcb20678e98da74f7c54813b074a5e3e995893" + } + }, + "active_lock_reason": null, + "additions": 1, + "assignee": null, + "assignees": [], + "author_association": "OWNER", + "auto_merge": null, + "base": { + "label": "codeflash-ai:main", + "ref": "main", + "repo": { + "allow_auto_merge": false, + "allow_forking": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/codeflash-ai/sample/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/codeflash-ai/sample/assignees{/user}", + "blobs_url": "https://api.github.com/repos/codeflash-ai/sample/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/codeflash-ai/sample/branches{/branch}", + "clone_url": "https://github.com/codeflash-ai/sample.git", + "collaborators_url": "https://api.github.com/repos/codeflash-ai/sample/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/codeflash-ai/sample/comments{/number}", + "commits_url": "https://api.github.com/repos/codeflash-ai/sample/commits{/sha}", + "compare_url": "https://api.github.com/repos/codeflash-ai/sample/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/codeflash-ai/sample/contents/{+path}", + "contributors_url": "https://api.github.com/repos/codeflash-ai/sample/contributors", + "created_at": "2025-06-11T14:28:03Z", + "default_branch": "main", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/codeflash-ai/sample/deployments", + "description": null, + "disabled": false, + "downloads_url": "https://api.github.com/repos/codeflash-ai/sample/downloads", + "events_url": "https://api.github.com/repos/codeflash-ai/sample/events", + "fork": false, + "forks": 1, + "forks_count": 1, + "forks_url": "https://api.github.com/repos/codeflash-ai/sample/forks", + "full_name": "codeflash-ai/sample", + "git_commits_url": "https://api.github.com/repos/codeflash-ai/sample/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/codeflash-ai/sample/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/codeflash-ai/sample/git/tags{/sha}", + "git_url": "git://github.com/codeflash-ai/sample.git", + "has_discussions": false, + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/codeflash-ai/sample/hooks", + "html_url": "https://github.com/codeflash-ai/sample", + "id": 1000277295, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/codeflash-ai/sample/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/codeflash-ai/sample/issues/events{/number}", + "issues_url": "https://api.github.com/repos/codeflash-ai/sample/issues{/number}", + "keys_url": "https://api.github.com/repos/codeflash-ai/sample/keys{/key_id}", + "labels_url": "https://api.github.com/repos/codeflash-ai/sample/labels{/name}", + "language": "Python", + "languages_url": "https://api.github.com/repos/codeflash-ai/sample/languages", + "license": null, + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "merges_url": "https://api.github.com/repos/codeflash-ai/sample/merges", + "milestones_url": "https://api.github.com/repos/codeflash-ai/sample/milestones{/number}", + "mirror_url": null, + "name": "sample", + "node_id": "R_kgDOO58FLw", + "notifications_url": "https://api.github.com/repos/codeflash-ai/sample/notifications{?since,all,participating}", + "open_issues": 5, + "open_issues_count": 5, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", + "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", + "followers_url": "https://api.github.com/users/codeflash-ai/followers", + "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", + "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/codeflash-ai", + "id": 64513301, + "login": "codeflash-ai", + "node_id": "MDQ6VXNlcjY0NTEzMzAx", + "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", + "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", + "repos_url": "https://api.github.com/users/codeflash-ai/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", + "type": "User", + "url": "https://api.github.com/users/codeflash-ai", + "user_view_type": "public" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/codeflash-ai/sample/pulls{/number}", + "pushed_at": "2025-06-20T12:27:40Z", + "releases_url": "https://api.github.com/repos/codeflash-ai/sample/releases{/id}", + "size": 58, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "ssh_url": "git@github.com:codeflash-ai/sample.git", + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/codeflash-ai/sample/stargazers", + "statuses_url": "https://api.github.com/repos/codeflash-ai/sample/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/codeflash-ai/sample/subscribers", + "subscription_url": "https://api.github.com/repos/codeflash-ai/sample/subscription", + "svn_url": "https://github.com/codeflash-ai/sample", + "tags_url": "https://api.github.com/repos/codeflash-ai/sample/tags", + "teams_url": "https://api.github.com/repos/codeflash-ai/sample/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/codeflash-ai/sample/git/trees{/sha}", + "updated_at": "2025-06-20T12:27:25Z", + "url": "https://api.github.com/repos/codeflash-ai/sample", + "use_squash_pr_title_as_default": false, + "visibility": "public", + "watchers": 0, + "watchers_count": 0, + "web_commit_signoff_required": false + }, + "sha": "e91bb066a0aef48cef29d000dcba4a62c83a8bec", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", + "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", + "followers_url": "https://api.github.com/users/codeflash-ai/followers", + "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", + "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/codeflash-ai", + "id": 64513301, + "login": "codeflash-ai", + "node_id": "MDQ6VXNlcjY0NTEzMzAx", + "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", + "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", + "repos_url": "https://api.github.com/users/codeflash-ai/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", + "type": "User", + "url": "https://api.github.com/users/codeflash-ai", + "user_view_type": "public" + } + }, + "body": null, + "changed_files": 1, + "closed_at": null, + "comments": 0, + "comments_url": "https://api.github.com/repos/codeflash-ai/sample/issues/10/comments", + "commits": 1, + "commits_url": "https://api.github.com/repos/codeflash-ai/sample/pulls/10/commits", + "created_at": "2025-06-20T12:27:45Z", + "deletions": 0, + "diff_url": "https://github.com/codeflash-ai/sample/pull/10.diff", + "draft": false, + "head": { + "label": "codeflash-ai:codeflash-ai-patch-3", + "ref": "codeflash-ai-patch-3", + "repo": { + "allow_auto_merge": false, + "allow_forking": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "allow_update_branch": false, + "archive_url": "https://api.github.com/repos/codeflash-ai/sample/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/codeflash-ai/sample/assignees{/user}", + "blobs_url": "https://api.github.com/repos/codeflash-ai/sample/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/codeflash-ai/sample/branches{/branch}", + "clone_url": "https://github.com/codeflash-ai/sample.git", + "collaborators_url": "https://api.github.com/repos/codeflash-ai/sample/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/codeflash-ai/sample/comments{/number}", + "commits_url": "https://api.github.com/repos/codeflash-ai/sample/commits{/sha}", + "compare_url": "https://api.github.com/repos/codeflash-ai/sample/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/codeflash-ai/sample/contents/{+path}", + "contributors_url": "https://api.github.com/repos/codeflash-ai/sample/contributors", + "created_at": "2025-06-11T14:28:03Z", + "default_branch": "main", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/codeflash-ai/sample/deployments", + "description": null, + "disabled": false, + "downloads_url": "https://api.github.com/repos/codeflash-ai/sample/downloads", + "events_url": "https://api.github.com/repos/codeflash-ai/sample/events", + "fork": false, + "forks": 1, + "forks_count": 1, + "forks_url": "https://api.github.com/repos/codeflash-ai/sample/forks", + "full_name": "codeflash-ai/sample", + "git_commits_url": "https://api.github.com/repos/codeflash-ai/sample/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/codeflash-ai/sample/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/codeflash-ai/sample/git/tags{/sha}", + "git_url": "git://github.com/codeflash-ai/sample.git", + "has_discussions": false, + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/codeflash-ai/sample/hooks", + "html_url": "https://github.com/codeflash-ai/sample", + "id": 1000277295, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/codeflash-ai/sample/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/codeflash-ai/sample/issues/events{/number}", + "issues_url": "https://api.github.com/repos/codeflash-ai/sample/issues{/number}", + "keys_url": "https://api.github.com/repos/codeflash-ai/sample/keys{/key_id}", + "labels_url": "https://api.github.com/repos/codeflash-ai/sample/labels{/name}", + "language": "Python", + "languages_url": "https://api.github.com/repos/codeflash-ai/sample/languages", + "license": null, + "merge_commit_message": "PR_TITLE", + "merge_commit_title": "MERGE_MESSAGE", + "merges_url": "https://api.github.com/repos/codeflash-ai/sample/merges", + "milestones_url": "https://api.github.com/repos/codeflash-ai/sample/milestones{/number}", + "mirror_url": null, + "name": "sample", + "node_id": "R_kgDOO58FLw", + "notifications_url": "https://api.github.com/repos/codeflash-ai/sample/notifications{?since,all,participating}", + "open_issues": 5, + "open_issues_count": 5, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", + "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", + "followers_url": "https://api.github.com/users/codeflash-ai/followers", + "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", + "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/codeflash-ai", + "id": 64513301, + "login": "codeflash-ai", + "node_id": "MDQ6VXNlcjY0NTEzMzAx", + "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", + "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", + "repos_url": "https://api.github.com/users/codeflash-ai/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", + "type": "User", + "url": "https://api.github.com/users/codeflash-ai", + "user_view_type": "public" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/codeflash-ai/sample/pulls{/number}", + "pushed_at": "2025-06-20T12:27:40Z", + "releases_url": "https://api.github.com/repos/codeflash-ai/sample/releases{/id}", + "size": 58, + "squash_merge_commit_message": "COMMIT_MESSAGES", + "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", + "ssh_url": "git@github.com:codeflash-ai/sample.git", + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/codeflash-ai/sample/stargazers", + "statuses_url": "https://api.github.com/repos/codeflash-ai/sample/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/codeflash-ai/sample/subscribers", + "subscription_url": "https://api.github.com/repos/codeflash-ai/sample/subscription", + "svn_url": "https://github.com/codeflash-ai/sample", + "tags_url": "https://api.github.com/repos/codeflash-ai/sample/tags", + "teams_url": "https://api.github.com/repos/codeflash-ai/sample/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/codeflash-ai/sample/git/trees{/sha}", + "updated_at": "2025-06-20T12:27:25Z", + "url": "https://api.github.com/repos/codeflash-ai/sample", + "use_squash_pr_title_as_default": false, + "visibility": "public", + "watchers": 0, + "watchers_count": 0, + "web_commit_signoff_required": false + }, + "sha": "5ebcb20678e98da74f7c54813b074a5e3e995893", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", + "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", + "followers_url": "https://api.github.com/users/codeflash-ai/followers", + "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", + "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/codeflash-ai", + "id": 64513301, + "login": "codeflash-ai", + "node_id": "MDQ6VXNlcjY0NTEzMzAx", + "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", + "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", + "repos_url": "https://api.github.com/users/codeflash-ai/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", + "type": "User", + "url": "https://api.github.com/users/codeflash-ai", + "user_view_type": "public" + } + }, + "html_url": "https://github.com/codeflash-ai/sample/pull/10", + "id": 2607341348, + "issue_url": "https://api.github.com/repos/codeflash-ai/sample/issues/10", + "labels": [], + "locked": false, + "maintainer_can_modify": false, + "merge_commit_sha": null, + "mergeable": null, + "mergeable_state": "unknown", + "merged": false, + "merged_at": null, + "merged_by": null, + "milestone": null, + "node_id": "PR_kwDOO58FL86baN8k", + "number": 10, + "patch_url": "https://github.com/codeflash-ai/sample/pull/10.patch", + "rebaseable": null, + "requested_reviewers": [], + "requested_teams": [], + "review_comment_url": "https://api.github.com/repos/codeflash-ai/sample/pulls/comments{/number}", + "review_comments": 0, + "review_comments_url": "https://api.github.com/repos/codeflash-ai/sample/pulls/10/comments", + "state": "open", + "statuses_url": "https://api.github.com/repos/codeflash-ai/sample/statuses/5ebcb20678e98da74f7c54813b074a5e3e995893", + "title": "Update pyproject.toml", + "updated_at": "2025-06-20T12:27:45Z", + "url": "https://api.github.com/repos/codeflash-ai/sample/pulls/10", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", + "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", + "followers_url": "https://api.github.com/users/codeflash-ai/followers", + "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", + "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/codeflash-ai", + "id": 64513301, + "login": "codeflash-ai", + "node_id": "MDQ6VXNlcjY0NTEzMzAx", + "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", + "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", + "repos_url": "https://api.github.com/users/codeflash-ai/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", + "type": "User", + "url": "https://api.github.com/users/codeflash-ai", + "user_view_type": "public" + } + }, + "repository": { + "allow_forking": true, + "archive_url": "https://api.github.com/repos/codeflash-ai/sample/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/codeflash-ai/sample/assignees{/user}", + "blobs_url": "https://api.github.com/repos/codeflash-ai/sample/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/codeflash-ai/sample/branches{/branch}", + "clone_url": "https://github.com/codeflash-ai/sample.git", + "collaborators_url": "https://api.github.com/repos/codeflash-ai/sample/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/codeflash-ai/sample/comments{/number}", + "commits_url": "https://api.github.com/repos/codeflash-ai/sample/commits{/sha}", + "compare_url": "https://api.github.com/repos/codeflash-ai/sample/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/codeflash-ai/sample/contents/{+path}", + "contributors_url": "https://api.github.com/repos/codeflash-ai/sample/contributors", + "created_at": "2025-06-11T14:28:03Z", + "default_branch": "main", + "deployments_url": "https://api.github.com/repos/codeflash-ai/sample/deployments", + "description": null, + "disabled": false, + "downloads_url": "https://api.github.com/repos/codeflash-ai/sample/downloads", + "events_url": "https://api.github.com/repos/codeflash-ai/sample/events", + "fork": false, + "forks": 1, + "forks_count": 1, + "forks_url": "https://api.github.com/repos/codeflash-ai/sample/forks", + "full_name": "codeflash-ai/sample", + "git_commits_url": "https://api.github.com/repos/codeflash-ai/sample/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/codeflash-ai/sample/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/codeflash-ai/sample/git/tags{/sha}", + "git_url": "git://github.com/codeflash-ai/sample.git", + "has_discussions": false, + "has_downloads": true, + "has_issues": true, + "has_pages": false, + "has_projects": true, + "has_wiki": true, + "homepage": null, + "hooks_url": "https://api.github.com/repos/codeflash-ai/sample/hooks", + "html_url": "https://github.com/codeflash-ai/sample", + "id": 1000277295, + "is_template": false, + "issue_comment_url": "https://api.github.com/repos/codeflash-ai/sample/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/codeflash-ai/sample/issues/events{/number}", + "issues_url": "https://api.github.com/repos/codeflash-ai/sample/issues{/number}", + "keys_url": "https://api.github.com/repos/codeflash-ai/sample/keys{/key_id}", + "labels_url": "https://api.github.com/repos/codeflash-ai/sample/labels{/name}", + "language": "Python", + "languages_url": "https://api.github.com/repos/codeflash-ai/sample/languages", + "license": null, + "merges_url": "https://api.github.com/repos/codeflash-ai/sample/merges", + "milestones_url": "https://api.github.com/repos/codeflash-ai/sample/milestones{/number}", + "mirror_url": null, + "name": "sample", + "node_id": "R_kgDOO58FLw", + "notifications_url": "https://api.github.com/repos/codeflash-ai/sample/notifications{?since,all,participating}", + "open_issues": 5, + "open_issues_count": 5, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", + "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", + "followers_url": "https://api.github.com/users/codeflash-ai/followers", + "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", + "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/codeflash-ai", + "id": 64513301, + "login": "codeflash-ai", + "node_id": "MDQ6VXNlcjY0NTEzMzAx", + "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", + "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", + "repos_url": "https://api.github.com/users/codeflash-ai/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", + "type": "User", + "url": "https://api.github.com/users/codeflash-ai", + "user_view_type": "public" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/codeflash-ai/sample/pulls{/number}", + "pushed_at": "2025-06-20T12:27:40Z", + "releases_url": "https://api.github.com/repos/codeflash-ai/sample/releases{/id}", + "size": 58, + "ssh_url": "git@github.com:codeflash-ai/sample.git", + "stargazers_count": 0, + "stargazers_url": "https://api.github.com/repos/codeflash-ai/sample/stargazers", + "statuses_url": "https://api.github.com/repos/codeflash-ai/sample/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/codeflash-ai/sample/subscribers", + "subscription_url": "https://api.github.com/repos/codeflash-ai/sample/subscription", + "svn_url": "https://github.com/codeflash-ai/sample", + "tags_url": "https://api.github.com/repos/codeflash-ai/sample/tags", + "teams_url": "https://api.github.com/repos/codeflash-ai/sample/teams", + "topics": [], + "trees_url": "https://api.github.com/repos/codeflash-ai/sample/git/trees{/sha}", + "updated_at": "2025-06-20T12:27:25Z", + "url": "https://api.github.com/repos/codeflash-ai/sample", + "visibility": "public", + "watchers": 0, + "watchers_count": 0, + "web_commit_signoff_required": false + }, + "sender": { + "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", + "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", + "followers_url": "https://api.github.com/users/codeflash-ai/followers", + "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", + "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/codeflash-ai", + "id": 64513301, + "login": "codeflash-ai", + "node_id": "MDQ6VXNlcjY0NTEzMzAx", + "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", + "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", + "repos_url": "https://api.github.com/users/codeflash-ai/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", + "type": "User", + "url": "https://api.github.com/users/codeflash-ai", + "user_view_type": "public" + } +}''' + + + +@pytest.fixture +def set_event_file(tmp_path): + def _write_event(content: str): + path = tmp_path / "event.json" + path.write_text(content) + os.environ["GITHUB_EVENT_PATH"] = str(path) + return path + return _write_event + + +def test_is_repo_not_a_fork(set_event_file): + set_event_file(pr_event_file) + assert env_utils.is_repo_a_fork() is False + + +def test_is_pr_not_draft(set_event_file): + set_event_file(pr_event_file) + assert env_utils.is_pr_draft() is False + +def test_get_pr_number(set_event_file): + set_event_file(pr_event_file) + pr_number = env_utils.get_pr_number() + assert type(pr_number) is int + assert pr_number is 10 + From a41f592e409f933471d4243a49b875bb04982196 Mon Sep 17 00:00:00 2001 From: mohammed Date: Fri, 4 Jul 2025 16:27:10 +0300 Subject: [PATCH 08/11] override gh event path in tests --- tests/test_github_event_path.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/test_github_event_path.py b/tests/test_github_event_path.py index 131dcd294..b12b1994a 100644 --- a/tests/test_github_event_path.py +++ b/tests/test_github_event_path.py @@ -504,25 +504,22 @@ @pytest.fixture def set_event_file(tmp_path): - def _write_event(content: str): - path = tmp_path / "event.json" - path.write_text(content) - os.environ["GITHUB_EVENT_PATH"] = str(path) - return path - return _write_event + path = tmp_path / "event.json" + existing_or_new_path = Path(os.getenv("GITHUB_EVENT_PATH", str(path))) + existing_or_new_path.write_text(pr_event_file, encoding="utf-8") + os.environ["GITHUB_EVENT_PATH"] = str(existing_or_new_path) + print(existing_or_new_path) + return existing_or_new_path def test_is_repo_not_a_fork(set_event_file): - set_event_file(pr_event_file) assert env_utils.is_repo_a_fork() is False def test_is_pr_not_draft(set_event_file): - set_event_file(pr_event_file) assert env_utils.is_pr_draft() is False def test_get_pr_number(set_event_file): - set_event_file(pr_event_file) pr_number = env_utils.get_pr_number() assert type(pr_number) is int assert pr_number is 10 From 70c176867da34c3451d03ddae3da45463bc1426f Mon Sep 17 00:00:00 2001 From: mohammed Date: Fri, 4 Jul 2025 16:30:27 +0300 Subject: [PATCH 09/11] fix: for no git test --- codeflash/api/cfapi.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codeflash/api/cfapi.py b/codeflash/api/cfapi.py index ca1cf7e4e..0f1fbf654 100644 --- a/codeflash/api/cfapi.py +++ b/codeflash/api/cfapi.py @@ -205,9 +205,10 @@ def get_blocklisted_functions() -> dict[str, set[str]] | dict[str, Any]: if pr_number is None: return {} - owner, repo = get_repo_owner_and_name() - information = {"pr_number": pr_number, "repo_owner": owner, "repo_name": repo} try: + owner, repo = get_repo_owner_and_name() + information = {"pr_number": pr_number, "repo_owner": owner, "repo_name": repo} + req = make_cfapi_request(endpoint="/verify-existing-optimizations", method="POST", payload=information) req.raise_for_status() content: dict[str, list[str]] = req.json() From 47723307601b2398cd6df372f1fb225dc2ba4a99 Mon Sep 17 00:00:00 2001 From: mohammed Date: Fri, 4 Jul 2025 16:43:02 +0300 Subject: [PATCH 10/11] fixes --- tests/test_github_event_path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_github_event_path.py b/tests/test_github_event_path.py index b12b1994a..9bf63c760 100644 --- a/tests/test_github_event_path.py +++ b/tests/test_github_event_path.py @@ -504,11 +504,11 @@ @pytest.fixture def set_event_file(tmp_path): + env_utils.get_cached_gh_event_data.cache_clear() path = tmp_path / "event.json" existing_or_new_path = Path(os.getenv("GITHUB_EVENT_PATH", str(path))) existing_or_new_path.write_text(pr_event_file, encoding="utf-8") os.environ["GITHUB_EVENT_PATH"] = str(existing_or_new_path) - print(existing_or_new_path) return existing_or_new_path From 5a12b7cae927c67d04f238a47e4523cdd422f9c1 Mon Sep 17 00:00:00 2001 From: mohammed Date: Fri, 4 Jul 2025 16:50:02 +0300 Subject: [PATCH 11/11] cleanup --- tests/test_github_event_path.py | 526 -------------------------------- 1 file changed, 526 deletions(-) delete mode 100644 tests/test_github_event_path.py diff --git a/tests/test_github_event_path.py b/tests/test_github_event_path.py deleted file mode 100644 index 9bf63c760..000000000 --- a/tests/test_github_event_path.py +++ /dev/null @@ -1,526 +0,0 @@ -import pytest -from pathlib import Path -from codeflash.code_utils import env_utils -import json -import os - -pr_event_file = '''{ - "action": "opened", - "number": 10, - "pull_request": { - "_links": { - "comments": { - "href": "https://api.github.com/repos/codeflash-ai/sample/issues/10/comments" - }, - "commits": { - "href": "https://api.github.com/repos/codeflash-ai/sample/pulls/10/commits" - }, - "html": { - "href": "https://github.com/codeflash-ai/sample/pull/10" - }, - "issue": { - "href": "https://api.github.com/repos/codeflash-ai/sample/issues/10" - }, - "review_comment": { - "href": "https://api.github.com/repos/codeflash-ai/sample/pulls/comments{/number}" - }, - "review_comments": { - "href": "https://api.github.com/repos/codeflash-ai/sample/pulls/10/comments" - }, - "self": { - "href": "https://api.github.com/repos/codeflash-ai/sample/pulls/10" - }, - "statuses": { - "href": "https://api.github.com/repos/codeflash-ai/sample/statuses/5ebcb20678e98da74f7c54813b074a5e3e995893" - } - }, - "active_lock_reason": null, - "additions": 1, - "assignee": null, - "assignees": [], - "author_association": "OWNER", - "auto_merge": null, - "base": { - "label": "codeflash-ai:main", - "ref": "main", - "repo": { - "allow_auto_merge": false, - "allow_forking": true, - "allow_merge_commit": true, - "allow_rebase_merge": true, - "allow_squash_merge": true, - "allow_update_branch": false, - "archive_url": "https://api.github.com/repos/codeflash-ai/sample/{archive_format}{/ref}", - "archived": false, - "assignees_url": "https://api.github.com/repos/codeflash-ai/sample/assignees{/user}", - "blobs_url": "https://api.github.com/repos/codeflash-ai/sample/git/blobs{/sha}", - "branches_url": "https://api.github.com/repos/codeflash-ai/sample/branches{/branch}", - "clone_url": "https://github.com/codeflash-ai/sample.git", - "collaborators_url": "https://api.github.com/repos/codeflash-ai/sample/collaborators{/collaborator}", - "comments_url": "https://api.github.com/repos/codeflash-ai/sample/comments{/number}", - "commits_url": "https://api.github.com/repos/codeflash-ai/sample/commits{/sha}", - "compare_url": "https://api.github.com/repos/codeflash-ai/sample/compare/{base}...{head}", - "contents_url": "https://api.github.com/repos/codeflash-ai/sample/contents/{+path}", - "contributors_url": "https://api.github.com/repos/codeflash-ai/sample/contributors", - "created_at": "2025-06-11T14:28:03Z", - "default_branch": "main", - "delete_branch_on_merge": false, - "deployments_url": "https://api.github.com/repos/codeflash-ai/sample/deployments", - "description": null, - "disabled": false, - "downloads_url": "https://api.github.com/repos/codeflash-ai/sample/downloads", - "events_url": "https://api.github.com/repos/codeflash-ai/sample/events", - "fork": false, - "forks": 1, - "forks_count": 1, - "forks_url": "https://api.github.com/repos/codeflash-ai/sample/forks", - "full_name": "codeflash-ai/sample", - "git_commits_url": "https://api.github.com/repos/codeflash-ai/sample/git/commits{/sha}", - "git_refs_url": "https://api.github.com/repos/codeflash-ai/sample/git/refs{/sha}", - "git_tags_url": "https://api.github.com/repos/codeflash-ai/sample/git/tags{/sha}", - "git_url": "git://github.com/codeflash-ai/sample.git", - "has_discussions": false, - "has_downloads": true, - "has_issues": true, - "has_pages": false, - "has_projects": true, - "has_wiki": true, - "homepage": null, - "hooks_url": "https://api.github.com/repos/codeflash-ai/sample/hooks", - "html_url": "https://github.com/codeflash-ai/sample", - "id": 1000277295, - "is_template": false, - "issue_comment_url": "https://api.github.com/repos/codeflash-ai/sample/issues/comments{/number}", - "issue_events_url": "https://api.github.com/repos/codeflash-ai/sample/issues/events{/number}", - "issues_url": "https://api.github.com/repos/codeflash-ai/sample/issues{/number}", - "keys_url": "https://api.github.com/repos/codeflash-ai/sample/keys{/key_id}", - "labels_url": "https://api.github.com/repos/codeflash-ai/sample/labels{/name}", - "language": "Python", - "languages_url": "https://api.github.com/repos/codeflash-ai/sample/languages", - "license": null, - "merge_commit_message": "PR_TITLE", - "merge_commit_title": "MERGE_MESSAGE", - "merges_url": "https://api.github.com/repos/codeflash-ai/sample/merges", - "milestones_url": "https://api.github.com/repos/codeflash-ai/sample/milestones{/number}", - "mirror_url": null, - "name": "sample", - "node_id": "R_kgDOO58FLw", - "notifications_url": "https://api.github.com/repos/codeflash-ai/sample/notifications{?since,all,participating}", - "open_issues": 5, - "open_issues_count": 5, - "owner": { - "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", - "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", - "followers_url": "https://api.github.com/users/codeflash-ai/followers", - "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", - "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/codeflash-ai", - "id": 64513301, - "login": "codeflash-ai", - "node_id": "MDQ6VXNlcjY0NTEzMzAx", - "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", - "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", - "repos_url": "https://api.github.com/users/codeflash-ai/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", - "type": "User", - "url": "https://api.github.com/users/codeflash-ai", - "user_view_type": "public" - }, - "private": false, - "pulls_url": "https://api.github.com/repos/codeflash-ai/sample/pulls{/number}", - "pushed_at": "2025-06-20T12:27:40Z", - "releases_url": "https://api.github.com/repos/codeflash-ai/sample/releases{/id}", - "size": 58, - "squash_merge_commit_message": "COMMIT_MESSAGES", - "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", - "ssh_url": "git@github.com:codeflash-ai/sample.git", - "stargazers_count": 0, - "stargazers_url": "https://api.github.com/repos/codeflash-ai/sample/stargazers", - "statuses_url": "https://api.github.com/repos/codeflash-ai/sample/statuses/{sha}", - "subscribers_url": "https://api.github.com/repos/codeflash-ai/sample/subscribers", - "subscription_url": "https://api.github.com/repos/codeflash-ai/sample/subscription", - "svn_url": "https://github.com/codeflash-ai/sample", - "tags_url": "https://api.github.com/repos/codeflash-ai/sample/tags", - "teams_url": "https://api.github.com/repos/codeflash-ai/sample/teams", - "topics": [], - "trees_url": "https://api.github.com/repos/codeflash-ai/sample/git/trees{/sha}", - "updated_at": "2025-06-20T12:27:25Z", - "url": "https://api.github.com/repos/codeflash-ai/sample", - "use_squash_pr_title_as_default": false, - "visibility": "public", - "watchers": 0, - "watchers_count": 0, - "web_commit_signoff_required": false - }, - "sha": "e91bb066a0aef48cef29d000dcba4a62c83a8bec", - "user": { - "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", - "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", - "followers_url": "https://api.github.com/users/codeflash-ai/followers", - "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", - "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/codeflash-ai", - "id": 64513301, - "login": "codeflash-ai", - "node_id": "MDQ6VXNlcjY0NTEzMzAx", - "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", - "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", - "repos_url": "https://api.github.com/users/codeflash-ai/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", - "type": "User", - "url": "https://api.github.com/users/codeflash-ai", - "user_view_type": "public" - } - }, - "body": null, - "changed_files": 1, - "closed_at": null, - "comments": 0, - "comments_url": "https://api.github.com/repos/codeflash-ai/sample/issues/10/comments", - "commits": 1, - "commits_url": "https://api.github.com/repos/codeflash-ai/sample/pulls/10/commits", - "created_at": "2025-06-20T12:27:45Z", - "deletions": 0, - "diff_url": "https://github.com/codeflash-ai/sample/pull/10.diff", - "draft": false, - "head": { - "label": "codeflash-ai:codeflash-ai-patch-3", - "ref": "codeflash-ai-patch-3", - "repo": { - "allow_auto_merge": false, - "allow_forking": true, - "allow_merge_commit": true, - "allow_rebase_merge": true, - "allow_squash_merge": true, - "allow_update_branch": false, - "archive_url": "https://api.github.com/repos/codeflash-ai/sample/{archive_format}{/ref}", - "archived": false, - "assignees_url": "https://api.github.com/repos/codeflash-ai/sample/assignees{/user}", - "blobs_url": "https://api.github.com/repos/codeflash-ai/sample/git/blobs{/sha}", - "branches_url": "https://api.github.com/repos/codeflash-ai/sample/branches{/branch}", - "clone_url": "https://github.com/codeflash-ai/sample.git", - "collaborators_url": "https://api.github.com/repos/codeflash-ai/sample/collaborators{/collaborator}", - "comments_url": "https://api.github.com/repos/codeflash-ai/sample/comments{/number}", - "commits_url": "https://api.github.com/repos/codeflash-ai/sample/commits{/sha}", - "compare_url": "https://api.github.com/repos/codeflash-ai/sample/compare/{base}...{head}", - "contents_url": "https://api.github.com/repos/codeflash-ai/sample/contents/{+path}", - "contributors_url": "https://api.github.com/repos/codeflash-ai/sample/contributors", - "created_at": "2025-06-11T14:28:03Z", - "default_branch": "main", - "delete_branch_on_merge": false, - "deployments_url": "https://api.github.com/repos/codeflash-ai/sample/deployments", - "description": null, - "disabled": false, - "downloads_url": "https://api.github.com/repos/codeflash-ai/sample/downloads", - "events_url": "https://api.github.com/repos/codeflash-ai/sample/events", - "fork": false, - "forks": 1, - "forks_count": 1, - "forks_url": "https://api.github.com/repos/codeflash-ai/sample/forks", - "full_name": "codeflash-ai/sample", - "git_commits_url": "https://api.github.com/repos/codeflash-ai/sample/git/commits{/sha}", - "git_refs_url": "https://api.github.com/repos/codeflash-ai/sample/git/refs{/sha}", - "git_tags_url": "https://api.github.com/repos/codeflash-ai/sample/git/tags{/sha}", - "git_url": "git://github.com/codeflash-ai/sample.git", - "has_discussions": false, - "has_downloads": true, - "has_issues": true, - "has_pages": false, - "has_projects": true, - "has_wiki": true, - "homepage": null, - "hooks_url": "https://api.github.com/repos/codeflash-ai/sample/hooks", - "html_url": "https://github.com/codeflash-ai/sample", - "id": 1000277295, - "is_template": false, - "issue_comment_url": "https://api.github.com/repos/codeflash-ai/sample/issues/comments{/number}", - "issue_events_url": "https://api.github.com/repos/codeflash-ai/sample/issues/events{/number}", - "issues_url": "https://api.github.com/repos/codeflash-ai/sample/issues{/number}", - "keys_url": "https://api.github.com/repos/codeflash-ai/sample/keys{/key_id}", - "labels_url": "https://api.github.com/repos/codeflash-ai/sample/labels{/name}", - "language": "Python", - "languages_url": "https://api.github.com/repos/codeflash-ai/sample/languages", - "license": null, - "merge_commit_message": "PR_TITLE", - "merge_commit_title": "MERGE_MESSAGE", - "merges_url": "https://api.github.com/repos/codeflash-ai/sample/merges", - "milestones_url": "https://api.github.com/repos/codeflash-ai/sample/milestones{/number}", - "mirror_url": null, - "name": "sample", - "node_id": "R_kgDOO58FLw", - "notifications_url": "https://api.github.com/repos/codeflash-ai/sample/notifications{?since,all,participating}", - "open_issues": 5, - "open_issues_count": 5, - "owner": { - "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", - "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", - "followers_url": "https://api.github.com/users/codeflash-ai/followers", - "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", - "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/codeflash-ai", - "id": 64513301, - "login": "codeflash-ai", - "node_id": "MDQ6VXNlcjY0NTEzMzAx", - "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", - "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", - "repos_url": "https://api.github.com/users/codeflash-ai/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", - "type": "User", - "url": "https://api.github.com/users/codeflash-ai", - "user_view_type": "public" - }, - "private": false, - "pulls_url": "https://api.github.com/repos/codeflash-ai/sample/pulls{/number}", - "pushed_at": "2025-06-20T12:27:40Z", - "releases_url": "https://api.github.com/repos/codeflash-ai/sample/releases{/id}", - "size": 58, - "squash_merge_commit_message": "COMMIT_MESSAGES", - "squash_merge_commit_title": "COMMIT_OR_PR_TITLE", - "ssh_url": "git@github.com:codeflash-ai/sample.git", - "stargazers_count": 0, - "stargazers_url": "https://api.github.com/repos/codeflash-ai/sample/stargazers", - "statuses_url": "https://api.github.com/repos/codeflash-ai/sample/statuses/{sha}", - "subscribers_url": "https://api.github.com/repos/codeflash-ai/sample/subscribers", - "subscription_url": "https://api.github.com/repos/codeflash-ai/sample/subscription", - "svn_url": "https://github.com/codeflash-ai/sample", - "tags_url": "https://api.github.com/repos/codeflash-ai/sample/tags", - "teams_url": "https://api.github.com/repos/codeflash-ai/sample/teams", - "topics": [], - "trees_url": "https://api.github.com/repos/codeflash-ai/sample/git/trees{/sha}", - "updated_at": "2025-06-20T12:27:25Z", - "url": "https://api.github.com/repos/codeflash-ai/sample", - "use_squash_pr_title_as_default": false, - "visibility": "public", - "watchers": 0, - "watchers_count": 0, - "web_commit_signoff_required": false - }, - "sha": "5ebcb20678e98da74f7c54813b074a5e3e995893", - "user": { - "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", - "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", - "followers_url": "https://api.github.com/users/codeflash-ai/followers", - "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", - "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/codeflash-ai", - "id": 64513301, - "login": "codeflash-ai", - "node_id": "MDQ6VXNlcjY0NTEzMzAx", - "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", - "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", - "repos_url": "https://api.github.com/users/codeflash-ai/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", - "type": "User", - "url": "https://api.github.com/users/codeflash-ai", - "user_view_type": "public" - } - }, - "html_url": "https://github.com/codeflash-ai/sample/pull/10", - "id": 2607341348, - "issue_url": "https://api.github.com/repos/codeflash-ai/sample/issues/10", - "labels": [], - "locked": false, - "maintainer_can_modify": false, - "merge_commit_sha": null, - "mergeable": null, - "mergeable_state": "unknown", - "merged": false, - "merged_at": null, - "merged_by": null, - "milestone": null, - "node_id": "PR_kwDOO58FL86baN8k", - "number": 10, - "patch_url": "https://github.com/codeflash-ai/sample/pull/10.patch", - "rebaseable": null, - "requested_reviewers": [], - "requested_teams": [], - "review_comment_url": "https://api.github.com/repos/codeflash-ai/sample/pulls/comments{/number}", - "review_comments": 0, - "review_comments_url": "https://api.github.com/repos/codeflash-ai/sample/pulls/10/comments", - "state": "open", - "statuses_url": "https://api.github.com/repos/codeflash-ai/sample/statuses/5ebcb20678e98da74f7c54813b074a5e3e995893", - "title": "Update pyproject.toml", - "updated_at": "2025-06-20T12:27:45Z", - "url": "https://api.github.com/repos/codeflash-ai/sample/pulls/10", - "user": { - "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", - "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", - "followers_url": "https://api.github.com/users/codeflash-ai/followers", - "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", - "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/codeflash-ai", - "id": 64513301, - "login": "codeflash-ai", - "node_id": "MDQ6VXNlcjY0NTEzMzAx", - "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", - "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", - "repos_url": "https://api.github.com/users/codeflash-ai/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", - "type": "User", - "url": "https://api.github.com/users/codeflash-ai", - "user_view_type": "public" - } - }, - "repository": { - "allow_forking": true, - "archive_url": "https://api.github.com/repos/codeflash-ai/sample/{archive_format}{/ref}", - "archived": false, - "assignees_url": "https://api.github.com/repos/codeflash-ai/sample/assignees{/user}", - "blobs_url": "https://api.github.com/repos/codeflash-ai/sample/git/blobs{/sha}", - "branches_url": "https://api.github.com/repos/codeflash-ai/sample/branches{/branch}", - "clone_url": "https://github.com/codeflash-ai/sample.git", - "collaborators_url": "https://api.github.com/repos/codeflash-ai/sample/collaborators{/collaborator}", - "comments_url": "https://api.github.com/repos/codeflash-ai/sample/comments{/number}", - "commits_url": "https://api.github.com/repos/codeflash-ai/sample/commits{/sha}", - "compare_url": "https://api.github.com/repos/codeflash-ai/sample/compare/{base}...{head}", - "contents_url": "https://api.github.com/repos/codeflash-ai/sample/contents/{+path}", - "contributors_url": "https://api.github.com/repos/codeflash-ai/sample/contributors", - "created_at": "2025-06-11T14:28:03Z", - "default_branch": "main", - "deployments_url": "https://api.github.com/repos/codeflash-ai/sample/deployments", - "description": null, - "disabled": false, - "downloads_url": "https://api.github.com/repos/codeflash-ai/sample/downloads", - "events_url": "https://api.github.com/repos/codeflash-ai/sample/events", - "fork": false, - "forks": 1, - "forks_count": 1, - "forks_url": "https://api.github.com/repos/codeflash-ai/sample/forks", - "full_name": "codeflash-ai/sample", - "git_commits_url": "https://api.github.com/repos/codeflash-ai/sample/git/commits{/sha}", - "git_refs_url": "https://api.github.com/repos/codeflash-ai/sample/git/refs{/sha}", - "git_tags_url": "https://api.github.com/repos/codeflash-ai/sample/git/tags{/sha}", - "git_url": "git://github.com/codeflash-ai/sample.git", - "has_discussions": false, - "has_downloads": true, - "has_issues": true, - "has_pages": false, - "has_projects": true, - "has_wiki": true, - "homepage": null, - "hooks_url": "https://api.github.com/repos/codeflash-ai/sample/hooks", - "html_url": "https://github.com/codeflash-ai/sample", - "id": 1000277295, - "is_template": false, - "issue_comment_url": "https://api.github.com/repos/codeflash-ai/sample/issues/comments{/number}", - "issue_events_url": "https://api.github.com/repos/codeflash-ai/sample/issues/events{/number}", - "issues_url": "https://api.github.com/repos/codeflash-ai/sample/issues{/number}", - "keys_url": "https://api.github.com/repos/codeflash-ai/sample/keys{/key_id}", - "labels_url": "https://api.github.com/repos/codeflash-ai/sample/labels{/name}", - "language": "Python", - "languages_url": "https://api.github.com/repos/codeflash-ai/sample/languages", - "license": null, - "merges_url": "https://api.github.com/repos/codeflash-ai/sample/merges", - "milestones_url": "https://api.github.com/repos/codeflash-ai/sample/milestones{/number}", - "mirror_url": null, - "name": "sample", - "node_id": "R_kgDOO58FLw", - "notifications_url": "https://api.github.com/repos/codeflash-ai/sample/notifications{?since,all,participating}", - "open_issues": 5, - "open_issues_count": 5, - "owner": { - "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", - "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", - "followers_url": "https://api.github.com/users/codeflash-ai/followers", - "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", - "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/codeflash-ai", - "id": 64513301, - "login": "codeflash-ai", - "node_id": "MDQ6VXNlcjY0NTEzMzAx", - "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", - "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", - "repos_url": "https://api.github.com/users/codeflash-ai/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", - "type": "User", - "url": "https://api.github.com/users/codeflash-ai", - "user_view_type": "public" - }, - "private": false, - "pulls_url": "https://api.github.com/repos/codeflash-ai/sample/pulls{/number}", - "pushed_at": "2025-06-20T12:27:40Z", - "releases_url": "https://api.github.com/repos/codeflash-ai/sample/releases{/id}", - "size": 58, - "ssh_url": "git@github.com:codeflash-ai/sample.git", - "stargazers_count": 0, - "stargazers_url": "https://api.github.com/repos/codeflash-ai/sample/stargazers", - "statuses_url": "https://api.github.com/repos/codeflash-ai/sample/statuses/{sha}", - "subscribers_url": "https://api.github.com/repos/codeflash-ai/sample/subscribers", - "subscription_url": "https://api.github.com/repos/codeflash-ai/sample/subscription", - "svn_url": "https://github.com/codeflash-ai/sample", - "tags_url": "https://api.github.com/repos/codeflash-ai/sample/tags", - "teams_url": "https://api.github.com/repos/codeflash-ai/sample/teams", - "topics": [], - "trees_url": "https://api.github.com/repos/codeflash-ai/sample/git/trees{/sha}", - "updated_at": "2025-06-20T12:27:25Z", - "url": "https://api.github.com/repos/codeflash-ai/sample", - "visibility": "public", - "watchers": 0, - "watchers_count": 0, - "web_commit_signoff_required": false - }, - "sender": { - "avatar_url": "https://avatars.githubusercontent.com/u/64513301?v=4", - "events_url": "https://api.github.com/users/codeflash-ai/events{/privacy}", - "followers_url": "https://api.github.com/users/codeflash-ai/followers", - "following_url": "https://api.github.com/users/codeflash-ai/following{/other_user}", - "gists_url": "https://api.github.com/users/codeflash-ai/gists{/gist_id}", - "gravatar_id": "", - "html_url": "https://github.com/codeflash-ai", - "id": 64513301, - "login": "codeflash-ai", - "node_id": "MDQ6VXNlcjY0NTEzMzAx", - "organizations_url": "https://api.github.com/users/codeflash-ai/orgs", - "received_events_url": "https://api.github.com/users/codeflash-ai/received_events", - "repos_url": "https://api.github.com/users/codeflash-ai/repos", - "site_admin": false, - "starred_url": "https://api.github.com/users/codeflash-ai/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/codeflash-ai/subscriptions", - "type": "User", - "url": "https://api.github.com/users/codeflash-ai", - "user_view_type": "public" - } -}''' - - - -@pytest.fixture -def set_event_file(tmp_path): - env_utils.get_cached_gh_event_data.cache_clear() - path = tmp_path / "event.json" - existing_or_new_path = Path(os.getenv("GITHUB_EVENT_PATH", str(path))) - existing_or_new_path.write_text(pr_event_file, encoding="utf-8") - os.environ["GITHUB_EVENT_PATH"] = str(existing_or_new_path) - return existing_or_new_path - - -def test_is_repo_not_a_fork(set_event_file): - assert env_utils.is_repo_a_fork() is False - - -def test_is_pr_not_draft(set_event_file): - assert env_utils.is_pr_draft() is False - -def test_get_pr_number(set_event_file): - pr_number = env_utils.get_pr_number() - assert type(pr_number) is int - assert pr_number is 10 -