{"action":"created","comment":{"url":"https://api.github.com/repos/tumblr/collins/pulls/comments/22731273","id":22731273,"diff_hunk":"@@ -0,0 +1,84 @@\n+require 'json'\n+\n+module CollinsNotify\n+\n+  # currently this only supports incoming webhooks to pust to slack\n+  # https://tumblr.slack.com/services/new/incoming-webhook\n+\n+  class SlackAdapter < Notifier\n+    register_name :slack\n+    supports_mimetype :text\n+    require_config :webhook_url\n+\n+    def configure!\n+      @webhook_url = config.adapters[:slack][:webhook_url]\n+      logger.info \"Configured Slack adapter\"\n+    end\n+    \n+    # Available in template binding:\n+    # message_obj - Depends on call\n+    # channel - channel sending to\n+    def notify! message_obj = OpenStruct.new, to = nil\n+      slack_hash = Hash.new\n+      channel = get_channel config.adapters[:slack], to\n+      slack_hash['channel'] = channel\n+      optional_parameters = [:username, :icon_url, :icon_emoji]\n+      optional_parameters.each do |op|\n+        if config.adapters[:slack][op]\n+          slack_hash[op] = config.adapters[:slack][op]\n+        end\n+      end\n+\n+      slack_hash['text'] = get_message_body(binding)\n+\n+      @logger.debug \"slack parameters: #{slack_hash.inspect}\"\n+        \n+      if config.test? then\n+        @logger.info \"Not sending message in test mode\"\n+        return true\n+      end\n+\n+      begin\n+        @logger.debug \"Posting to slack webhook: #{@webhook_url}\"\n+        reply = HTTParty.post(@webhook_url, :body => JSON.dump(slack_hash))\n+        reply.response.value # this raises an error if the response said it was unsuccessful\n+        true\n+      rescue CollinsNotify::CollinsNotifyException => e\n+        @logger.error \"error sending slack notification - #{e}\"\n+        raise e\n+      rescue Exception => e\n+        @logger.error \"#{e.class.to_s} - error sending slack notification - #{e}\"\n+        raise CollinsNotify::CollinsNotifyException.new e\n+      end\n+    end\n+\n+    protected\n+\n+    # get the channel from one of many sources\n+    # slack does not require a channel for a web hook (you can set a default through the webhook settings)\n+    # but we're going to require that a channel is specified for the purposes of this gem\n+    def get_channel hash, to\n+      if config.recipient then\n+        make_channel config.recipient\n+      elsif to then\n+        make_channel to\n+      elsif hash[:channel]\n+        make_channel hash[:channel]\n+      else\n+        raise CollinsNotify::ConfigurationError.new \"No slack.channel or config.recipient specified\"\n+      end\n+    end\n+\n+    # slack can both DM users and post to channels\n+    # If the recipient isn't explicitly a user (@username) then we'll assume the string is a channel\n+    def make_channel chan\n+      @logger.debug \"In make_channel, got #{chan}\"\n+      # If we are DMing a user (chan looks like @username), do nothing\n+      # otherwise, make sure chan starts with a '#', if it doesn't already\n+      chan = chan.sub(/^(?!#|@)/,'#')","path":"support/ruby/collins-notify/lib/collins_notify/adapter/slack.rb","position":78,"original_position":78,"commit_id":"304b141eb5bf88e2f396fb9b9e2dc9ae7dc67db9","original_commit_id":"304b141eb5bf88e2f396fb9b9e2dc9ae7dc67db9","user":{"login":"Primer42","id":555841,"avatar_url":"https://avatars.githubusercontent.com/u/555841?v=3","gravatar_id":"","url":"https://api.github.com/users/Primer42","html_url":"https://github.com/Primer42","followers_url":"https://api.github.com/users/Primer42/followers","following_url":"https://api.github.com/users/Primer42/following{/other_user}","gists_url":"https://api.github.com/users/Primer42/gists{/gist_id}","starred_url":"https://api.github.com/users/Primer42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Primer42/subscriptions","organizations_url":"https://api.github.com/users/Primer42/orgs","repos_url":"https://api.github.com/users/Primer42/repos","events_url":"https://api.github.com/users/Primer42/events{/privacy}","received_events_url":"https://api.github.com/users/Primer42/received_events","type":"User","site_admin":false},"body":"I just found specs for valid characters in channel names - I'm adding a commit no enforce those now","created_at":"2015-01-09T17:59:11Z","updated_at":"2015-01-09T17:59:11Z","html_url":"https://github.com/tumblr/collins/pull/247#discussion_r22731273","pull_request_url":"https://api.github.com/repos/tumblr/collins/pulls/247","_links":{"self":{"href":"https://api.github.com/repos/tumblr/collins/pulls/comments/22731273"},"html":{"href":"https://github.com/tumblr/collins/pull/247#discussion_r22731273"},"pull_request":{"href":"https://api.github.com/repos/tumblr/collins/pulls/247"}}},"pull_request":{"url":"https://api.github.com/repos/tumblr/collins/pulls/247","id":26988596,"html_url":"https://github.com/tumblr/collins/pull/247","diff_url":"https://github.com/tumblr/collins/pull/247.diff","patch_url":"https://github.com/tumblr/collins/pull/247.patch","issue_url":"https://api.github.com/repos/tumblr/collins/issues/247","number":247,"state":"open","locked":false,"title":"Will collins notify slack","user":{"login":"Primer42","id":555841,"avatar_url":"https://avatars.githubusercontent.com/u/555841?v=3","gravatar_id":"","url":"https://api.github.com/users/Primer42","html_url":"https://github.com/Primer42","followers_url":"https://api.github.com/users/Primer42/followers","following_url":"https://api.github.com/users/Primer42/following{/other_user}","gists_url":"https://api.github.com/users/Primer42/gists{/gist_id}","starred_url":"https://api.github.com/users/Primer42/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Primer42/subscriptions","organizations_url":"https://api.github.com/users/Primer42/orgs","repos_url":"https://api.github.com/users/Primer42/repos","events_url":"https://api.github.com/users/Primer42/events{/privacy}","received_events_url":"https://api.github.com/users/Primer42/received_events","type":"User","site_admin":false},"body":"Squashed version of #246 \r\nAdding slack support to `collins-notify`\r\n@byxorna @maddalab @CaptPhunkosis ","created_at":"2015-01-07T21:20:26Z","updated_at":"2015-01-09T17:59:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a1aa73136800dc1674be74aafa124a872d18e21d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/tumblr/collins/pulls/247/commits","review_comments_url":"https://api.github.com/repos/tumblr/collins/pulls/247/comments","review_comment_url":"https://api.github.com/repos/tumblr/collins/pulls/comments/{number}","comments_url":"https://api.github.com/repos/tumblr/collins/issues/247/comments","statuses_url":"https://api.github.com/repos/tumblr/collins/statuses/304b141eb5bf88e2f396fb9b9e2dc9ae7dc67db9","head":{"label":"tumblr:will-collins-notify-slack","ref":"will-collins-notify-slack","sha":"304b141eb5bf88e2f396fb9b9e2dc9ae7dc67db9","user":{"login":"tumblr","id":366151,"avatar_url":"https://avatars.githubusercontent.com/u/366151?v=3","gravatar_id":"","url":"https://api.github.com/users/tumblr","html_url":"https://github.com/tumblr","followers_url":"https://api.github.com/users/tumblr/followers","following_url":"https://api.github.com/users/tumblr/following{/other_user}","gists_url":"https://api.github.com/users/tumblr/gists{/gist_id}","starred_url":"https://api.github.com/users/tumblr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tumblr/subscriptions","organizations_url":"https://api.github.com/users/tumblr/orgs","repos_url":"https://api.github.com/users/tumblr/repos","events_url":"https://api.github.com/users/tumblr/events{/privacy}","received_events_url":"https://api.github.com/users/tumblr/received_events","type":"Organization","site_admin":false},"repo":{"id":5252760,"name":"collins","full_name":"tumblr/collins","owner":{"login":"tumblr","id":366151,"avatar_url":"https://avatars.githubusercontent.com/u/366151?v=3","gravatar_id":"","url":"https://api.github.com/users/tumblr","html_url":"https://github.com/tumblr","followers_url":"https://api.github.com/users/tumblr/followers","following_url":"https://api.github.com/users/tumblr/following{/other_user}","gists_url":"https://api.github.com/users/tumblr/gists{/gist_id}","starred_url":"https://api.github.com/users/tumblr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tumblr/subscriptions","organizations_url":"https://api.github.com/users/tumblr/orgs","repos_url":"https://api.github.com/users/tumblr/repos","events_url":"https://api.github.com/users/tumblr/events{/privacy}","received_events_url":"https://api.github.com/users/tumblr/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tumblr/collins","description":"groovy kind of love","fork":false,"url":"https://api.github.com/repos/tumblr/collins","forks_url":"https://api.github.com/repos/tumblr/collins/forks","keys_url":"https://api.github.com/repos/tumblr/collins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tumblr/collins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tumblr/collins/teams","hooks_url":"https://api.github.com/repos/tumblr/collins/hooks","issue_events_url":"https://api.github.com/repos/tumblr/collins/issues/events{/number}","events_url":"https://api.github.com/repos/tumblr/collins/events","assignees_url":"https://api.github.com/repos/tumblr/collins/assignees{/user}","branches_url":"https://api.github.com/repos/tumblr/collins/branches{/branch}","tags_url":"https://api.github.com/repos/tumblr/collins/tags","blobs_url":"https://api.github.com/repos/tumblr/collins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tumblr/collins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tumblr/collins/git/refs{/sha}","trees_url":"https://api.github.com/repos/tumblr/collins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tumblr/collins/statuses/{sha}","languages_url":"https://api.github.com/repos/tumblr/collins/languages","stargazers_url":"https://api.github.com/repos/tumblr/collins/stargazers","contributors_url":"https://api.github.com/repos/tumblr/collins/contributors","subscribers_url":"https://api.github.com/repos/tumblr/collins/subscribers","subscription_url":"https://api.github.com/repos/tumblr/collins/subscription","commits_url":"https://api.github.com/repos/tumblr/collins/commits{/sha}","git_commits_url":"https://api.github.com/repos/tumblr/collins/git/commits{/sha}","comments_url":"https://api.github.com/repos/tumblr/collins/comments{/number}","issue_comment_url":"https://api.github.com/repos/tumblr/collins/issues/comments/{number}","contents_url":"https://api.github.com/repos/tumblr/collins/contents/{+path}","compare_url":"https://api.github.com/repos/tumblr/collins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tumblr/collins/merges","archive_url":"https://api.github.com/repos/tumblr/collins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tumblr/collins/downloads","issues_url":"https://api.github.com/repos/tumblr/collins/issues{/number}","pulls_url":"https://api.github.com/repos/tumblr/collins/pulls{/number}","milestones_url":"https://api.github.com/repos/tumblr/collins/milestones{/number}","notifications_url":"https://api.github.com/repos/tumblr/collins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tumblr/collins/labels{/name}","releases_url":"https://api.github.com/repos/tumblr/collins/releases{/id}","created_at":"2012-07-31T23:18:59Z","updated_at":"2015-01-09T13:58:55Z","pushed_at":"2015-01-08T16:20:38Z","git_url":"git://github.com/tumblr/collins.git","ssh_url":"git@github.com:tumblr/collins.git","clone_url":"https://github.com/tumblr/collins.git","svn_url":"https://github.com/tumblr/collins","homepage":"tumblr.github.com/collins","size":224045,"stargazers_count":242,"watchers_count":242,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":46,"mirror_url":null,"open_issues_count":39,"forks":46,"open_issues":39,"watchers":242,"default_branch":"master"}},"base":{"label":"tumblr:master","ref":"master","sha":"0b38d37d5cf7db8889edbbf35752f71f6ad24e16","user":{"login":"tumblr","id":366151,"avatar_url":"https://avatars.githubusercontent.com/u/366151?v=3","gravatar_id":"","url":"https://api.github.com/users/tumblr","html_url":"https://github.com/tumblr","followers_url":"https://api.github.com/users/tumblr/followers","following_url":"https://api.github.com/users/tumblr/following{/other_user}","gists_url":"https://api.github.com/users/tumblr/gists{/gist_id}","starred_url":"https://api.github.com/users/tumblr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tumblr/subscriptions","organizations_url":"https://api.github.com/users/tumblr/orgs","repos_url":"https://api.github.com/users/tumblr/repos","events_url":"https://api.github.com/users/tumblr/events{/privacy}","received_events_url":"https://api.github.com/users/tumblr/received_events","type":"Organization","site_admin":false},"repo":{"id":5252760,"name":"collins","full_name":"tumblr/collins","owner":{"login":"tumblr","id":366151,"avatar_url":"https://avatars.githubusercontent.com/u/366151?v=3","gravatar_id":"","url":"https://api.github.com/users/tumblr","html_url":"https://github.com/tumblr","followers_url":"https://api.github.com/users/tumblr/followers","following_url":"https://api.github.com/users/tumblr/following{/other_user}","gists_url":"https://api.github.com/users/tumblr/gists{/gist_id}","starred_url":"https://api.github.com/users/tumblr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tumblr/subscriptions","organizations_url":"https://api.github.com/users/tumblr/orgs","repos_url":"https://api.github.com/users/tumblr/repos","events_url":"https://api.github.com/users/tumblr/events{/privacy}","received_events_url":"https://api.github.com/users/tumblr/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tumblr/collins","description":"groovy kind of love","fork":false,"url":"https://api.github.com/repos/tumblr/collins","forks_url":"https://api.github.com/repos/tumblr/collins/forks","keys_url":"https://api.github.com/repos/tumblr/collins/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tumblr/collins/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tumblr/collins/teams","hooks_url":"https://api.github.com/repos/tumblr/collins/hooks","issue_events_url":"https://api.github.com/repos/tumblr/collins/issues/events{/number}","events_url":"https://api.github.com/repos/tumblr/collins/events","assignees_url":"https://api.github.com/repos/tumblr/collins/assignees{/user}","branches_url":"https://api.github.com/repos/tumblr/collins/branches{/branch}","tags_url":"https://api.github.com/repos/tumblr/collins/tags","blobs_url":"https://api.github.com/repos/tumblr/collins/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tumblr/collins/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tumblr/collins/git/refs{/sha}","trees_url":"https://api.github.com/repos/tumblr/collins/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tumblr/collins/statuses/{sha}","languages_url":"https://api.github.com/repos/tumblr/collins/languages","stargazers_url":"https://api.github.com/repos/tumblr/collins/stargazers","contributors_url":"https://api.github.com/repos/tumblr/collins/contributors","subscribers_url":"https://api.github.com/repos/tumblr/collins/subscribers","subscription_url":"https://api.github.com/repos/tumblr/collins/subscription","commits_url":"https://api.github.com/repos/tumblr/collins/commits{/sha}","git_commits_url":"https://api.github.com/repos/tumblr/collins/git/commits{/sha}","comments_url":"https://api.github.com/repos/tumblr/collins/comments{/number}","issue_comment_url":"https://api.github.com/repos/tumblr/collins/issues/comments/{number}","contents_url":"https://api.github.com/repos/tumblr/collins/contents/{+path}","compare_url":"https://api.github.com/repos/tumblr/collins/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tumblr/collins/merges","archive_url":"https://api.github.com/repos/tumblr/collins/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tumblr/collins/downloads","issues_url":"https://api.github.com/repos/tumblr/collins/issues{/number}","pulls_url":"https://api.github.com/repos/tumblr/collins/pulls{/number}","milestones_url":"https://api.github.com/repos/tumblr/collins/milestones{/number}","notifications_url":"https://api.github.com/repos/tumblr/collins/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tumblr/collins/labels{/name}","releases_url":"https://api.github.com/repos/tumblr/collins/releases{/id}","created_at":"2012-07-31T23:18:59Z","updated_at":"2015-01-09T13:58:55Z","pushed_at":"2015-01-08T16:20:38Z","git_url":"git://github.com/tumblr/collins.git","ssh_url":"git@github.com:tumblr/collins.git","clone_url":"https://github.com/tumblr/collins.git","svn_url":"https://github.com/tumblr/collins","homepage":"tumblr.github.com/collins","size":224045,"stargazers_count":242,"watchers_count":242,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":46,"mirror_url":null,"open_issues_count":39,"forks":46,"open_issues":39,"watchers":242,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tumblr/collins/pulls/247"},"html":{"href":"https://github.com/tumblr/collins/pull/247"},"issue":{"href":"https://api.github.com/repos/tumblr/collins/issues/247"},"comments":{"href":"https://api.github.com/repos/tumblr/collins/issues/247/comments"},"review_comments":{"href":"https://api.github.com/repos/tumblr/collins/pulls/247/comments"},"review_comment":{"href":"https://api.github.com/repos/tumblr/collins/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/tumblr/collins/pulls/247/commits"},"statuses":{"href":"https://api.github.com/repos/tumblr/collins/statuses/304b141eb5bf88e2f396fb9b9e2dc9ae7dc67db9"}}}}