jsmestad-integrity-email 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,52 @@
1
+ Integrity
2
+ =========
3
+
4
+ [Integrity][] is your friendly automated Continuous Integration server.
5
+
6
+ Integrity Email Notifier
7
+ ========================
8
+
9
+ This lets Integrity send emails after each build is made.
10
+
11
+ Setup Instructions
12
+ ==================
13
+
14
+ Just install this gem via `sudo gem install integrity-email` and then in your
15
+ Rackup (ie, `config.ru`) file:
16
+
17
+ require "rubygems"
18
+ require "integrity/notifier/email"
19
+
20
+ And badabing! Now you can set up your projects to send emails after
21
+ each build (just edit the project and the config options should be
22
+ there)
23
+
24
+ License
25
+ =======
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008, 2009 [Nicolás Sanguinetti][foca], [entp][]
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
+
50
+ [Integrity]: http://integrityapp.com
51
+ [foca]: http://nicolassanguinetti.info
52
+ [entp]: http://entp.com
@@ -0,0 +1,11 @@
1
+ task :default => :test
2
+
3
+ task :test do
4
+ ruby "test/integrity_email_test.rb"
5
+ end
6
+
7
+ begin
8
+ require "mg"
9
+ MG.new("integrity-email.gemspec")
10
+ rescue LoadError
11
+ end
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "integrity-email"
3
+ s.version = "1.0.5"
4
+ s.date = "2009-06-01"
5
+ s.summary = "Email notifier for the Integrity continuous integration server"
6
+ s.description = "Easily let Integrity send emails after each build"
7
+ s.homepage = "http://integrityapp.com"
8
+ s.email = "info@integrityapp.com"
9
+ s.authors = ["Nicolás Sanguinetti", "Simon Rozet"]
10
+ s.has_rdoc = false
11
+
12
+ #s.add_dependency "integrity"
13
+ s.add_dependency "sinatra-ditties", [">= 0.0.2"]
14
+
15
+ if s.respond_to?(:add_development_dependency)
16
+ s.add_development_dependency "rumbster"
17
+ end
18
+
19
+ s.rubyforge_project = "integrity"
20
+
21
+ s.files = %w[
22
+ README.markdown
23
+ Rakefile
24
+ integrity-email.gemspec
25
+ lib/integrity/notifier/config.haml
26
+ lib/integrity/notifier/email.rb
27
+ test/integrity_email_test.rb
28
+ ]
29
+ end
@@ -0,0 +1,38 @@
1
+ %p.normal
2
+ %label{ :for => "email_notifier_to" } Send to
3
+ %input.text#email_notifier_to{ :name => "notifiers[Email][to]", :type => "text", :value => config["to"] }
4
+
5
+ %p.normal
6
+ %label{ :for => "email_notifier_from" } Send from
7
+ %input.text#email_notifier_from{ :name => "notifiers[Email][from]", :type => "text", :value => config["from"] }
8
+
9
+ %h3 SMTP Server Configuration
10
+
11
+ %p.normal
12
+ %label{ :for => "email_notifier_host" } Host : Port
13
+ = succeed " : " do
14
+ %input.text#email_notifier_host{ :name => "notifiers[Email][host]", :value => config["host"], :style => "width: 24.5em;", :type => "text" }
15
+ %input.text#email_notifier_port{ :name => "notifiers[Email][port]", :value => config["port"], :style => "width: 3.5em;", :type => "text" }
16
+
17
+ %p.normal
18
+ %label{ :for => "email_notifier_user" } User
19
+ %input.text#email_notifier_user{ :name => "notifiers[Email][user]", :value => config["user"], :type => "text" }
20
+
21
+ %p.normal
22
+ %label{ :for => "email_notifier_pass" } Password
23
+ %input.text#email_notifier_pass{ :name => "notifiers[Email][pass]", :value => config["pass"], :type => "text" }
24
+
25
+ %p.normal
26
+ %label{ :for => "email_notifier_auth" } Auth type
27
+ %input.text#email_notifier_auth{ :name => "notifiers[Email][auth]", :value => (config["auth"] || "plain"), :type => "text" }
28
+
29
+ %p.normal
30
+ %label{ :for => "email_notifier_domain" } Domain
31
+ %input.text#email_notifier_domain{ :name => "notifiers[Email][domain]", :value => config["domain"], :type => "text" }
32
+
33
+
34
+ %h3 Or, enter the path to sendmail:
35
+
36
+ %p.normal
37
+ %label{ :for => "email_notifier_sendmail" } Sendmail path (often /usr/sbin/sendmail)
38
+ %input.text#email_notifier_sendmail{ :name => "notifiers[Email][sendmail]", :value => config["sendmail"], :type => "text" }
@@ -0,0 +1,77 @@
1
+ require "integrity"
2
+ require "sinatra/ditties/mailer"
3
+
4
+ module Integrity
5
+ class Notifier
6
+ class Email < Notifier::Base
7
+ attr_reader :to, :from
8
+
9
+ def self.notify_of_build(build, config)
10
+ # Only send email when build is failed
11
+ last_commit = build.commit.project.commits.first(:order => [:created_at.desc], :id.not => build.commit.id)
12
+ (build.commit.failed? || (last_commit && last_commit.failed?)) ? super : true
13
+ end
14
+
15
+ def self.to_haml
16
+ File.read(File.dirname(__FILE__) + "/config.haml")
17
+ end
18
+
19
+ def initialize(commit, config={})
20
+ @to = config.delete("to")
21
+ @from = config.delete("from")
22
+ super(commit, config)
23
+ configure_mailer
24
+ end
25
+
26
+ def deliver!
27
+ email.deliver!
28
+ end
29
+
30
+ def email
31
+ @email ||= Sinatra::Mailer::Email.new(
32
+ :to => to,
33
+ :from => from,
34
+ :text => body,
35
+ :subject => subject
36
+ )
37
+ end
38
+
39
+ def subject
40
+ "[Integrity] #{commit.project.name}: #{short_message}"
41
+ end
42
+
43
+ alias_method :body, :full_message
44
+
45
+ private
46
+ def configure_mailer
47
+ return configure_sendmail unless @config["sendmail"].blank?
48
+ configure_smtp
49
+ end
50
+
51
+ def configure_smtp
52
+ user = @config["user"] || ""
53
+ pass = @config["pass"] || ""
54
+ user = nil if user.empty?
55
+ pass = nil if pass.empty?
56
+
57
+ Sinatra::Mailer.delivery_method = "net_smtp"
58
+
59
+ Sinatra::Mailer.config = {
60
+ :host => @config["host"],
61
+ :port => @config["port"],
62
+ :user => user,
63
+ :pass => pass,
64
+ :auth => @config["auth"],
65
+ :domain => @config["domain"]
66
+ }
67
+ end
68
+
69
+ def configure_sendmail
70
+ Sinatra::Mailer.delivery_method = :sendmail
71
+ Sinatra::Mailer.config = {:sendmail_path => @config['sendmail']}
72
+ end
73
+ end
74
+
75
+ register Email
76
+ end
77
+ end
@@ -0,0 +1,93 @@
1
+ require "test/unit"
2
+ require "rumbster"
3
+ require "message_observers"
4
+ require "integrity/notifier/test"
5
+
6
+ begin
7
+ require "redgreen"
8
+ rescue LoadError
9
+ end
10
+
11
+ require File.dirname(__FILE__) + "/../lib/integrity/notifier/email"
12
+
13
+ class IntegrityEmailTest < Test::Unit::TestCase
14
+ include Integrity::Notifier::Test
15
+
16
+ MAIL_SERVER_PORT = 10_000
17
+
18
+ def notifier
19
+ "Email"
20
+ end
21
+
22
+ def setup
23
+ Net::SMTP.disable_tls
24
+
25
+ @server = Rumbster.new(MAIL_SERVER_PORT)
26
+ @mail_observer = MailMessageObserver.new
27
+ @server.add_observer(@mail_observer)
28
+
29
+ @server.start
30
+
31
+ setup_database
32
+ end
33
+
34
+ def commit(status=:successful)
35
+ Integrity::Commit.gen(status)
36
+ end
37
+
38
+ def teardown
39
+ @server.stop
40
+ end
41
+
42
+ def test_configuration_form
43
+ assert form_have_tag?("h3", :content => "SMTP Server Configuration")
44
+
45
+ assert provides_option? "to", "foo@example.org"
46
+ assert provides_option? "from", "bar@example.org"
47
+ assert provides_option? "host", "foobarhost.biz"
48
+ assert provides_option? "user", "foobaruser"
49
+ assert provides_option? "pass", "secret"
50
+ assert provides_option? "auth", "plain"
51
+ assert provides_option? "pass", "secret"
52
+ assert provides_option? "domain","localhost"
53
+ assert provides_option? "sendmail","/usr/sbin/sendmail"
54
+ end
55
+
56
+ def test_it_sends_email_notification
57
+ config = { "host" => "127.0.0.1",
58
+ "port" => MAIL_SERVER_PORT,
59
+ "to" => "you@example.org",
60
+ "from" => "me@example.org" }
61
+
62
+ successful = commit(:successful)
63
+ failed = commit(:failed)
64
+
65
+ Integrity::Notifier::Email.new(successful, config.dup).deliver!
66
+ Integrity::Notifier::Email.new(failed, config).deliver!
67
+
68
+ assert_equal "net_smtp", Sinatra::Mailer.delivery_method
69
+
70
+ mail = @mail_observer.messages.first
71
+
72
+ assert_equal ["you@example.org"], mail.destinations
73
+ assert_equal ["me@example.org"], mail.from
74
+ assert mail.subject.include?("successful")
75
+ assert mail.body.include?(successful.committed_at.to_s)
76
+ assert mail.body.include?(successful.author.name)
77
+ assert mail.body.include?(successful.output)
78
+ end
79
+
80
+ def test_it_configures_email_notification_with_sendmail
81
+ sendmail_path = "/usr/sbin/sendmail"
82
+
83
+ config = { "sendmail" => sendmail_path,
84
+ "to" => "sendmail@example.org",
85
+ "from" => "me@example.org" }
86
+ successful = commit(:successful)
87
+
88
+ Integrity::Notifier::Email.new(successful, config)
89
+
90
+ assert_equal :sendmail, Sinatra::Mailer.delivery_method
91
+ assert_equal sendmail_path, Sinatra::Mailer.config[:sendmail_path]
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsmestad-integrity-email
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.5
5
+ platform: ruby
6
+ authors:
7
+ - "Nicol\xC3\xA1s Sanguinetti"
8
+ - Simon Rozet
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-06-01 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: sinatra-ditties
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.2
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: rumbster
28
+ type: :development
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ version:
36
+ description: Easily let Integrity send emails after each build
37
+ email: info@integrityapp.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - README.markdown
46
+ - Rakefile
47
+ - integrity-email.gemspec
48
+ - lib/integrity/notifier/config.haml
49
+ - lib/integrity/notifier/email.rb
50
+ - test/integrity_email_test.rb
51
+ has_rdoc: false
52
+ homepage: http://integrityapp.com
53
+ licenses:
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project: integrity
74
+ rubygems_version: 1.3.5
75
+ signing_key:
76
+ specification_version: 2
77
+ summary: Email notifier for the Integrity continuous integration server
78
+ test_files: []
79
+