Skip to content

Commit cc2cc1b

Browse files
Merge branch 'main' of github.com:codeflash-ai/codeflash into feat/markdown-read-writable-context
2 parents 216eb7e + cbd0c43 commit cc2cc1b

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

codeflash/api/cfapi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,16 @@ def mark_optimization_success(trace_id: str, *, is_optimization_found: bool) ->
261261
"""
262262
payload = {"trace_id": trace_id, "is_optimization_found": is_optimization_found}
263263
return make_cfapi_request(endpoint="/mark-as-success", method="POST", payload=payload)
264+
265+
266+
def send_completion_email() -> Response:
267+
"""Send an email notification when codeflash --all completes."""
268+
try:
269+
owner, repo = get_repo_owner_and_name()
270+
except Exception as e:
271+
sentry_sdk.capture_exception(e)
272+
response = requests.Response()
273+
response.status_code = 500
274+
return response
275+
payload = {"owner": owner, "repo": repo}
276+
return make_cfapi_request(endpoint="/send-completion-email", method="POST", payload=payload)

codeflash/code_utils/env_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_cached_gh_event_data() -> dict[str, Any]:
111111

112112
def is_repo_a_fork() -> bool:
113113
event = get_cached_gh_event_data()
114-
return bool(event.get("repository", {}).get("fork", False))
114+
return bool(event.get("pull_request", {}).get("head", {}).get("repo", {}).get("fork", False))
115115

116116

117117
@lru_cache(maxsize=1)

codeflash/optimization/optimizer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import TYPE_CHECKING
1010

1111
from codeflash.api.aiservice import AiServiceClient, LocalAiServiceClient
12+
from codeflash.api.cfapi import send_completion_email
1213
from codeflash.cli_cmds.console import console, logger, progress_bar
1314
from codeflash.code_utils import env_utils
1415
from codeflash.code_utils.code_utils import cleanup_paths, get_run_tmp_file
@@ -342,6 +343,11 @@ def run(self) -> None:
342343
logger.info("❌ No optimizations found.")
343344
elif self.args.all:
344345
logger.info("✨ All functions have been optimized! ✨")
346+
response = send_completion_email() # TODO: Include more details in the email
347+
if response.ok:
348+
logger.info("✅ Completion email sent successfully.")
349+
else:
350+
logger.warning("⚠️ Failed to send completion email. Status")
345351
finally:
346352
if function_optimizer:
347353
function_optimizer.cleanup_generated_files()

docs/docs/optimizing-with-codeflash/trace-and-optimize.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ To optimize code called by pytest tests that you could normally run like `python
1717
codeflash optimize -m pytest tests/
1818
```
1919

20-
This powerful command creates high-quality optimizations, making it ideal when you need to optimize a workflow or script. The initial tracing process can be slow, so try to limit your script's runtime to under 1 minute for best results. If your workflow is longer, consider tracing it into smaller sections by using the Codeflash tracer as a context manager (point 3 below).
20+
This powerful command creates high-quality optimizations, making it ideal when you need to optimize a workflow or script. The initial tracing process can be slow, so try to limit your script's runtime to under 1 minute for best results. If your workflow is longer, consider tracing it into smaller sections by using the Codeflash tracer as a context manager (point 3 below).
21+
22+
The generated replay tests and the trace file are for the immediate optimization use, don't add them to git.
2123

2224
## What is the codeflash optimize command?
2325

0 commit comments

Comments
 (0)