Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 17 additions & 7 deletions codeflash/api/cfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@


def make_cfapi_request(
endpoint: str, method: str, payload: dict[str, Any] | None = None, extra_headers: dict[str, str] | None = None
endpoint: str,
method: str,
payload: dict[str, Any] | None = None,
extra_headers: dict[str, str] | None = None,
*,
suppress_errors: bool = False,
) -> Response:
"""Make an HTTP request using the specified method, URL, headers, and JSON payload.

:param endpoint: The endpoint URL to send the request to.
:param method: The HTTP method to use ('GET', 'POST', etc.).
:param payload: Optional JSON payload to include in the POST request body.
:param suppress_errors: If True, suppress error logging for HTTP errors.
:return: The response object from the API.
"""
url = f"{CFAPI_BASE_URL}/cfapi{endpoint}"
Expand Down Expand Up @@ -66,9 +72,10 @@ def make_cfapi_request(
except (ValueError, TypeError):
error_message = response.text

logger.error(
f"CF_API_Error:: making request to Codeflash API (url: {url}, method: {method}, status {response.status_code}): {error_message}"
)
if not suppress_errors:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Why are we suppressing the errors?

logger.error(
f"CF_API_Error:: making request to Codeflash API (url: {url}, method: {method}, status {response.status_code}): {error_message}"
)
return response


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


def is_github_app_installed_on_repo(owner: str, repo: str) -> bool:
def is_github_app_installed_on_repo(owner: str, repo: str, *, suppress_errors: bool = False) -> bool:
"""Check if the Codeflash GitHub App is installed on the specified repository.

:param owner: The owner of the repository.
:param repo: The name of the repository.
:return: The response object.
:param suppress_errors: If True, suppress error logging when the app is not installed.
:return: True if the app is installed, False otherwise.
"""
response = make_cfapi_request(endpoint=f"/is-github-app-installed?repo={repo}&owner={owner}", method="GET")
response = make_cfapi_request(
endpoint=f"/is-github-app-installed?repo={repo}&owner={owner}", method="GET", suppress_errors=suppress_errors
)
return response.ok and response.text == "true"


Expand Down
4 changes: 2 additions & 2 deletions codeflash/cli_cmds/cmd_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def install_github_app() -> None:
return
owner, repo = get_repo_owner_and_name(git_repo)

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

else:
Expand All @@ -774,7 +774,7 @@ def install_github_app() -> None:
)

count = 2
while not is_github_app_installed_on_repo(owner, repo):
while not is_github_app_installed_on_repo(owner, repo, suppress_errors=True):
if count == 0:
click.echo(
f"❌ It looks like the Codeflash GitHub App is not installed on the repository {owner}/{repo}.{LF}"
Expand Down
13 changes: 7 additions & 6 deletions codeflash/lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any

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

def show_message_log(self, message: str, message_type: str) -> None:
"""Send a log message to the client's output channel.

Args:
message: The message to log
message_type: String type - "Info", "Warning", "Error", or "Log"

"""
# Convert string message type to LSP MessageType enum
type_mapping = {
"Info": MessageType.Info,
"Warning": MessageType.Warning,
"Warning": MessageType.Warning,
"Error": MessageType.Error,
"Log": MessageType.Log
"Log": MessageType.Log,
}

lsp_message_type = type_mapping.get(message_type, MessageType.Info)

# Send log message to client (appears in output channel)
log_params = LogMessageParams(type=lsp_message_type, message=message)
self.lsp.notify("window/logMessage", log_params)
7 changes: 4 additions & 3 deletions codeflash/lsp/server_entry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This script is the dedicated entry point for the Codeflash Language Server.
It initializes the server and redirects its logs to stderr so that the
"""Dedicated entry point for the Codeflash Language Server.

Initializes the server and redirects its logs to stderr so that the
VS Code client can display them in the output channel.

This script is run by the VS Code extension and is not intended to be
Expand All @@ -13,7 +14,7 @@


# Configure logging to stderr for VS Code output channel
def setup_logging():
def setup_logging() -> logging.Logger:
# Clear any existing handlers to prevent conflicts
root_logger = logging.getLogger()
root_logger.handlers.clear()
Expand Down
Loading