Skip to content

Commit 90d29d8

Browse files
committed
CF 680
1 parent 67a9e79 commit 90d29d8

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
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

codeflash/cli_cmds/cmd_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ def install_github_app() -> None:
751751
return
752752
owner, repo = get_repo_owner_and_name(git_repo)
753753

754-
if is_github_app_installed_on_repo(owner, repo):
754+
if is_github_app_installed_on_repo(owner, repo, suppress_errors=True):
755755
click.echo("🐙 Looks like you've already installed the Codeflash GitHub app on this repository! Continuing…")
756756

757757
else:
@@ -774,7 +774,7 @@ def install_github_app() -> None:
774774
)
775775

776776
count = 2
777-
while not is_github_app_installed_on_repo(owner, repo):
777+
while not is_github_app_installed_on_repo(owner, repo, suppress_errors=True):
778778
if count == 0:
779779
click.echo(
780780
f"❌ It looks like the Codeflash GitHub App is not installed on the repository {owner}/{repo}.{LF}"

codeflash/lsp/server.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44
from typing import TYPE_CHECKING, Any
55

6-
from lsprotocol.types import INITIALIZE, MessageType, LogMessageParams
6+
from lsprotocol.types import INITIALIZE, LogMessageParams, MessageType
77
from pygls import uris
88
from pygls.protocol import LanguageServerProtocol, lsp_method
99
from pygls.server import LanguageServer
@@ -58,21 +58,22 @@ def initialize_optimizer(self, config_file: Path) -> None:
5858

5959
def show_message_log(self, message: str, message_type: str) -> None:
6060
"""Send a log message to the client's output channel.
61-
61+
6262
Args:
6363
message: The message to log
6464
message_type: String type - "Info", "Warning", "Error", or "Log"
65+
6566
"""
6667
# Convert string message type to LSP MessageType enum
6768
type_mapping = {
6869
"Info": MessageType.Info,
69-
"Warning": MessageType.Warning,
70+
"Warning": MessageType.Warning,
7071
"Error": MessageType.Error,
71-
"Log": MessageType.Log
72+
"Log": MessageType.Log,
7273
}
73-
74+
7475
lsp_message_type = type_mapping.get(message_type, MessageType.Info)
75-
76+
7677
# Send log message to client (appears in output channel)
7778
log_params = LogMessageParams(type=lsp_message_type, message=message)
7879
self.lsp.notify("window/logMessage", log_params)

codeflash/lsp/server_entry.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
"""This script is the dedicated entry point for the Codeflash Language Server.
2-
It initializes the server and redirects its logs to stderr so that the
1+
"""Dedicated entry point for the Codeflash Language Server.
2+
3+
Initializes the server and redirects its logs to stderr so that the
34
VS Code client can display them in the output channel.
45
56
This script is run by the VS Code extension and is not intended to be
@@ -13,7 +14,7 @@
1314

1415

1516
# Configure logging to stderr for VS Code output channel
16-
def setup_logging():
17+
def setup_logging() -> logging.Logger:
1718
# Clear any existing handlers to prevent conflicts
1819
root_logger = logging.getLogger()
1920
root_logger.handlers.clear()

0 commit comments

Comments
 (0)