Skip to content

Commit 5fa465f

Browse files
committed
check for GH App
1 parent 5052c9e commit 5fa465f

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

codeflash/cli_cmds/cli.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import git
77

8+
from codeflash.api.cfapi import is_github_app_installed_on_repo
89
from codeflash.cli_cmds import logging_config
910
from codeflash.cli_cmds.cli_common import apologize_and_exit
1011
from codeflash.cli_cmds.cmd_init import init_codeflash, install_github_actions
@@ -128,14 +129,22 @@ def process_pyproject_config(args: Namespace) -> Namespace:
128129
assert args.tests_root is not None, "--tests-root must be specified"
129130
assert Path(args.tests_root).is_dir(), f"--tests-root {args.tests_root} must be a valid directory"
130131

131-
assert not (env_utils.get_pr_number() is not None and not env_utils.ensure_codeflash_api_key()), (
132-
"Codeflash API key not found. When running in a Github Actions Context, provide the "
133-
"'CODEFLASH_API_KEY' environment variable as a secret.\n"
134-
"You can add a secret by going to your repository's settings page, then clicking 'Secrets' in the left sidebar.\n"
135-
"Then, click 'New repository secret' and add your api key with the variable name CODEFLASH_API_KEY.\n"
136-
f"Here's a direct link: {get_github_secrets_page_url()}\n"
137-
"Exiting..."
138-
)
132+
if env_utils.get_pr_number() is not None:
133+
assert env_utils.ensure_codeflash_api_key(), (
134+
"Codeflash API key not found. When running in a Github Actions Context, provide the "
135+
"'CODEFLASH_API_KEY' environment variable as a secret.\n"
136+
"You can add a secret by going to your repository's settings page, then clicking 'Secrets' in the left sidebar.\n"
137+
"Then, click 'New repository secret' and add your api key with the variable name CODEFLASH_API_KEY.\n"
138+
f"Here's a direct link: {get_github_secrets_page_url()}\n"
139+
"Exiting..."
140+
)
141+
142+
repo = git.Repo(search_parent_directories=True)
143+
144+
owner, repo_name = get_repo_owner_and_name(repo)
145+
146+
require_github_app_or_exit(owner, repo_name)
147+
139148
if hasattr(args, "ignore_paths") and args.ignore_paths is not None:
140149
normalized_ignore_paths = []
141150
for path in args.ignore_paths:

codeflash/cli_cmds/cmd_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def check_for_toml_or_setup_file() -> str | None:
362362
return cast(str, project_name)
363363

364364

365-
def install_github_actions(override_formatter_check: bool=False) -> None:
365+
def install_github_actions(override_formatter_check: bool = False) -> None:
366366
try:
367367
config, config_file_path = parse_config_file(override_formatter_check=override_formatter_check)
368368

codeflash/cli_cmds/console.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
)
2828

2929
logger = logging.getLogger("rich")
30-
logging.getLogger('parso').setLevel(logging.WARNING)
30+
logging.getLogger("parso").setLevel(logging.WARNING)
31+
3132

3233
def paneled_text(
3334
text: str, panel_args: dict[str, str | bool] | None = None, text_args: dict[str, str] | None = None

0 commit comments

Comments
 (0)