From bb051d473715c4e6e4dd3c4fc8add89508ccf8e0 Mon Sep 17 00:00:00 2001 From: Daniel Jewell <23286051+danieldjewell@users.noreply.github.com> Date: Mon, 13 Sep 2021 10:45:19 -0700 Subject: [PATCH 1/2] 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. --- README.md | 1 + github_archive/archive.py | 8 +++++++- github_archive/cli.py | 9 +++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6983d9f..54ff1de 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/github_archive/archive.py b/github_archive/archive.py index ae3bbae..85ba16c 100644 --- a/github_archive/archive.py +++ b/github_archive/archive.py @@ -37,6 +37,7 @@ def __init__( threads=DEFAULT_NUM_THREADS, token=None, location=DEFAULT_LOCATION, + use_https=False ): # Parameter variables self.view = view @@ -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 @@ -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: diff --git a/github_archive/cli.py b/github_archive/cli.py index 503a10b..ff2f4d7 100644 --- a/github_archive/cli.py +++ b/github_archive/cli.py @@ -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): @@ -126,6 +134,7 @@ def run(self): threads=self.threads, token=self.token, location=self.location, + use_https=self.https ) github_archive.run() From 8b3646049cfe8b0f9744cd44965232a0cda77cad Mon Sep 17 00:00:00 2001 From: Daniel Jewell <23286051+danieldjewell@users.noreply.github.com> Date: Tue, 14 Sep 2021 17:50:53 -0700 Subject: [PATCH 2/2] Add trailing commas --- github_archive/archive.py | 2 +- github_archive/cli.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/github_archive/archive.py b/github_archive/archive.py index 85ba16c..cb8179b 100644 --- a/github_archive/archive.py +++ b/github_archive/archive.py @@ -37,7 +37,7 @@ def __init__( threads=DEFAULT_NUM_THREADS, token=None, location=DEFAULT_LOCATION, - use_https=False + use_https=False, ): # Parameter variables self.view = view diff --git a/github_archive/cli.py b/github_archive/cli.py index ff2f4d7..bb5da36 100644 --- a/github_archive/cli.py +++ b/github_archive/cli.py @@ -116,7 +116,7 @@ def __init__(self): action='store_true', required=False, default=False, - help='Use HTTPS URLs instead of SSH.' + help='Use HTTPS URLs instead of SSH.', ) parser.parse_args(namespace=self) @@ -134,7 +134,7 @@ def run(self): threads=self.threads, token=self.token, location=self.location, - use_https=self.https + use_https=self.https, ) github_archive.run()