Skip to content

Commit 347fa9c

Browse files
committed
save event creator
1 parent 8758a41 commit 347fa9c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

codeflash/api/aiservice.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from codeflash.cli_cmds.console import console, logger
1414
from codeflash.code_utils.env_utils import get_codeflash_api_key
15+
from codeflash.code_utils.git_utils import get_last_commit_author_if_pr_exists, get_repo_owner_and_name
1516
from codeflash.models.models import OptimizedCandidate
1617
from codeflash.telemetry.posthog_cf import ph
1718
from codeflash.version import __version__ as codeflash_version
@@ -98,6 +99,7 @@ def optimize_python_code(
9899
99100
"""
100101
start_time = time.perf_counter()
102+
git_repo_owner, git_repo_name = get_repo_owner_and_name()
101103
payload = {
102104
"source_code": source_code,
103105
"dependency_code": dependency_code,
@@ -106,6 +108,9 @@ def optimize_python_code(
106108
"python_version": platform.python_version(),
107109
"experiment_metadata": experiment_metadata,
108110
"codeflash_version": codeflash_version,
111+
"current_username" : get_last_commit_author_if_pr_exists(None),
112+
"repo_owner": git_repo_owner,
113+
"repo_name": git_repo_name,
109114
}
110115

111116
logger.info("Generating optimized candidates…")

codeflash/code_utils/git_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import os
34
import shutil
45
import subprocess
56
import sys
@@ -174,3 +175,16 @@ def remove_git_worktrees(worktree_root: Path | None, worktrees: list[Path]) -> N
174175
logger.warning(f"Error removing worktrees: {e}")
175176
if worktree_root:
176177
shutil.rmtree(worktree_root)
178+
179+
180+
def get_last_commit_author_if_pr_exists(repo: Repo | None = None) -> str | None:
181+
"""
182+
Return the author's name of the last commit in the current branch if PR_NUMBER is set.
183+
Otherwise, return None.
184+
"""
185+
if "PR_NUMBER" not in os.environ:
186+
return None
187+
188+
repository: Repo = repo if repo else git.Repo(search_parent_directories=True)
189+
last_commit = repository.head.commit
190+
return last_commit.author.name

0 commit comments

Comments
 (0)