Add branch regex to irc client #283

Merged
merged 2 commits into from Apr 18, 2012
View
@@ -1,10 +1,11 @@
class Service::IRC < Service
- string :server, :port, :room, :nick
+ string :server, :port, :room, :nick, :branch_regexes
password :password
boolean :ssl, :message_without_join, :no_colors, :long_url, :notice
def receive_push
return if distinct_commits.empty?
+ return unless branch_name_matches?
url = data['long_url'].to_i == 1 ? summary_url : shorten_url(summary_url)
@@ -117,4 +118,14 @@ def format_commit_message(commit)
"\002#{sha1[0..6]}\002 (#{files.size} files in #{dirs.size} dirs): #{short}"
end
end
+
+ def branch_name_matches?
+ return true if data['branch_regexes'].nil?
+ return true if data['branch_regexes'].strip == ""
+ branch_regexes = data['branch_regexes'].split(',')
+ branch_regexes.each do |regex|
+ return true if Regexp.new(regex) =~ branch_name
+ end
+ false
+ end
end
View
@@ -44,6 +44,90 @@ def test_push
assert_equal "QUIT", msgs.shift.strip
assert_nil msgs.shift
end
+
+ def test_push_with_empty_branch_regex
+ svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => ''}, payload)
+
+ svc.receive_push
+ msgs = svc.writable_io.string.split("\n")
+ assert_equal "NICK n", msgs.shift
+ assert_match "USER n", msgs.shift
+ assert_equal "JOIN #r", msgs.shift.strip
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_equal "PART #r", msgs.shift.strip
+ assert_equal "QUIT", msgs.shift.strip
+ assert_nil msgs.shift
+ end
+
+ def test_push_with_single_matching_branch_regex
+ svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*'}, payload)
+
+ svc.receive_push
+ msgs = svc.writable_io.string.split("\n")
+ assert_equal "NICK n", msgs.shift
+ assert_match "USER n", msgs.shift
+ assert_equal "JOIN #r", msgs.shift.strip
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_equal "PART #r", msgs.shift.strip
+ assert_equal "QUIT", msgs.shift.strip
+ assert_nil msgs.shift
+ end
+
+ def test_push_with_single_mismatching_branch_regex
+ svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => '^ticket*'}, payload)
+
+ svc.receive_push
+ msgs = svc.writable_io.string.split("\n")
+ assert_nil msgs.shift
+ end
+
+ def test_push_with_multiple_branch_regexes_where_all_match
+ svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*,^ticket*'}, payload)
+
+ svc.receive_push
+ msgs = svc.writable_io.string.split("\n")
+ assert_equal "NICK n", msgs.shift
+ assert_match "USER n", msgs.shift
+ assert_equal "JOIN #r", msgs.shift.strip
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_equal "PART #r", msgs.shift.strip
+ assert_equal "QUIT", msgs.shift.strip
+ assert_nil msgs.shift
+ end
+
+ def test_push_with_multiple_branch_regexes_where_one_matches
+ svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => 'mast*,^ticket*'}, payload)
+
+ svc.receive_push
+ msgs = svc.writable_io.string.split("\n")
+ assert_equal "NICK n", msgs.shift
+ assert_match "USER n", msgs.shift
+ assert_equal "JOIN #r", msgs.shift.strip
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_match /PRIVMSG #r.*grit/, msgs.shift
+ assert_equal "PART #r", msgs.shift.strip
+ assert_equal "QUIT", msgs.shift.strip
+ assert_nil msgs.shift
+ end
+
+ def test_push_with_multiple_branch_regexes_where_none_match
+ svc = service({'room' => 'r', 'nick' => 'n', 'branch_regexes' => '^feature*,^ticket*'}, payload)
+
+ svc.receive_push
+ msgs = svc.writable_io.string.split("\n")
+ assert_nil msgs.shift
+ end
def test_push_with_nickserv
svc = service({'room' => 'r', 'nick' => 'n', 'nickservidentify' => 'booya'},