From 8fd0f2b64f091e857d4a9228ee3ce1171a74807c Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Sat, 15 Aug 2020 17:21:59 -0700 Subject: [PATCH 1/5] Do not use bare excepts --- github_backup/github_backup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index f6fd158..416d9ea 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -30,9 +30,11 @@ try: from urllib.request import Request from urllib.request import HTTPRedirectHandler from urllib.request import build_opener + from subprocess import SubprocessError except ImportError: # python 2 PY2 = True + from subprocess import CalledProcessError as SubprocessError from urlparse import urlparse from urllib import quote as urlquote from urllib import urlencode @@ -363,7 +365,7 @@ def get_auth(args, encode=True, for_git_cli=False): if not PY2: token = token.decode('utf-8') auth = token + ':' + 'x-oauth-basic' - except: + except SubprocessError: log_error('No password item matching the provided name and account could be found in the osx keychain.') elif args.osx_keychain_item_account: log_error('You must specify both name and account fields for osx keychain password items') From bb2e2b8c6f6a6aa6102f362e27bd3e84537c0cf7 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Sat, 15 Aug 2020 17:23:44 -0700 Subject: [PATCH 2/5] Fix whitespace issues --- github_backup/github_backup.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index 416d9ea..2e56279 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -424,7 +424,7 @@ def get_github_repo_url(args, repository): if args.prefer_ssh: # The git_pull_url value is always https for gists, so we need to transform it to ssh form repo_url = re.sub('^https?:\/\/(.+)\/(.+)\.git$', r'git@\1:\2.git', repository['git_pull_url']) - repo_url = re.sub('^git@gist\.', 'git@', repo_url) # strip gist subdomain for better hostkey compatibility + repo_url = re.sub('^git@gist\.', 'git@', repo_url) # strip gist subdomain for better hostkey compatibility else: repo_url = repository['git_pull_url'] return repo_url @@ -497,9 +497,11 @@ def retrieve_data_gen(args, template, query_args=None, single_request=False): if single_request: break + def retrieve_data(args, template, query_args=None, single_request=False): return list(retrieve_data_gen(args, template, query_args, single_request)) + def get_query_args(query_args=None): if not query_args: query_args = {} @@ -903,18 +905,22 @@ def backup_pulls(args, repo_cwd, repository, repos_template): pull_states = ['open', 'closed'] for pull_state in pull_states: query_args['state'] = pull_state - _pulls = retrieve_data_gen(args, - _pulls_template, - query_args=query_args) + _pulls = retrieve_data_gen( + args, + _pulls_template, + query_args=query_args + ) for pull in _pulls: if args.since and pull['updated_at'] < args.since: break if not args.since or pull['updated_at'] >= args.since: pulls[pull['number']] = pull else: - _pulls = retrieve_data_gen(args, - _pulls_template, - query_args=query_args) + _pulls = retrieve_data_gen( + args, + _pulls_template, + query_args=query_args + ) for pull in _pulls: if args.since and pull['updated_at'] < args.since: break From fa27988c1cd8e6565d33ed196bf1124d5c4b7583 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Sat, 15 Aug 2020 17:24:25 -0700 Subject: [PATCH 3/5] Update boolean check --- github_backup/github_backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index 2e56279..a1e1a20 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -433,7 +433,7 @@ def get_github_repo_url(args, repository): return repository['ssh_url'] auth = get_auth(args, encode=False, for_git_cli=True) - if auth and repository['private'] == True: + if auth and repository['private'] is True: repo_url = 'https://{0}@{1}/{2}/{3}.git'.format( auth, get_github_host(args), From 78cff47a911a438975fce524fa5edd2285c2e06b Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Sat, 15 Aug 2020 17:26:04 -0700 Subject: [PATCH 4/5] Fix regex string --- github_backup/github_backup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github_backup/github_backup.py b/github_backup/github_backup.py index a1e1a20..68bfb59 100644 --- a/github_backup/github_backup.py +++ b/github_backup/github_backup.py @@ -423,8 +423,8 @@ def get_github_repo_url(args, repository): if repository.get('is_gist'): if args.prefer_ssh: # The git_pull_url value is always https for gists, so we need to transform it to ssh form - repo_url = re.sub('^https?:\/\/(.+)\/(.+)\.git$', r'git@\1:\2.git', repository['git_pull_url']) - repo_url = re.sub('^git@gist\.', 'git@', repo_url) # strip gist subdomain for better hostkey compatibility + repo_url = re.sub(r'^https?:\/\/(.+)\/(.+)\.git$', r'git@\1:\2.git', repository['git_pull_url']) + repo_url = re.sub(r'^git@gist\.', 'git@', repo_url) # strip gist subdomain for better hostkey compatibility else: repo_url = repository['git_pull_url'] return repo_url From 2de96390be5b613045b89e8fcdadd7c946d75dc1 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Sat, 15 Aug 2020 17:27:22 -0700 Subject: [PATCH 5/5] Add flake8 instructions to readme --- README.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.rst b/README.rst index 7edb74f..a53a373 100644 --- a/README.rst +++ b/README.rst @@ -166,6 +166,15 @@ Backup a single organization repository with everything else (wiki, pull request # e.g. git@github.com:docker/cli.git github-backup $ORGANIZATION -P -t $ACCESS_TOKEN -o . --all -O -R $REPO +Testing +======= + +This project currently contains no unit tests. To run linting:: + + pip install flake8 + flake8 --ignore=E501 + + .. |PyPI| image:: https://img.shields.io/pypi/v/github-backup.svg :target: https://pypi.python.org/pypi/github-backup/ .. |Python Versions| image:: https://img.shields.io/pypi/pyversions/github-backup.svg