Skip to content

Commit 1f893ea

Browse files
committed
Add error handling to get_last_commit_author_if_pr_exists
1 parent 109ab3f commit 1f893ea

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

codeflash/code_utils/git_utils.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,13 @@ def get_last_commit_author_if_pr_exists(repo: Repo | None = None) -> str | None:
182182
Return the author's name of the last commit in the current branch if PR_NUMBER is set.
183183
Otherwise, return None.
184184
"""
185-
if "PR_NUMBER" not in os.environ:
185+
try:
186+
if "PR_NUMBER" not in os.environ:
187+
return None
188+
189+
repository: Repo = repo if repo else git.Repo(search_parent_directories=True)
190+
last_commit = repository.head.commit
191+
return last_commit.author.name
192+
except Exception as e:
193+
logger.exception("Failed to get last commit author.")
186194
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)