Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
Merge pull request #283 from jeffweiss/patch/master/add_branch_regex_…
Browse files Browse the repository at this point in the history
…to_irc_client

Add branch regex to irc client
  • Loading branch information
technoweenie committed Apr 18, 2012
2 parents b781a2f + 59bec11 commit ac98e69
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
13 changes: 12 additions & 1 deletion services/irc.rb
@@ -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)

Expand Down Expand Up @@ -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
84 changes: 84 additions & 0 deletions test/irc_test.rb
Expand Up @@ -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'},
Expand Down

0 comments on commit ac98e69

Please sign in to comment.