Skip to content

Commit

Permalink
Move clean_url to function
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Feb 23, 2024
1 parent b751ff7 commit 1db5e95
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ def removesuffix(self: str, suffix: str) -> str:
return self[:]


def clean_url(url: str) -> str:
# git@github.com:user/repo.git
# ->
# https://github.com/user/repo.git
if url.startswith("git@"):
url = "https://" + removeprefix(url, "git@").replace(":", "/")

# https://github.com/user/repo.git
# ->
# https://github.com:user/repo
url = removesuffix(url, ".git")

return url


def main(args):
# Find the user/repo of the Git origin
git_repo = git.Repo(".")
Expand All @@ -38,16 +53,7 @@ def main(args):
cprint("No upstream, opening origin", "yellow")
print(url)

# git@github.com:user/repo.git
# ->
# https://github.com/user/repo.git
if url.startswith("git@"):
url = "https://" + removeprefix(url, "git@").replace(":", "/")

# https://github.com/user/repo.git
# ->
# https://github.com:user/repo
url = removesuffix(url, ".git")
url = clean_url(url)

if args.tab:
if "gitlab" in url:
Expand Down

0 comments on commit 1db5e95

Please sign in to comment.