Skip to content

Commit

Permalink
Add Option to use Anon HTTPS URIs instead of SSH (#35)
Browse files Browse the repository at this point in the history
* Add Option to use Anon HTTPS URIs instead of SSH

Without this option, the only URL used to clone a repo was the SSH URL.
This adds a simple flag to switch clone operations to using the HTTPS
URL. The default behavior of using SSH is preserved so as to not break
scripts, etc.

* Add trailing commas
  • Loading branch information
danieldjewell committed Sep 16, 2021
1 parent b050473 commit 6850ecb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Options:
Provide your GitHub token to authenticate with the GitHub API and gain access to private repos and gists.
-l LOCATION, --location LOCATION
The location where you want your GitHub Archive to be stored.
-ht, --https Use HTTPS URLs instead of SSH.
```

### Automating SSH Passphrase Prompt (Recommended)
Expand Down
8 changes: 7 additions & 1 deletion github_archive/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(
threads=DEFAULT_NUM_THREADS,
token=None,
location=DEFAULT_LOCATION,
use_https=False,
):
# Parameter variables
self.view = view
Expand All @@ -51,6 +52,7 @@ def __init__(
self.threads = threads
self.token = token
self.location = location
self.use_https = use_https
# Internal variables
self.github_instance = Github(self.token) if self.token else Github()
self.authenticated_user = self.github_instance.get_user() if self.token else None
Expand Down Expand Up @@ -270,9 +272,13 @@ def archive_repo(self, thread_limiter, repo, repo_path, operation):
pass
else:
commands = {
CLONE_OPERATION: f'git clone {repo.ssh_url} {repo_path}',
PULL_OPERATION: f'cd {repo_path} && git pull --rebase',
}

if self.use_https:
commands.update({CLONE_OPERATION: f'git clone {repo.html_url} {repo_path}'})
else:
commands.update({CLONE_OPERATION: f'git clone {repo.ssh_url} {repo_path}'})
git_command = commands[operation]

try:
Expand Down
9 changes: 9 additions & 0 deletions github_archive/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ def __init__(self):
default=DEFAULT_LOCATION,
help='The location where you want your GitHub Archive to be stored.',
)
parser.add_argument(
'-ht',
'--https',
action='store_true',
required=False,
default=False,
help='Use HTTPS URLs instead of SSH.',
)
parser.parse_args(namespace=self)

def run(self):
Expand All @@ -126,6 +134,7 @@ def run(self):
threads=self.threads,
token=self.token,
location=self.location,
use_https=self.https,
)
github_archive.run()

Expand Down

0 comments on commit 6850ecb

Please sign in to comment.