Skip to content

Commit 0a4decf

Browse files
committed
Add option to backup additional PR details
Some payload is only included when requesting a single pull request
1 parent 2b9549f commit 0a4decf

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

bin/github-backup

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ def parse_args():
192192
action='store_true',
193193
dest='include_pull_commits',
194194
help='include pull request commits in backup')
195+
parser.add_argument('--pull-details',
196+
action='store_true',
197+
dest='include_pull_details',
198+
help='include more pull request details in backup')
195199
parser.add_argument('--labels',
196200
action='store_true',
197201
dest='include_labels',
@@ -656,23 +660,35 @@ def backup_pulls(args, repo_cwd, repository, repos_template):
656660
pulls = {}
657661
_pulls_template = '{0}/{1}/pulls'.format(repos_template,
658662
repository['full_name'])
663+
query_args = {
664+
'filter': 'all',
665+
'state': 'all',
666+
'sort': 'updated',
667+
'direction': 'desc',
668+
}
659669

660-
pull_states = ['open', 'closed']
661-
for pull_state in pull_states:
662-
query_args = {
663-
'filter': 'all',
664-
'state': pull_state,
665-
'sort': 'updated',
666-
'direction': 'desc',
667-
}
668-
669-
# It'd be nice to be able to apply the args.since filter here...
670+
if not args.include_pull_details:
671+
pull_states = ['open', 'closed']
672+
for pull_state in pull_states:
673+
query_args['state'] = pull_state
674+
# It'd be nice to be able to apply the args.since filter here...
675+
_pulls = retrieve_data(args,
676+
_pulls_template,
677+
query_args=query_args)
678+
for pull in _pulls:
679+
if not args.since or pull['updated_at'] >= args.since:
680+
pulls[pull['number']] = pull
681+
else:
670682
_pulls = retrieve_data(args,
671683
_pulls_template,
672684
query_args=query_args)
673685
for pull in _pulls:
674686
if not args.since or pull['updated_at'] >= args.since:
675-
pulls[pull['number']] = pull
687+
pulls[pull['number']] = retrieve_data(
688+
args,
689+
_pulls_template + '/{}'.format(pull['number']),
690+
single_request=True
691+
)
676692

677693
log_info('Saving {0} pull requests to disk'.format(
678694
len(list(pulls.keys()))))

0 commit comments

Comments
 (0)