Skip to content

Commit 7781756

Browse files
authored
Merge branch 'main' into diversity
2 parents cdf85d2 + e2f4324 commit 7781756

File tree

5 files changed

+674
-76
lines changed

5 files changed

+674
-76
lines changed

codeflash/api/aiservice.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,60 @@ def get_optimization_review(
773773
console.rule()
774774
return ""
775775

776+
def generate_workflow_steps(
777+
self,
778+
repo_files: dict[str, str],
779+
directory_structure: dict[str, Any],
780+
codeflash_config: dict[str, Any] | None = None,
781+
) -> str | None:
782+
"""Generate GitHub Actions workflow steps based on repository analysis.
783+
784+
:param repo_files: Dictionary mapping file paths to their contents
785+
:param directory_structure: 2-level nested directory structure
786+
:param codeflash_config: Optional codeflash configuration
787+
:return: YAML string for workflow steps section, or None on error
788+
"""
789+
payload = {
790+
"repo_files": repo_files,
791+
"directory_structure": directory_structure,
792+
"codeflash_config": codeflash_config,
793+
}
794+
795+
logger.debug(
796+
f"[aiservice.py:generate_workflow_steps] Sending request to AI service with {len(repo_files)} files, "
797+
f"{len(directory_structure)} top-level directories"
798+
)
799+
800+
try:
801+
response = self.make_ai_service_request("/workflow-gen", payload=payload, timeout=60)
802+
except requests.exceptions.RequestException as e:
803+
# AI service unavailable - this is expected, will fall back to static workflow
804+
logger.debug(
805+
f"[aiservice.py:generate_workflow_steps] Request exception (falling back to static workflow): {e}"
806+
)
807+
return None
808+
809+
if response.status_code == 200:
810+
response_data = response.json()
811+
workflow_steps = cast("str", response_data.get("workflow_steps"))
812+
logger.debug(
813+
f"[aiservice.py:generate_workflow_steps] Successfully received workflow steps "
814+
f"({len(workflow_steps) if workflow_steps else 0} chars)"
815+
)
816+
return workflow_steps
817+
# AI service unavailable or endpoint not found - this is expected, will fall back to static workflow
818+
logger.debug(
819+
f"[aiservice.py:generate_workflow_steps] AI service returned status {response.status_code}, "
820+
f"falling back to static workflow generation"
821+
)
822+
try:
823+
error_response = response.json()
824+
error = cast("str", error_response.get("error", "Unknown error"))
825+
logger.debug(f"[aiservice.py:generate_workflow_steps] Error: {error}")
826+
except Exception:
827+
logger.debug("[aiservice.py:generate_workflow_steps] Could not parse error response")
828+
return None
829+
776830

777831
class LocalAiServiceClient(AiServiceClient):
778832
"""Client for interacting with the local AI service."""

codeflash/api/cfapi.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,17 @@ def make_cfapi_request(
5555
*,
5656
api_key: str | None = None,
5757
suppress_errors: bool = False,
58+
params: dict[str, Any] | None = None,
5859
) -> Response:
5960
"""Make an HTTP request using the specified method, URL, headers, and JSON payload.
6061
6162
:param endpoint: The endpoint URL to send the request to.
6263
:param method: The HTTP method to use ('GET', 'POST', etc.).
6364
:param payload: Optional JSON payload to include in the POST request body.
65+
:param extra_headers: Optional extra headers to include in the request.
66+
:param api_key: Optional API key to use for authentication.
6467
:param suppress_errors: If True, suppress error logging for HTTP errors.
68+
:param params: Optional query parameters for GET requests.
6569
:return: The response object from the API.
6670
"""
6771
url = f"{get_cfapi_base_urls().cfapi_base_url}/cfapi{endpoint}"
@@ -75,7 +79,7 @@ def make_cfapi_request(
7579
cfapi_headers["Content-Type"] = "application/json"
7680
response = requests.post(url, data=json_payload, headers=cfapi_headers, timeout=60)
7781
else:
78-
response = requests.get(url, headers=cfapi_headers, timeout=60)
82+
response = requests.get(url, headers=cfapi_headers, params=params, timeout=60)
7983
response.raise_for_status()
8084
return response # noqa: TRY300
8185
except requests.exceptions.HTTPError:
@@ -239,6 +243,20 @@ def create_pr(
239243
return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload)
240244

241245

246+
def setup_github_actions(owner: str, repo: str, base_branch: str, workflow_content: str) -> Response:
247+
"""Set up GitHub Actions workflow by creating a PR with the workflow file.
248+
249+
:param owner: Repository owner (username or organization)
250+
:param repo: Repository name
251+
:param base_branch: Base branch to create PR against (e.g., "main", "master")
252+
:param workflow_content: Content of the GitHub Actions workflow file (YAML)
253+
:return: Response object with pr_url and pr_number on success
254+
"""
255+
payload = {"owner": owner, "repo": repo, "baseBranch": base_branch, "workflowContent": workflow_content}
256+
257+
return make_cfapi_request(endpoint="/setup-github-actions", method="POST", payload=payload)
258+
259+
242260
def create_staging(
243261
original_code: dict[Path, str],
244262
new_code: dict[Path, str],

0 commit comments

Comments
 (0)