Permalink
Browse files

Add Gitter service

  • Loading branch information...
1 parent e174f55 commit f72fea5732e2080c3d089063f85bae394e0c01a2 @malditogeek malditogeek committed Dec 11, 2013
Showing with 118 additions and 0 deletions.
  1. +26 −0 docs/gitter
  2. +30 −0 lib/services/gitter.rb
  3. +62 −0 test/gitter_test.rb
View
@@ -0,0 +1,26 @@
+Gitter
+======
+
+Chat rooms for your public and private repos with awesome GitHub integration.
+
+https://gitter.im
+
+If you want to see detailed repo activity in your room, follow this steps:
+
+ - Click the **Settings Cog** on the top right
+ - Click on **Integrations**
+ - Select **GitHub**
+ - Click on **configure manually** option
+ - Copy and paste the provided token here
+
+Install Notes
+-------------
+
+1. **Token** - Gitter token for this repo
+
+Options
+
+2. **Mute Fork** - Mute fork notifications.
+3. **Mute Watch** - Mute watch notifications.
+4. **Mute Comments** - Mute issue and pull request comments.
+5. **Mute Wiki** - Mute wiki changes.
View
@@ -0,0 +1,30 @@
+class Service::Gitter < Service::HttpPost
+ string :token
+ boolean :mute_fork, :mute_watch, :mute_comments, :mute_wiki
+
+ default_events ALL_EVENTS
+
+ url 'https://gitter.im'
+ logo_url 'https://gitter.im/_s/1/images/2/gitter/logo-blue-text.png'
+
+ maintained_by github: 'malditogeek',
+ twitter: '@malditogeek'
+
+ supported_by github: 'gitterHQ',
+ twitter: '@gitchat',
+ email: 'support@gitter.im'
+
+ def receive_event
+ token = required_config_value('token')
+ raise_config_error 'Invalid token' unless token.match(/^\w+$/)
+
+ return if data['mute_fork'] && event.to_s =~ /fork/
+ return if data['mute_watch'] && event.to_s =~ /watch/
+ return if data['mute_comments'] && event.to_s =~ /comment/
+ return if data['mute_wiki'] && event.to_s =~ /gollum/
+
+ http.headers['X-GitHub-Event'] = event.to_s
+
+ deliver "https://webhooks.gitter.im/e/#{token}"
+ end
+end
View
@@ -0,0 +1,62 @@
+require File.expand_path('../helper', __FILE__)
+
+class GitterTest < Service::TestCase
+ include Service::HttpTestMethods
+
+ def test_push
+ data = {'token' => "0123456789abcde"}
+
+ svc = service :push, data, push_payload
+
+ @stubs.post "/e/#{data['token']}" do |env|
+ body = JSON.parse(env[:body])
+
+ #assert_equal env[:url].host, "webhooks.gitter.im"
+ assert_equal env[:request_headers]['X-GitHub-Event'], "push"
+ assert_match 'guid-', body['guid']
+ assert_equal data, body['config']
+ assert_equal 'push', body['event']
+ [200, {}, '']
+ end
+
+ svc.receive_event
+ @stubs.verify_stubbed_calls
+ end
+
+ def test_mute_fork
+ data = {'token' => "0123456789abcde", 'mute_fork' => true}
+
+ svc = service :fork, data, basic_payload
+ svc.receive_event
+ assert @stubs.empty?
+ end
+
+ def test_mute_watch
+ data = {'token' => "0123456789abcde", 'mute_watch' => true}
+
+ svc = service :watch, data, basic_payload
+ svc.receive_event
+ assert @stubs.empty?
+ end
+
+ def test_mute_comments
+ data = {'token' => "0123456789abcde", 'mute_comments' => true}
+
+ svc = service :issue_comment, data, issue_comment_payload
+ svc.receive_event
+ assert @stubs.empty?
+ end
+
+ def test_mute_wiki
+ data = {'token' => "0123456789abcde", 'mute_wiki' => true}
+
+ svc = service :gollum, data, gollum_payload
+ svc.receive_event
+ assert @stubs.empty?
+ end
+
+ def service_class
+ Service::Gitter
+ end
+end
+

0 comments on commit f72fea5

Please sign in to comment.