2012-09-19 150 views

回答

5

搜索了很長一段時間,我發現後該解決方案,我在這裏發佈的任何其他人誰有興趣使Git/Gerrit鉤做像我這樣的事情:

首先在您的瀏覽器中打開http://example.com/rest/api/2/issue/<ISSUE>/transitions?expand=transitions.fields以查找您的網站和問題編號以查找轉換ID。

假如這是1000:

import urllib 
import urllib2 
import base64 
import json 

key = 'JIRA-123' 
comment = "It's done!" 
username = 'username' 
password = 'password' 

# See http://docs.atlassian.com/jira/REST/latest/#id199544 
url = 'http://example.com/rest/api/2/issue/%s/transitions' % key 
auth = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') 
data = json.dumps({ 
    'transition': { 
     'id': 1000 # Resolved (for my setup) 
    }, 
    'update': { 
     'comment': [ 
      { 
       'add': { 
        'body': comment 
       } 
      } 
     ] 
    }, 
}) 
request = urllib2.Request(url, data, { 
    'Authorization': 'Basic %s' % auth, 
    'Content-Type': 'application/json', 
}) 
print urllib2.urlopen(request).read() 

您可以完全忽略註釋部分,如果你不希望添加評論。