Permalink
Browse files

Add SES Email Notifier.

  • Loading branch information...
1 parent 0ca4793 commit 1d9633293e7d715c07630cb0a0ebd440cae3d148 @JDutil JDutil committed with richmeyers Feb 28, 2012
Showing with 111 additions and 0 deletions.
  1. +4 −0 Gemfile
  2. +2 −0 init.rb
  3. +17 −0 lib/integrity/notifier/ses.haml
  4. +46 −0 lib/integrity/notifier/ses.rb
  5. +42 −0 test/acceptance/ses_notification_test.rb
View
@@ -36,6 +36,9 @@ gem "rack", "1.1.0"
# = Email
# gem "pony", "1.1"
+# = SES Email
+# gem 'aws-ses', '0.4.3', :require => 'aws/ses'
+
# = Campfire
# gem "broach", "0.2.1"
# gem "nap", "0.4"
@@ -69,6 +72,7 @@ gem "rack", "1.1.0"
# = Development dependencies.
group :test do
+ gem 'aws-ses', '0.4.3', :require => 'aws/ses'
gem "ruby-debug", "0.10.4" if RUBY_VERSION < '1.9'
gem "extlib", "0.9.15"
gem "sqlite3-ruby", "~> 1.3.2"
View
@@ -11,6 +11,8 @@
# Uncomment as appropriate for the notifier you want to use
# = Email
# require "integrity/notifier/email"
+# = SES Email
+# require "integrity/notifier/ses"
# = Campfire
# require "integrity/notifier/campfire"
# = TCP
@@ -0,0 +1,17 @@
+%p.normal
+ %label{ :for => "ses_notifier_to" } Send to
+ %input.text#ses_notifier_to{ :name => "notifiers[SES][to]", :type => "text", :value => config["to"] }
+
+%p.normal
+ %label{ :for => "ses_notifier_from" } Send from
+ %input.text#ses_notifier_from{ :name => "notifiers[SES][from]", :type => "text", :value => config["from"] }
+
+%h3 SES Configuration
+
+%p.normal
+ %label{ :for => "ses_notifier_access_key_id" } Access Key ID
+ %input.text#ses_notifier_access_key_id{ :name => "notifiers[SES][access_key_id]", :value => config["access_key_id"], :type => "text" }
+
+%p.normal
+ %label{ :for => "ses_notifier_secret_access_key" } Secret Access Key
+ %input.text#ses_notifier_secret_access_key{ :name => "notifiers[SES][secret_access_key]", :value => config["secret_access_key"], :type => "text" }
@@ -0,0 +1,46 @@
+begin
+ require 'aws/ses'
+rescue LoadError => e
+ warn "Install aws-ses to use the SES Email notifier: #{e.class}: #{e.message}"
+ raise
+end
+
+module Integrity
+ class Notifier
+ class SES < Notifier::Base
+ attr_reader :from, :ses, :to
+
+ def self.to_haml
+ @haml ||= File.read(File.dirname(__FILE__) + "/ses.haml")
+ end
+
+ def initialize(build, config={})
+ @from = config["from"]
+ @ses = AWS::SES::Base.new(
+ :access_key_id => config['access_key_id'],
+ :secret_access_key => config['secret_access_key']
+ )
+ @to = config["to"]
+ super(build, config)
+ end
+
+ def deliver!
+ ses.send_email(
+ :to => to,
+ :from => from,
+ :subject => subject,
+ :body => body
+ )
+ end
+
+ def subject
+ "[Integrity] #{build.project.name}: #{short_message}"
+ end
+
+ alias_method :body, :full_message
+
+ end
+
+ register SES
+ end
+end
@@ -0,0 +1,42 @@
+require "helper/acceptance"
+
+class SESNotificationTest < Test::Unit::AcceptanceTestCase
+ story <<-EOS
+ As an administrator,
+ I want to setup the SES email notifiers on my projects
+ So that I get alerts with every build
+ EOS
+
+ setup do
+ load "integrity/notifier/ses.rb"
+ end
+
+ teardown do
+ Notifier.available.replace({})
+ end
+
+ scenario "Setting SES configuration" do
+ stub.instance_of(Integrity::Notifier::SES).deliver! { nil }
+ repo = git_repo(:my_test_project)
+ project = Project.gen(:my_test_project, :uri => repo.uri)
+ repo.add_successful_commit
+
+ login_as "admin", "test"
+ visit "/my-test-project"
+ click_link "Edit"
+
+ check "enabled_notifiers_ses"
+ fill_in "ses_notifier_to", :with => "hacker@example.org"
+ fill_in "ses_notifier_from", :with => "ci@example.org"
+ fill_in "ses_notifier_access_key_id", :with => "id"
+ fill_in "ses_notifier_secret_access_key", :with => "key"
+ click_button "Update"
+ click_button "Manual Build"
+
+ # TODO: Need the initialized notifier. Not sure how to properly assert notifier values are set correctly here, but testing manually it works.
+ # assert_equal "hacker@example.org", Integrity::Notifier::SES.to
+ # assert_equal "ci@example.org", Integrity::Notifier::SES.from
+ # assert_equal "id", Integrity::Notifier::SES.ses.access_key_id
+ # assert_equal "key", Integrity::Notifier::SES.ses.secret_access_key
+ end
+end

0 comments on commit 1d96332

Please sign in to comment.