statsd: fix crash if there is no git repository (#23775)

* fix crash if there is no git repository

* return default

Co-authored-by: Willem Melching <willem.melching@gmail.com>
old-commit-hash: a84ddaecf1
This commit is contained in:
Jack Huang 2022-02-16 21:30:54 +08:00 committed by GitHub
parent 6ca0269f47
commit c0478078ee
1 changed files with 9 additions and 5 deletions

View File

@ -55,11 +55,15 @@ def get_origin(default: Optional[str] = None) -> Optional[str]:
@cache
def get_normalized_origin(default: Optional[str] = None) -> Optional[str]:
return get_origin()\
.replace("git@", "", 1)\
.replace(".git", "", 1)\
.replace("https://", "", 1)\
.replace(":", "/", 1)
origin = get_origin()
if origin is None:
return default
return origin.replace("git@", "", 1) \
.replace(".git", "", 1) \
.replace("https://", "", 1) \
.replace(":", "/", 1)
@cache