This repository has been archived by the owner on Jan 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
jira.rb
49 lines (39 loc) · 1.52 KB
/
jira.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Service::Jira < Service
string :server_url, :api_version, :username
password :password
white_list :api_version, :server_url, :username
def receive_push
payload['commits'].each do |commit|
next if commit['message'] =~ /^x /
comment_body = "#{commit['message']}\n#{commit['url']}"
commit['message'].match(/\[#(.+)\]/)
# Don't need to continue if we don't have a commit message containing JIRA markup
next unless $1
jira_markup = $1.split
issue_id = jira_markup.shift
changeset = { :comment => { :body => comment_body } }
jira_markup.each do |entry|
key, value = entry.split(':')
if key =~ /(?i)status|(?i)transition/
changeset.merge!(:transition => value.to_i)
elsif key =~ /(?i)resolution/
changeset.merge!(:fields => { :resolution => value.to_i })
else
changeset.merge!(:fields => { key.to_sym => "Resolved" })
end
end
# Don't need to continue if we don't have a transition to perform
next unless changeset.has_key?(:transition)
begin
# :(
http.ssl[:verify] = false
http.basic_auth data['username'], data['password']
http.headers['Content-Type'] = 'application/json'
res = http_post '%s/rest/api/%s/issue/%s/transitions' % [data['server_url'], data['api_version'], issue_id],
changeset.to_json
rescue URI::InvalidURIError
raise_config_error "Invalid server_hostname: #{data['server_url']}"
end
end
end
end