From 0145b78d9fe7c89d9a03fedc5cf4726b4b4e876c Mon Sep 17 00:00:00 2001 From: Lingchaox Xin Date: Wed, 20 Mar 2013 14:47:46 +0800 Subject: [PATCH] Adjust job_deletetag.py for cdbc28c Change-Id: I6ba95d34804ee61bbdbb66f7401ffcc5cee2f2e3 --- job_deletetag.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/job_deletetag.py b/job_deletetag.py index 87f39c2..d7e5dd2 100755 --- a/job_deletetag.py +++ b/job_deletetag.py @@ -11,6 +11,7 @@ import sys from common.git import Git, clone_gitproject from common.gerrit import Gerrit +from common.gerritevent import get_gerrit_event def clone_tmp_git(tmpdir, gerrit_project): @@ -40,27 +41,25 @@ def main(): """The main body""" tmpdir = tempfile.mkdtemp(prefix=(os.getenv('WORKSPACE') + '/')) - gerrit = Gerrit(os.getenv('GERRIT_HOSTNAME'), os.getenv( - 'GERRIT_USERNAME'), os.getenv('GERRIT_SSHPORT')) - patchs = gerrit.query('change:%s --patch-sets' % os.getenv( - 'GERRIT_CHANGE_NUMBER')) - - gerrit_event_type = os.getenv('GERRIT_EVENT_TYPE') - gerrit_project = os.getenv('GERRIT_PROJECT') - - if gerrit_event_type == 'PATCHSET_CREATED': - gerrit_patchset_number = os.getenv('GERRIT_PATCHSET_NUMBER') - if gerrit_patchset_number != '1': + events = get_gerrit_event() + gerrit = Gerrit(events['hostname'], events['username'], + events['sshport']) + 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(gerrit_patchset_number)-1: - delete_tags(clone_tmp_git(tmpdir, gerrit_project), patch[ - 'revision']) + 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 gerrit_event_type == 'CHANGE_ABANDONED': - mygit = clone_tmp_git(tmpdir, gerrit_project) + 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']) -- 2.7.4