Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
947e2ab
calling cf-api while setting up github actions during init command
mashraf-222 Nov 13, 2025
bea874f
updating the cf-api request for github action installation
mashraf-222 Nov 14, 2025
6471a5c
User experience improvements
mashraf-222 Nov 14, 2025
d971d08
fix lint errors
mashraf-222 Nov 14, 2025
7f6b758
update Set up GitHub Action message during init command
mashraf-222 Nov 14, 2025
d3c55d2
check if the workflow file exists before setting up the github action
mashraf-222 Nov 14, 2025
9b6c0c1
skip user's prompt for github action installatin if already installed
mashraf-222 Nov 14, 2025
0c6065c
local check for the codeflash.yaml instead of remote
mashraf-222 Nov 14, 2025
03875b9
adding collect_repo_files_for_workflow and generate_workflow_steps fo…
mashraf-222 Nov 17, 2025
cb20ff8
logs clean up & update
mashraf-222 Nov 18, 2025
fc88658
fix formatting
mashraf-222 Nov 26, 2025
786c67d
Merge branch 'main' into ashraf/cf-861-raise-pr-with-the-github-actio…
Saga4 Dec 8, 2025
ef2b9b3
Merge branch 'main' into ashraf/cf-861-raise-pr-with-the-github-actio…
mashraf-222 Dec 10, 2025
32f29af
fix linting for pre-commit
mashraf-222 Dec 10, 2025
1ce7cf7
Updating the UV installation command to include install --upgrade
mashraf-222 Dec 10, 2025
c9502b6
remove unused function
mashraf-222 Dec 10, 2025
98d2cef
revert the secret cf api key while setup of github workflow file
mashraf-222 Dec 16, 2025
5861c83
Enhance UX by show a focused message and abort early when there is pe…
mashraf-222 Dec 16, 2025
cbbc323
Merge branch 'main' into ashraf/cf-861-raise-pr-with-the-github-actio…
mashraf-222 Dec 16, 2025
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
54 changes: 54 additions & 0 deletions codeflash/api/aiservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,60 @@ def get_optimization_review(
console.rule()
return ""

def generate_workflow_steps(
self,
repo_files: dict[str, str],
directory_structure: dict[str, Any],
codeflash_config: dict[str, Any] | None = None,
) -> str | None:
"""Generate GitHub Actions workflow steps based on repository analysis.

:param repo_files: Dictionary mapping file paths to their contents
:param directory_structure: 2-level nested directory structure
:param codeflash_config: Optional codeflash configuration
:return: YAML string for workflow steps section, or None on error
"""
payload = {
"repo_files": repo_files,
"directory_structure": directory_structure,
"codeflash_config": codeflash_config,
}

logger.debug(
f"[aiservice.py:generate_workflow_steps] Sending request to AI service with {len(repo_files)} files, "
f"{len(directory_structure)} top-level directories"
)

try:
response = self.make_ai_service_request("/workflow-gen", payload=payload, timeout=60)
except requests.exceptions.RequestException as e:
# AI service unavailable - this is expected, will fall back to static workflow
logger.debug(
f"[aiservice.py:generate_workflow_steps] Request exception (falling back to static workflow): {e}"
)
return None

if response.status_code == 200:
response_data = response.json()
workflow_steps = cast("str", response_data.get("workflow_steps"))
logger.debug(
f"[aiservice.py:generate_workflow_steps] Successfully received workflow steps "
f"({len(workflow_steps) if workflow_steps else 0} chars)"
)
return workflow_steps
# AI service unavailable or endpoint not found - this is expected, will fall back to static workflow
logger.debug(
f"[aiservice.py:generate_workflow_steps] AI service returned status {response.status_code}, "
f"falling back to static workflow generation"
)
try:
error_response = response.json()
error = cast("str", error_response.get("error", "Unknown error"))
logger.debug(f"[aiservice.py:generate_workflow_steps] Error: {error}")
except Exception:
logger.debug("[aiservice.py:generate_workflow_steps] Could not parse error response")
return None


class LocalAiServiceClient(AiServiceClient):
"""Client for interacting with the local AI service."""
Expand Down
20 changes: 19 additions & 1 deletion codeflash/api/cfapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ def make_cfapi_request(
*,
api_key: str | None = None,
suppress_errors: bool = False,
params: dict[str, Any] | None = None,
) -> 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 extra_headers: Optional extra headers to include in the request.
:param api_key: Optional API key to use for authentication.
:param suppress_errors: If True, suppress error logging for HTTP errors.
:param params: Optional query parameters for GET requests.
:return: The response object from the API.
"""
url = f"{get_cfapi_base_urls().cfapi_base_url}/cfapi{endpoint}"
Expand All @@ -75,7 +79,7 @@ def make_cfapi_request(
cfapi_headers["Content-Type"] = "application/json"
response = requests.post(url, data=json_payload, headers=cfapi_headers, timeout=60)
else:
response = requests.get(url, headers=cfapi_headers, timeout=60)
response = requests.get(url, headers=cfapi_headers, params=params, timeout=60)
response.raise_for_status()
return response # noqa: TRY300
except requests.exceptions.HTTPError:
Expand Down Expand Up @@ -239,6 +243,20 @@ def create_pr(
return make_cfapi_request(endpoint="/create-pr", method="POST", payload=payload)


def setup_github_actions(owner: str, repo: str, base_branch: str, workflow_content: str) -> Response:
"""Set up GitHub Actions workflow by creating a PR with the workflow file.

:param owner: Repository owner (username or organization)
:param repo: Repository name
:param base_branch: Base branch to create PR against (e.g., "main", "master")
:param workflow_content: Content of the GitHub Actions workflow file (YAML)
:return: Response object with pr_url and pr_number on success
"""
payload = {"owner": owner, "repo": repo, "baseBranch": base_branch, "workflowContent": workflow_content}

return make_cfapi_request(endpoint="/setup-github-actions", method="POST", payload=payload)


def create_staging(
original_code: dict[Path, str],
new_code: dict[Path, str],
Expand Down
Loading
Loading