Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option to use Anon HTTPS URIs instead of SSH #35

Merged
merged 2 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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