Fix potodo failing when no "origin" remote is found (#37) (#38)

Fix potodo failing when no "origin" remote is found (#37)
This commit is contained in:
Jules Lasne (jlasne) 2019-12-13 12:39:42 +01:00 committed by GitHub
commit 503b760ddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,21 +1,26 @@
import re
import requests
import subprocess
from typing import Mapping
from subprocess import check_output
def get_repo_url(repo_path: str) -> str:
"""Tries to get the repository url from git commands
"""
url = check_output("git remote get-url --all upstream".split(), universal_newlines=True, cwd=repo_path)
if "fatal" in url:
url = check_output("git remote get-url --all upstream".split(), universal_newlines=True, cwd=repo_path)
if "fatal" in url:
# If the commands didn't work
raise RuntimeError(
f"Unknown error. `git get-url --all upstream|origin` returned {url}"
)
try:
url = subprocess.check_output("git remote get-url --all upstream".split(),
universal_newlines=True, cwd=repo_path,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
try:
url = subprocess.check_output("git remote get-url --all origin".split(),
universal_newlines=True, cwd=repo_path,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
raise RuntimeError(
f"Unknown error. `git get-url --all upstream|origin` returned \"{e.output.rstrip()}\"."
)
return url