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

Adds Flowdock notification support #232

Merged
merged 1 commit into from Apr 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/integrity.txt
Expand Up @@ -206,6 +206,7 @@ Integrity supports a number of notification mechanisms:

* AMQP
* http://campfirenow.com[Campfire]
* https://www.flowdock.com[Flowdock]
* Co-op
* Email
* HTTP
Expand Down
2 changes: 2 additions & 0 deletions init.rb
Expand Up @@ -15,6 +15,8 @@
# require "integrity/notifier/ses"
# = Campfire
# require "integrity/notifier/campfire"
# = Flowdock
# require "integrity/notifier/flowdock"
# = TCP
# require "integrity/notifier/tcp"
# = HTTP
Expand Down
11 changes: 11 additions & 0 deletions lib/integrity/notifier/flowdock.haml
@@ -0,0 +1,11 @@
%p.normal
%label{ :for => "flowdock_notifier_token" } API Token
%input.text#flowdock_notifier_token{ :name => "notifiers[Flowdock][token]", :value => config["token"], :type => "text" }

%p.normal
%label{ :for => "flowdock_notifier_from_address" } From address (used for Gravatar)
%input.text#flowdock_from_address{ :name => "notifiers[Flowdock][from_address]", :value => config["from_address"], :type => "email", :placeholder => 'integrity@yourdomain.com' }

%p.normal
%label{ :for => "flowdock_notifier_announce_success" } Notify on success?
%input#flowdock_notifier_announce_success{ :name => "notifiers[Flowdock][announce_success]", :type => "checkbox", :checked => config['announce_success'], :value => "1" }
49 changes: 49 additions & 0 deletions lib/integrity/notifier/flowdock.rb
@@ -0,0 +1,49 @@
require 'uri'
require 'net/http'
require 'net/https'

module Integrity
class Notifier
class Flowdock < Notifier::Base
attr_reader :config

def self.to_haml
@haml ||= File.read(File.dirname(__FILE__) + "/flowdock.haml")
end

def deliver!
token = config["token"]

headers = {
"Accept" => "application/json",
"Content-Type" => "application/json; charset=utf-8",
"User-Agent" => "Integrity Flowdock Notifier",
}

uri = URI.parse("https://api.flowdock.com/v1/messages/team_inbox/#{token}")

https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE

post = Net::HTTP::Post.new(uri.path, headers)
post.body = {
"source" => "Integrity",
"subject" => short_message,
"content" => "<pre>#{full_message}</pre>",
"from_address" => config["from_address"],
"link" => build_url,
"tags" => ["integrity", build.failed? ? "failure" : "success"]
}.to_json

response = https.request(post)
end

def announce_build?
build.failed? || config["announce_success"]
end
end

register Flowdock
end
end
64 changes: 64 additions & 0 deletions test/acceptance/flowdock_notification_test.rb
@@ -0,0 +1,64 @@
require "helper/acceptance"

class FlowdockNotificationTest < Test::Unit::AcceptanceTestCase
story <<-EOS
As an administrator,
I want to setup the Flowdock notifiers on my projects
So that I get alerts with every build
EOS

setup do
load "integrity/notifier/flowdock.rb"

@token = "fc7795d580b6adacaa90f1ds24030s14a31a6522sed"
@repo = git_repo(:my_test_project)
Project.gen(:my_test_project, :uri => @repo.uri)

@api_url = "https://api.flowdock.com/v1/messages/team_inbox/#{@token}"
end

teardown do
WebMock.reset!
Notifier.available.replace({})
end

def commit(successful)
successful ? @repo.add_successful_commit : @repo.add_failing_commit
@repo.short_head
end

def build
login_as "admin", "test"
visit "/my-test-project"
click_link "Edit"

check "enabled_notifiers_flowdock"
fill_in "API Token", :with => @token
check "Notify on success?"
click_button "Update"
click_button "Manual Build"
end

scenario "Notifying a successful build" do
head = commit(true)

stub_request(:post, @api_url).to_return(
:status => 200,
:body => {}.to_json)

build

assert_requested :post, @api_url
end

scenario "Notifying a failed build" do
head = commit(false)
stub_request(:post, @api_url).to_return(
:status => 200,
:body => {}.to_json)

build

assert_requested :post, @api_url
end
end