Skip to content

Commit

Permalink
🐛fix: function parse url git
Browse files Browse the repository at this point in the history
  • Loading branch information
D10S0VSkY-OSS committed Dec 26, 2023
1 parent 94983fa commit eb60670
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions sld-dashboard/app/helpers/parsers.py
Original file line number Diff line number Diff line change
@@ -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
return url_readme

0 comments on commit eb60670

Please sign in to comment.