|
32 | 32 |
|
33 | 33 |
|
34 | 34 | 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, |
36 | 41 | ) -> Response: |
37 | 42 | """Make an HTTP request using the specified method, URL, headers, and JSON payload. |
38 | 43 |
|
39 | 44 | :param endpoint: The endpoint URL to send the request to. |
40 | 45 | :param method: The HTTP method to use ('GET', 'POST', etc.). |
41 | 46 | :param payload: Optional JSON payload to include in the POST request body. |
| 47 | + :param suppress_errors: If True, suppress error logging for HTTP errors. |
42 | 48 | :return: The response object from the API. |
43 | 49 | """ |
44 | 50 | url = f"{CFAPI_BASE_URL}/cfapi{endpoint}" |
@@ -66,9 +72,10 @@ def make_cfapi_request( |
66 | 72 | except (ValueError, TypeError): |
67 | 73 | error_message = response.text |
68 | 74 |
|
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 | + ) |
72 | 79 | return response |
73 | 80 |
|
74 | 81 |
|
@@ -175,14 +182,17 @@ def create_pr( |
175 | 182 | return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload) |
176 | 183 |
|
177 | 184 |
|
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: |
179 | 186 | """Check if the Codeflash GitHub App is installed on the specified repository. |
180 | 187 |
|
181 | 188 | :param owner: The owner of the repository. |
182 | 189 | :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. |
184 | 192 | """ |
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 | + ) |
186 | 196 | return response.ok and response.text == "true" |
187 | 197 |
|
188 | 198 |
|
|
0 commit comments