From 944b612d918720e3a3b581aed0d7ac853854a44d Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Thu, 24 Aug 2023 16:07:47 -0600 Subject: [PATCH] feat: adds https flag and clarifies authentication --- .coveragerc | 4 +++- CHANGELOG.md | 8 ++++++++ README.md | 23 ++++++++++++++++++++++- forks_sync/_version.py | 2 +- forks_sync/cli.py | 8 ++++++++ forks_sync/sync.py | 6 +++++- 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/.coveragerc b/.coveragerc index 85167aa..6e3604c 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,2 +1,4 @@ [run] -omit = forks_sync/cli.py +omit = + forks_sync/cli.py + forks_sync/_version.py diff --git a/CHANGELOG.md b/CHANGELOG.md index a7af6da..c558544 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,15 @@ # CHANGELOG +## v4.2.0 (2023-08-24) + +- Corrects the premature URL changes from `v4.1.0` + - Restores the previous behavior of using the SSH URL by default + - Adds new `--https` flag that will trigger using the `clone_url` instead of the default `ssh_url` + ## v4.1.0 (2023-08-24) +**NOTE:** Please do not use this release! It has been yanked from PyPi + - Swaps the `ssh_url` for the `clone_url` when cloning repos to remove the unnecessary reliance on having an SSH key or agent to use this tool - Adds `--version` CLI flag diff --git a/README.md b/README.md index 50ee904..568dde9 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ just install ```text Usage: - forks-sync --token 123... + forks-sync --token 123 Options: -h, --help show this help message and exit @@ -49,6 +49,27 @@ Options: --version show program's version number and exit ``` +### Authentication + +There are two methods of authentication with this tool. The `--token` flag is required in addition to one of the following: + +#### SSH + +To allow the script to run continuosly without requiring passwords for every repo, you can add your SSH passphrase to the SSH agent: + +```bash +# This assumes you've saved your SSH keys to the default location +ssh-add +``` + +You can then run a command similar to `forks-sync --token 123` where the token is your GitHub API token. This will authenticate you with the GitHub API via the `token` and with GitHub via `ssh`. + +#### Git Credential Manager + +Alternatively, you can use a tool like [Git Credential Manager](https://github.com/git-ecosystem/git-credential-manager) to populate your Git credentials under the hood. When not using SSH, we'll clone from the git URLs instead of the SSH URLs. To trigger this behavior, you must pass the `--https` flag. + +You can then run a command similar to `forks-sync --token 123 --https` where the token is your GitHub API token. This will authenticate you with the GitHub API via the `token` and with GitHub via your Git credentials via `GCM`. + ## Development ```bash diff --git a/forks_sync/_version.py b/forks_sync/_version.py index fa721b4..ea5d65f 100644 --- a/forks_sync/_version.py +++ b/forks_sync/_version.py @@ -1 +1 @@ -__version__ = '4.1.0' +__version__ = '4.2.0' diff --git a/forks_sync/cli.py b/forks_sync/cli.py index e312183..138b8f0 100644 --- a/forks_sync/cli.py +++ b/forks_sync/cli.py @@ -30,6 +30,13 @@ def __init__(self): default=False, help='Pass this flag to force push changes to forked repos, otherwise the tool will run in "dry mode".', ), + parser.add_argument( + '--https', + action='store_true', + required=False, + default=False, + help='Use HTTPS URLs instead of SSH.', + ) parser.add_argument( '-th', '--threads', @@ -65,6 +72,7 @@ def run(self): forks_sync = ForksSync( token=self.token, force=self.force, + use_https=self.https, threads=self.threads, timeout=self.timeout, location=self.location, diff --git a/forks_sync/sync.py b/forks_sync/sync.py index 0dd65a6..34340bd 100644 --- a/forks_sync/sync.py +++ b/forks_sync/sync.py @@ -34,6 +34,7 @@ def __init__( self, token: Optional[str] = None, force: bool = False, + use_https: bool = False, threads: int = DEFAULT_NUM_THREADS, timeout: int = DEFAULT_TIMEOUT, location: str = DEFAULT_LOCATION, @@ -41,6 +42,7 @@ def __init__( # Parameter variables self.token = token self.force = force + self.use_https = use_https self.threads = threads self.timeout = timeout self.location = location @@ -136,8 +138,10 @@ def clone_repo(self, thread_limiter: BoundedSemaphore, repo: Repository.Reposito """Clone projects that don't exist locally.""" logger = woodchips.get(LOGGER_NAME) + repo_url = repo.clone_url if self.use_https else repo.ssh_url + commands = [ - ['git', 'clone', '--depth=1', repo.clone_url, repo_path], + ['git', 'clone', '--depth=1', repo_url, repo_path], ['git', '-C', repo_path, 'remote', 'add', 'upstream', repo.parent.clone_url], ]