mirror of
https://github.com/josegonzalez/python-github-backup.git
synced 2025-12-05 08:08:02 +01:00
josegonzales/python-github-backup#12 Added backup of labels and milestones.
This commit is contained in:
@@ -102,6 +102,8 @@ def parse_args():
|
||||
parser.add_argument('--pulls', action='store_true', dest='include_pulls', help='include pull requests in backup')
|
||||
parser.add_argument('--pull-comments', action='store_true', dest='include_pull_comments', help='include pull request review comments in backup')
|
||||
parser.add_argument('--pull-commits', action='store_true', dest='include_pull_commits', help='include pull request commits in backup')
|
||||
parser.add_argument('--labels', action='store_true', dest='include_labels', help='include labels in backup')
|
||||
parser.add_argument('--milestones', action='store_true', dest='include_milestones', help='include milestones in backup')
|
||||
parser.add_argument('--repositories', action='store_true', dest='include_repository', help='include repository clone in backup')
|
||||
parser.add_argument('--wikis', action='store_true', dest='include_wiki', help='include wiki clone in backup')
|
||||
parser.add_argument('--skip-existing', action='store_true', dest='skip_existing', help='skip project if a backup directory exists')
|
||||
@@ -351,6 +353,47 @@ def backup_repositories(args, output_directory, repositories):
|
||||
with open('{0}/{1}.json'.format(pulls_cwd, number), 'w') as pull_file:
|
||||
json.dump(pull, pull_file, sort_keys=True, indent=4, separators=(',', ': '))
|
||||
|
||||
if args.include_milestones or args.include_everything:
|
||||
if args.skip_existing and os.path.isdir('{0}/milestones/.git'.format(repo_cwd)):
|
||||
continue
|
||||
|
||||
log_info('Retrieving {0} milestones'.format(repository['full_name']))
|
||||
milestone_cwd = os.path.join(repo_cwd, 'milestones')
|
||||
mkdir_p(backup_cwd, repo_cwd, milestone_cwd)
|
||||
|
||||
milestones = {}
|
||||
_milestone_template = '{0}/{1}/milestones'.format(repos_template, repository['full_name'])
|
||||
|
||||
query_args = {
|
||||
'state': 'all'
|
||||
}
|
||||
|
||||
_milestones = retrieve_data(args, _milestone_template, query_args=query_args)
|
||||
|
||||
for milestone in _milestones:
|
||||
milestones[milestone['number']] = milestone
|
||||
|
||||
log_info('Saving {0} milestones to disk'.format(len(milestones.keys())))
|
||||
for number, milestone in milestones.iteritems():
|
||||
with open('{0}/{1}.json'.format(milestone_cwd, number), 'w') as milestone_file:
|
||||
json.dump(milestone, milestone_file, sort_keys=True, indent=4, separators=(',', ': '))
|
||||
|
||||
if args.include_labels or args.include_everything:
|
||||
if args.skip_existing and os.path.isdir('{0}/labels/.git'.format(repo_cwd)):
|
||||
continue
|
||||
|
||||
log_info('Retrieving {0} labels'.format(repository['full_name']))
|
||||
label_cwd = os.path.join(repo_cwd, 'labels')
|
||||
mkdir_p(backup_cwd, repo_cwd, label_cwd)
|
||||
|
||||
_label_template = '{0}/{1}/labels'.format(repos_template, repository['full_name'])
|
||||
|
||||
labels = retrieve_data(args, _label_template, query_args={})
|
||||
|
||||
log_info('Saving {0} labels to disk'.format(len(labels)))
|
||||
with open('{0}/labels.json'.format(label_cwd), 'w') as label_file:
|
||||
json.dump(labels, label_file, sort_keys=True, indent=4, separators=(',', ': '))
|
||||
|
||||
|
||||
def fetch_repository(name, remote_url, local_dir, skip_existing=False):
|
||||
clone_exists = os.path.exists(os.path.join(local_dir, '.git'))
|
||||
@@ -362,7 +405,7 @@ def fetch_repository(name, remote_url, local_dir, skip_existing=False):
|
||||
if initalized == 128:
|
||||
log_info("Skipping {} since it's not initalized".format(name))
|
||||
return
|
||||
|
||||
|
||||
if clone_exists:
|
||||
log_info('Updating {} in {}'.format(name, local_dir))
|
||||
git_command = ['git', 'fetch', '--all', '--tags', '--prune']
|
||||
|
||||
Reference in New Issue
Block a user