diff --git a/utils/deactivate_empty_repo.py b/utils/deactivate_empty_repo.py index 0138b8b..173864c 100755 --- a/utils/deactivate_empty_repo.py +++ b/utils/deactivate_empty_repo.py @@ -1,57 +1,57 @@ #!/usr/bin/env python3 from phabricator import Phabricator import arrow -date_before = arrow.get().shift(years=-1) +date_before = arrow.get().shift(months=-6) 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']) - if r['id'] in [3516, 3518]: + if r['id'] in [3516, 3518] or r['id'] < 5769: 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': 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))