-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
import configparser | ||
|
||
|
||
GITHUB_ENDPOINT = os.getenv('GITHUB_ENDPOINT') | ||
|
||
|
||
def is_git_repo(path: str) -> bool: | ||
""" Check if the path is a git repository. """ | ||
# NOTE: Checking it through `git.Repo` must be avoided. | ||
|
@@ -46,16 +49,21 @@ def git_url(fullpath): | |
|
||
return None | ||
|
||
|
||
def normalize_url(url) -> str: | ||
url = url.replace("[email protected]:", "https://github.com/") | ||
if url.endswith('.git'): | ||
url = url[:-4] | ||
if 'github' in url or (GITHUB_ENDPOINT is not None and GITHUB_ENDPOINT in url): | ||
author = os.path.basename(os.path.dirname(url)) | ||
repo_name = os.path.basename(url) | ||
url = f"https://github.com/{author}/{repo_name}" | ||
|
||
return url | ||
|
||
def normalize_url_http(url) -> str: | ||
url = url.replace("https://github.com/", "[email protected]:") | ||
if url.endswith('.git'): | ||
url = url[:-4] | ||
|
||
return url | ||
def get_url_for_clone(url): | ||
url = normalize_url(url) | ||
|
||
if GITHUB_ENDPOINT is not None and url.startswith('https://github.com/'): | ||
url = GITHUB_ENDPOINT + url[18:] # url[18:] -> remove `https://github.com` | ||
|
||
return url | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters