diff --git a/utils/deactivate_empty_repo.py b/utils/deactivate_empty_repo.py index 0d0f7c5..0138b8b 100755 --- a/utils/deactivate_empty_repo.py +++ b/utils/deactivate_empty_repo.py @@ -1,56 +1,57 @@ #!/usr/bin/env python3 from phabricator import Phabricator import arrow date_before = arrow.get().shift(years=-1) phab = Phabricator(host='https://c4science.ch/api/') phab.update_interfaces() def get_repos(after): return phab.diffusion.repository.search( after=after, order="oldest", ) number = 0 total = 0 after = 0 while after != None: repo = get_repos(after) after = repo['cursor']['after'] for r in repo['data']: phid = r['phid'] name = r['fields']['name'] date = arrow.get(r['fields']['dateCreated']) status = r['fields']['status'] url = 'https://c4science.ch/diffusion/{_id}/'.format(_id=r['id']) - total += 1 if r['id'] in [3516, 3518]: continue print('R{_id} {name} {url} {created}'.format( _id=r['id'], name=name, url=url, created=date.humanize())) commits = phab.diffusion.commit.search( limit = 1, constraints = { "repositories": [phid], }, ) if len(commits['data']) == 0: - if status == 'active' and date < date_before: - number += 1 - phab.diffusion.repository.edit( - objectIdentifier = phid, - transactions = [ - {'type': 'status', 'value': 'inactive'}, - ], - ) - print('Deactivated {}'.format(phid)) + if status == 'active': + total += 1 + if date < date_before: + number += 1 + phab.diffusion.repository.edit( + objectIdentifier = phid, + transactions = [ + {'type': 'status', 'value': 'inactive'}, + ], + ) + print('Deactivated {}'.format(phid)) print('Total {} empty repositories'.format(total)) print('Deactivated {} repositories'.format(number))