-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from SeongjunJo/enhance_git_clone
Add functions to clone private repository and ssh url
- Loading branch information
Showing
2 changed files
with
29 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,7 @@ If you give a link, the source is downloaded to the target directory through git | |
|
||
#### How it works | ||
1. Try git clone. | ||
1-1. If the link is ssh-url, convert to https-url. | ||
2. If git clone fails, download it with wget and extract the compressed file. | ||
3. After extracting the compressed file, delete the compressed file. | ||
|
||
|
@@ -127,7 +128,11 @@ If you give a link, the source is downloaded to the target directory through git | |
|
||
#### How to run | ||
``` | ||
$ fosslight_download -s "https://github.com/LGE-OSS/example" -t target_dir/ | ||
$ fosslight_download -s "https://github.com/LGE-OSS/example" -t target_dir/ | ||
``` | ||
If you want to try with private repository, set your github token like below. | ||
``` | ||
$ fosslight_download -s "https://[email protected]/Foo/private_repo -t target_dir/" | ||
``` | ||
|
||
## 👏 How to report issue | ||
|
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 |
---|---|---|
|
@@ -61,13 +61,21 @@ def change_src_link_to_https(src_link): | |
return src_link | ||
|
||
|
||
def change_ssh_link_to_https(src_link): | ||
src_link = src_link.replace("[email protected]:", "https://github.com/") | ||
return src_link | ||
|
||
|
||
def parse_src_link(src_link): | ||
src_info = {"url": src_link} | ||
src_link_changed = "" | ||
if src_link.startswith("git://") or src_link.startswith("https://") or src_link.startswith("http://"): | ||
if src_link.startswith("git://") or src_link.startswith("git@") \ | ||
or src_link.startswith("https://") or src_link.startswith("http://"): | ||
src_link_split = src_link.split(';') | ||
if src_link.startswith("git://github.com/"): | ||
src_link_changed = change_src_link_to_https(src_link_split[0]) | ||
elif src_link.startswith("[email protected]:"): | ||
src_link_changed = change_ssh_link_to_https(src_link_split[0]) | ||
else: | ||
if "rubygems.org" in src_link: | ||
src_info["rubygems"] = True | ||
|
@@ -205,11 +213,24 @@ def get_github_ossname(link): | |
return oss_name | ||
|
||
|
||
def get_github_token(git_url): | ||
github_token = "" | ||
pattern = r'https://(.*?)@' | ||
search = re.search(pattern, git_url) | ||
if search: | ||
github_token = search.group(1) | ||
return github_token | ||
|
||
|
||
def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""): | ||
ref_to_checkout = decide_checkout(checkout_to, tag, branch) | ||
msg = "" | ||
oss_name = get_github_ossname(git_url) | ||
oss_version = "" | ||
github_token = get_github_token(git_url) | ||
callbacks = None | ||
if github_token != "": | ||
callbacks = git.RemoteCallbacks(credentials=git.UserPass("foo", github_token)) # username is not used, so set to dummy | ||
|
||
if platform.system() != "Windows": | ||
signal.signal(signal.SIGALRM, alarm_handler) | ||
|
@@ -221,7 +242,7 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""): | |
Path(target_dir).mkdir(parents=True, exist_ok=True) | ||
repo = git.clone_repository(git_url, target_dir, | ||
bare=False, repository=None, | ||
remote=None, callbacks=None) | ||
remote=None, callbacks=callbacks) | ||
if platform.system() != "Windows": | ||
signal.alarm(0) | ||
else: | ||
|