cleanup script logging and failure count fix
This commit is contained in:
parent
ac3c287766
commit
6fb2c53be8
1 changed files with 7 additions and 10 deletions
|
@ -40,22 +40,19 @@ def delete_old_branches(repo_path: str, max_age: datetime.datetime, branch_patte
|
||||||
print('Found {} branches at {} in total.'.format(len(refs), remote_name))
|
print('Found {} branches at {} in total.'.format(len(refs), remote_name))
|
||||||
del_count = 0
|
del_count = 0
|
||||||
fail_count = 0
|
fail_count = 0
|
||||||
|
if dry_run:
|
||||||
|
print('DRY RUN NO BRANCHES WILL BE DELETED', flush=True)
|
||||||
for reference in refs:
|
for reference in refs:
|
||||||
committed_date = datetime.datetime.fromtimestamp(reference.commit.committed_date)
|
committed_date = datetime.datetime.fromtimestamp(reference.commit.committed_date)
|
||||||
if committed_date < max_age and _has_pattern_match(reference.name, branch_patterns):
|
if committed_date < max_age and _has_pattern_match(reference.name, branch_patterns):
|
||||||
if dry_run:
|
print('Deleting {}'.format(reference.name), flush=True)
|
||||||
print('dryrun: would have been deleted {}'.format(reference.name))
|
del_count += 1
|
||||||
sys.stdout.flush()
|
if not dry_run:
|
||||||
else:
|
|
||||||
print('Deleting {}'.format(reference.name))
|
|
||||||
sys.stdout.flush()
|
|
||||||
try:
|
try:
|
||||||
remote.push(refspec=':{}'.format(reference.remote_head))
|
remote.push(refspec=':{}'.format(reference.remote_head))
|
||||||
del_count += 1
|
|
||||||
except git.GitCommandError:
|
except git.GitCommandError:
|
||||||
print('ERROR: Failed to delete {}.'.format(reference.name))
|
print('ERROR: Failed to delete {}.'.format(reference.name), flush=True)
|
||||||
fail_count = 0
|
fail_count += 1
|
||||||
|
|
||||||
print('Deleted {} branches.'.format(del_count))
|
print('Deleted {} branches.'.format(del_count))
|
||||||
if fail_count > 0:
|
if fail_count > 0:
|
||||||
print('Failed to delete {} branches.'.format(fail_count))
|
print('Failed to delete {} branches.'.format(fail_count))
|
||||||
|
|
Loading…
Reference in a new issue