Skip to content

Commit

Permalink
Check both updated_at and pushed_at properties
Browse files Browse the repository at this point in the history
Check both updated_at and pushed_at dates to get the last_update to reduce data retrieved on incremental api calls using since.
  • Loading branch information
kenbailey committed Feb 28, 2023
1 parent 07e32b1 commit fbb977a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion github_backup/github_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@ def backup_repositories(args, output_directory, repositories):
repos_template = 'https://{0}/repos'.format(get_github_api_host(args))

if args.incremental:
last_update = max(list(repository['updated_at'] for repository in repositories) or [time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime())]) # noqa
last_update_path = os.path.join(output_directory, 'last_update')
if os.path.exists(last_update_path):
args.since = open(last_update_path).read().strip()
Expand All @@ -777,7 +776,13 @@ def backup_repositories(args, output_directory, repositories):
else:
args.since = None

last_update = '0000-00-00T00:00:00Z'
for repository in repositories:
if 'updated_at' in repository and repository['updated_at'] > last_update:
last_update = repository['updated_at']
elif 'pushed_at' in repository and repository['pushed_at'] > last_update:
last_update = repository['pushed_at']

if repository.get('is_gist'):
repo_cwd = os.path.join(output_directory, 'gists', repository['id'])
elif repository.get('is_starred'):
Expand Down Expand Up @@ -840,6 +845,9 @@ def backup_repositories(args, output_directory, repositories):
include_assets=args.include_assets or args.include_everything)

if args.incremental:
if last_update == '0000-00-00T00:00:00Z':
last_update = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime())

open(last_update_path, 'w').write(last_update)


Expand Down

0 comments on commit fbb977a

Please sign in to comment.