Merge pull request #157 from albertyw/lint

This commit is contained in:
Jose Diaz-Gonzalez
2020-08-29 02:37:19 -04:00
committed by GitHub
2 changed files with 27 additions and 10 deletions

View File

@@ -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

View File

@@ -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')
@@ -421,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
@@ -431,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),
@@ -495,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 = {}
@@ -901,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 = retrieve_data_gen(
args,
_pulls_template,
query_args=query_args)
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 = retrieve_data_gen(
args,
_pulls_template,
query_args=query_args)
query_args=query_args
)
for pull in _pulls:
if args.since and pull['updated_at'] < args.since:
break