Add option to backup additional PR details

Some payload is only included when requesting a single pull request
This commit is contained in:
Robin Gloster
2017-12-29 21:39:59 +01:00
parent 2b9549ffde
commit 0a4decfb3b

View File

@@ -192,6 +192,10 @@ def parse_args():
action='store_true', action='store_true',
dest='include_pull_commits', dest='include_pull_commits',
help='include pull request commits in backup') help='include pull request commits in backup')
parser.add_argument('--pull-details',
action='store_true',
dest='include_pull_details',
help='include more pull request details in backup')
parser.add_argument('--labels', parser.add_argument('--labels',
action='store_true', action='store_true',
dest='include_labels', dest='include_labels',
@@ -656,23 +660,35 @@ def backup_pulls(args, repo_cwd, repository, repos_template):
pulls = {} pulls = {}
_pulls_template = '{0}/{1}/pulls'.format(repos_template, _pulls_template = '{0}/{1}/pulls'.format(repos_template,
repository['full_name']) repository['full_name'])
query_args = {
'filter': 'all',
'state': 'all',
'sort': 'updated',
'direction': 'desc',
}
pull_states = ['open', 'closed'] if not args.include_pull_details:
for pull_state in pull_states: pull_states = ['open', 'closed']
query_args = { for pull_state in pull_states:
'filter': 'all', query_args['state'] = pull_state
'state': pull_state, # It'd be nice to be able to apply the args.since filter here...
'sort': 'updated', _pulls = retrieve_data(args,
'direction': 'desc', _pulls_template,
} query_args=query_args)
for pull in _pulls:
# It'd be nice to be able to apply the args.since filter here... if not args.since or pull['updated_at'] >= args.since:
pulls[pull['number']] = pull
else:
_pulls = retrieve_data(args, _pulls = retrieve_data(args,
_pulls_template, _pulls_template,
query_args=query_args) query_args=query_args)
for pull in _pulls: for pull in _pulls:
if not args.since or pull['updated_at'] >= args.since: if not args.since or pull['updated_at'] >= args.since:
pulls[pull['number']] = pull pulls[pull['number']] = retrieve_data(
args,
_pulls_template + '/{}'.format(pull['number']),
single_request=True
)
log_info('Saving {0} pull requests to disk'.format( log_info('Saving {0} pull requests to disk'.format(
len(list(pulls.keys())))) len(list(pulls.keys()))))