Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add branch regex to irc client #283

Merged
merged 2 commits into from

2 participants

@jeffweiss

Prior to this commit, the IRC service would dutifully notify you of
every push to every branch. This allows you to limit, via
comma-separated regexes, which branches will notify via IRC.

NOTE: It's possible that a , separated list of regexes could cause
problems if people want to use a , in the regex. If this is an issue,
I'll add a field to specify the delimiter.

jeffweiss added some commits
@jeffweiss jeffweiss Add branch regex filter for IRC client
Prior to this commit, the IRC service would dutifully notify you of
every push to every branch. This allows you to limit, via
comma-separated regexes, which branches will notify via IRC.
5dfdb9d
@jeffweiss jeffweiss Add branch regex filter for IRC client
Add tests for regex filter for IRC client.
Fix edge case of existing, but empty regex filter.
59bec11
@technoweenie technoweenie merged commit ac98e69 into github:master
@technoweenie

You should see the new field available on the form now. Let me know if you have any problems!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 11, 2012
  1. @jeffweiss

    Add branch regex filter for IRC client

    jeffweiss authored
    Prior to this commit, the IRC service would dutifully notify you of
    every push to every branch. This allows you to limit, via
    comma-separated regexes, which branches will notify via IRC.
  2. @jeffweiss

    Add branch regex filter for IRC client

    jeffweiss authored
    Add tests for regex filter for IRC client.
    Fix edge case of existing, but empty regex filter.
This page is out of date. Refresh to see the latest.
Showing with 96 additions and 1 deletion.
  1. +12 −1 services/irc.rb
  2. +84 −0 test/irc_test.rb
View
13 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)
@@ -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
84 test/irc_test.rb
@@ -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'},
Something went wrong with that request. Please try again.