This repository has been archived by the owner on Jan 31, 2019. It is now read-only.
/
fog_bugz.rb
49 lines (42 loc) · 1.59 KB
/
fog_bugz.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::FogBugz < Service
string :cvssubmit_url, :fb_repoid, :fb_version
white_list :cvssubmit_url, :fb_repoid, :fb_version
def receive_push
if (fb_url = data['cvssubmit_url']).blank?
raise_config_error "Invalid FogBugz URL"
end
# FIXME
http.ssl[:verify] = false
repository = payload['repository']['name']
branch = branch_name
before = payload['before']
payload['commits'].each do |commit|
commit_id = commit['id']
message = commit["message"]
files = commit["removed"] | commit["added"] | commit["modified"]
# look for a bug id in each line of the commit message
bug_list = []
message.split("\n").each do |line|
# match variants of bugids or cases
if (line =~ /\s*(?:Bug[zs]*\s*IDs*\s*|Case[s]*)[#:; ]+((\d+[ ,:;#]*)+)/i)
bug_list << $1.to_i
end
end
# for each found bugzid, submit the files to fogbugz.
bug_list.each do |fb_bugzid|
files.each do |f|
# build the GET request, and send it to fogbugz
params = {:ixBug => fb_bugzid, :sFile => "#{branch}/#{f}", :sPrev => before, :sNew => commit_id}
if data['fb_version'] == '6'
# FogBugz 6 created repositories automatically upon source checkin based on "sRepo"
params[:sRepo] = repository
else
# FogBugz 7 and later requires you to create the repo in FogBugz and supply "ixRepository" here
params[:ixRepository] = data['fb_repoid']
end
http_get fb_url, params
end
end
end
end
end