Skip to content

Commit f8c7f2a

Browse files
authored
CF 680 don't emit unnecessary warning & improve UX when using cmd init (#487)
* CF 680 * don't * Update uv.lock * improve UX when under cmd init * fix mypy
1 parent 67a9e79 commit f8c7f2a

File tree

10 files changed

+1302
-734
lines changed

10 files changed

+1302
-734
lines changed

codeflash/api/cfapi.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@
3232

3333

3434
def make_cfapi_request(
35-
endpoint: str, method: str, payload: dict[str, Any] | None = None, extra_headers: dict[str, str] | None = None
35+
endpoint: str,
36+
method: str,
37+
payload: dict[str, Any] | None = None,
38+
extra_headers: dict[str, str] | None = None,
39+
*,
40+
suppress_errors: bool = False,
3641
) -> Response:
3742
"""Make an HTTP request using the specified method, URL, headers, and JSON payload.
3843
3944
:param endpoint: The endpoint URL to send the request to.
4045
:param method: The HTTP method to use ('GET', 'POST', etc.).
4146
:param payload: Optional JSON payload to include in the POST request body.
47+
:param suppress_errors: If True, suppress error logging for HTTP errors.
4248
:return: The response object from the API.
4349
"""
4450
url = f"{CFAPI_BASE_URL}/cfapi{endpoint}"
@@ -66,9 +72,10 @@ def make_cfapi_request(
6672
except (ValueError, TypeError):
6773
error_message = response.text
6874

69-
logger.error(
70-
f"CF_API_Error:: making request to Codeflash API (url: {url}, method: {method}, status {response.status_code}): {error_message}"
71-
)
75+
if not suppress_errors:
76+
logger.error(
77+
f"CF_API_Error:: making request to Codeflash API (url: {url}, method: {method}, status {response.status_code}): {error_message}"
78+
)
7279
return response
7380

7481

@@ -175,14 +182,17 @@ def create_pr(
175182
return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload)
176183

177184

178-
def is_github_app_installed_on_repo(owner: str, repo: str) -> bool:
185+
def is_github_app_installed_on_repo(owner: str, repo: str, *, suppress_errors: bool = False) -> bool:
179186
"""Check if the Codeflash GitHub App is installed on the specified repository.
180187
181188
:param owner: The owner of the repository.
182189
:param repo: The name of the repository.
183-
:return: The response object.
190+
:param suppress_errors: If True, suppress error logging when the app is not installed.
191+
:return: True if the app is installed, False otherwise.
184192
"""
185-
response = make_cfapi_request(endpoint=f"/is-github-app-installed?repo={repo}&owner={owner}", method="GET")
193+
response = make_cfapi_request(
194+
endpoint=f"/is-github-app-installed?repo={repo}&owner={owner}", method="GET", suppress_errors=suppress_errors
195+
)
186196
return response.ok and response.text == "true"
187197

188198

0 commit comments

Comments
 (0)