Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 4 additions & 2 deletions codeflash/code_utils/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ def get_git_remotes(repo: Repo) -> list[str]:
def get_repo_owner_and_name(repo: Repo | None = None, git_remote: str | None = "origin") -> tuple[str, str]:
remote_url = get_remote_url(repo, git_remote) # call only once
remote_url = remote_url.removesuffix(".git") if remote_url.endswith(".git") else remote_url
# remote_url = get_remote_url(repo, git_remote).removesuffix(".git") if remote_url.endswith(".git") else remote_url
split_url = remote_url.split("/")
repo_owner_with_github, repo_name = split_url[-2], split_url[-1]
if split_url[-1] == "":
repo_owner_with_github, repo_name = split_url[-3], split_url[-2]
else:
repo_owner_with_github, repo_name = split_url[-2], split_url[-1]
repo_owner = repo_owner_with_github.split(":")[1] if ":" in repo_owner_with_github else repo_owner_with_github
return repo_owner, repo_name

Expand Down
6 changes: 6 additions & 0 deletions tests/test_git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def test_test_get_repo_owner_and_name(self, mock_get_remote_url):
assert owner == "owner"
assert repo_name == "repo"

# Test with another GitHub SSH URL
mock_get_remote_url.return_value = "[email protected]:codeflash-ai/posthog/"
owner, repo_name = get_repo_owner_and_name()
assert owner == "codeflash-ai"
assert repo_name == "posthog"

@patch("codeflash.code_utils.git_utils.git.Repo")
def test_check_running_in_git_repo_in_git_repo(self, mock_repo):
mock_repo.return_value.git_dir = "/path/to/repo/.git"
Expand Down
Loading