From eb606708caf45c185c6b47b84123064c28c54bd8 Mon Sep 17 00:00:00 2001 From: d10s <79284025+D10S0VSkY-OSS@users.noreply.github.com> Date: Tue, 26 Dec 2023 12:49:29 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9Bfix:=20function=20parse=20url=20git?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sld-dashboard/app/helpers/parsers.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sld-dashboard/app/helpers/parsers.py b/sld-dashboard/app/helpers/parsers.py index 81114c6..931669c 100644 --- a/sld-dashboard/app/helpers/parsers.py +++ b/sld-dashboard/app/helpers/parsers.py @@ -1,16 +1,21 @@ +import urllib.parse + + def fetch_url_readme(git_repo, branch='main'): - if git_repo.endswith('.git'): - git_repo = git_repo[:-4] + if not git_repo.endswith('.git'): + git_repo += '.git' - if 'github.com' in git_repo: - raw_url = git_repo.replace('github.com', 'raw.githubusercontent.com') + parsed_url = urllib.parse.urlparse(git_repo) + + if parsed_url.netloc == 'github.com': + raw_url = f"https://raw.githubusercontent.com/{parsed_url.path[1:-4]}" url_readme = f"{raw_url}/{branch}/README.md" - elif 'gitlab.com' in git_repo: - raw_url = git_repo.replace('gitlab.com', 'gitlab.com') + elif parsed_url.netloc == 'gitlab.com': + raw_url = f"https://gitlab.com/{parsed_url.path[1:-4]}" url_readme = f"{raw_url}/-/raw/{branch}/README.md" else: print("Unsupported Git repository platform.") return None print(f"Fetching {url_readme}...") - return url_readme \ No newline at end of file + return url_readme