+++ /dev/null
-#!/usr/bin/env python
-# vim: ai ts=4 sts=4 et sw=4
-
-"""This script will delete all tags on abandoned commit adapted from
-job_deletetag.sh"""
-
-import os
-import tempfile
-import shutil
-import sys
-
-from common.git import Git, clone_gitproject
-from common.gerrit import Gerrit, get_gerrit_event
-
-from gbp.git.repository import GitRepositoryError
-
-def clone_tmp_git(tmpdir, gerrit_project):
- """Clone a temp git repo"""
-
- # clone gerrit project to local dir
- if not clone_gitproject(
- gerrit_project, os.path.join(tmpdir, gerrit_project)):
- exit(-1)
-
- return Git(os.path.join(tmpdir, gerrit_project))
-
-
-def delete_tags(mygit, revision):
- """Delete all tags which belongs to the same commit"""
-
- while 1:
- try:
- result = mygit.describe(revision, tags=True, exact_match=True)
- except GitRepositoryError:
- break
- if result:
- mygit.push(repo='origin', src='', dst=result, force=True)
- mygit.delete_tag(result)
-
-def main():
- """The main body"""
-
- tmpdir = tempfile.mkdtemp(prefix=(os.getenv('WORKSPACE') + '/'))
- events = get_gerrit_event()
- gerrit = Gerrit(events['hostname'], events['username'],
- events['sshport'], int(os.getenv('GERRIT_SILENT_MODE')))
- patchs = gerrit.query('change:%s --patch-sets' %
- events['change_number'])
-
- if events['event_type'] == 'patchset-created':
- if events['patchset_number'] != '1':
- for patch in patchs[0]['patchSets']:
- if int(patch['number']) == \
- int(events['patchset_number'])-1:
- delete_tags(clone_tmp_git(tmpdir, \
- events['project']), patch['revision'])
- break
- else:
- print 'Less than 2 patchSets, exit...'
-
- elif events['event_type'] == 'change-abandoned':
- mygit = clone_tmp_git(tmpdir, events['project'])
- for patch in patchs[0]['patchSets']:
- if int(patch['number']) == len(patchs[0]['patchSets']):
- delete_tags(mygit, patch['revision'])
- break
- else:
- print 'Nothing to do...'
-
- shutil.rmtree(tmpdir)
-
-if __name__ == '__main__':
- sys.exit(main())