disable comment job trigger for v2 branch

This commit is contained in:
andyque 2015-04-13 09:57:49 +08:00
parent fdb03f150d
commit 68f86adab1
1 changed files with 30 additions and 28 deletions

View File

@ -7,9 +7,9 @@ import traceback
import urllib2 import urllib2
http_proxy = '' http_proxy = ''
if(os.environ.has_key('HTTP_PROXY')): if('HTTP_PROXY' in os.environ):
http_proxy = os.environ['HTTP_PROXY'] http_proxy = os.environ['HTTP_PROXY']
proxyDict = {'http':http_proxy,'https':http_proxy} proxyDict = {'http': http_proxy, 'https': http_proxy}
def main(): def main():
#get payload from os env #get payload from os env
@ -23,8 +23,8 @@ def main():
#get pull number #get pull number
pr_num = issue['number'] pr_num = issue['number']
print 'pr_num:' + str(pr_num) print 'pr_num:' + str(pr_num)
payload_forword = {"number":pr_num} payload_forword = {"number": pr_num}
comment = payload['comment'] comment = payload['comment']
#get comment body #get comment body
comment_body = comment['body'] comment_body = comment['body']
@ -38,12 +38,12 @@ def main():
if searchCI is None and searchConsole is None: if searchCI is None and searchConsole is None:
print 'skip build for pull request #' + str(pr_num) print 'skip build for pull request #' + str(pr_num)
return(0) return(0)
#build for pull request action 'open' and 'synchronize', skip 'close' #build for pull request action 'open' and 'synchronize', skip 'close'
action = issue['state'] action = issue['state']
print 'action: ' + action print 'action: ' + action
payload_forword['action'] = action payload_forword['action'] = action
pr = issue['pull_request'] pr = issue['pull_request']
url = pr['html_url'] url = pr['html_url']
print "url:" + url print "url:" + url
@ -74,20 +74,22 @@ def main():
#set commit status to pending #set commit status to pending
target_url = os.environ['JOB_PULL_REQUEST_BUILD_URL'] target_url = os.environ['JOB_PULL_REQUEST_BUILD_URL']
if(action == 'closed' or action == 'assigned'): if(action == 'closed' or action == 'assigned' or branch == 'v2'):
print 'pull request #' + str(pr_num) + ' is '+action+', no build triggered' print 'pull request #' + str(pr_num) + ' is ' + action + ', no build triggered'
return(0) return(0)
data = {"state":"pending", "target_url":target_url, "context":"Jenkins CI", "description":"Wait available build machine..."} data = {"state": "pending", "target_url": target_url, "context": "Jenkins CI",
"description": "Wait available build machine..."}
access_token = os.environ['GITHUB_ACCESS_TOKEN'] access_token = os.environ['GITHUB_ACCESS_TOKEN']
Headers = {"Authorization":"token " + access_token} Headers = {"Authorization": "token " + access_token}
try: try:
if searchCI: if searchCI:
ciOper = searchCI.group() ciOper = searchCI.group()
if('rebuild' in ciOper): if('rebuild' in ciOper):
requests.post(statuses_url, data=json.dumps(data), headers=Headers, proxies = proxyDict) requests.post(statuses_url, data=json.dumps(data),
headers=Headers, proxies=proxyDict)
except: except:
traceback.print_exc() traceback.print_exc()
@ -95,15 +97,15 @@ def main():
if searchCI: if searchCI:
ciOper = searchCI.group() ciOper = searchCI.group()
if('rebuild' in ciOper): if('rebuild' in ciOper):
job_trigger_url = os.environ['JOB_PULL_REQUEST_BUILD_TRIGGER_URL'] job_trigger_url = os.environ['JOB_PULL_REQUEST_BUILD_TRIGGER_URL']
if('emptytest' in ciOper): if('emptytest' in ciOper):
job_trigger_url = os.environ['JOB_EMPTYTEST_TRIGGER_URL'] job_trigger_url = os.environ['JOB_EMPTYTEST_TRIGGER_URL']
if('release' in ciOper): if('release' in ciOper):
searchTag = re.search('\[ci release (.*)\]', ciOper) searchTag = re.search('\[ci release (.*)\]', ciOper)
if searchTag: if searchTag:
ci_tag = searchTag.group(1) ci_tag = searchTag.group(1)
payload_forword['tag'] = ci_tag payload_forword['tag'] = ci_tag
job_trigger_url = os.environ['JOB_RELEASE_TRIGGER_URL'] job_trigger_url = os.environ['JOB_RELEASE_TRIGGER_URL']
if searchConsole: if searchConsole:
consoleOper = searchConsole.group() consoleOper = searchConsole.group()
job_trigger_url = os.environ['JOB_CONSOLE_TEST_TRIGGER_URL'] job_trigger_url = os.environ['JOB_CONSOLE_TEST_TRIGGER_URL']
@ -112,19 +114,19 @@ def main():
#send trigger and payload #send trigger and payload
if('tag' in payload_forword): if('tag' in payload_forword):
post_data = {'tag':""} post_data = {'tag': ""}
post_data['tag'] = payload_forword['tag'] post_data['tag'] = payload_forword['tag']
else: else:
post_data = {'payload':""} post_data = {'payload': ""}
post_data['payload']= json.dumps(payload_forword) post_data['payload'] = json.dumps(payload_forword)
requests.post(job_trigger_url, data=post_data, proxies = proxyDict) requests.post(job_trigger_url, data=post_data, proxies=proxyDict)
return(0) return(0)
# -------------- main -------------- # -------------- main --------------
if __name__ == '__main__': if __name__ == '__main__':
sys_ret = 0 sys_ret = 0
try: try:
sys_ret = main() sys_ret = main()
except: except:
traceback.print_exc() traceback.print_exc()