forked from appelier/bigtuna
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/flamontagne/bigtuna into …
…flamontagne-master
- Loading branch information
Showing
10 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ module BigTuna | |
|
||
HOOKS = [ | ||
Hooks::Mailer, | ||
Hooks::Xmpp | ||
] | ||
|
||
DEFAULT_CONFIG = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#XMPP notifications | ||
#We subclass ActionMailer | ||
module BigTuna | ||
class Hooks::Xmpp | ||
NAME = "xmpp" | ||
|
||
# def self.build_passed(build, config) | ||
# end | ||
|
||
|
||
def self.build_fixed(build, config) | ||
Sender.delay.build_fixed(build,config) unless config["recipients"].split(",").empty? | ||
end | ||
|
||
def self.build_still_fails(build, config) | ||
Sender.delay.build_still_fails(build,config) unless config["recipients"].split(",").empty? | ||
end | ||
|
||
# def self.build_finished(build, config) | ||
# end | ||
|
||
def self.build_failed(build, config) | ||
Sender.delay.build_failed(build,config) unless config["recipients"].split(",").empty? | ||
end | ||
|
||
class Sender < ActionMailer::Base | ||
self.append_view_path("extras/big_tuna/hooks") | ||
|
||
def send_im(config,msg) | ||
recipients = config["recipients"].split(",") | ||
if recipients.size > 0 | ||
im = Jabber::Simple.new(config["sender_full_jid"], config["sender_password"]) | ||
recipients.each {|r| im.deliver(r.strip, msg)} | ||
end | ||
end | ||
|
||
def build_failed(build, config) | ||
@build = build | ||
@project = @build.project | ||
|
||
send_im( | ||
config, | ||
mail.body = render_to_string( | ||
"xmpp/build_failed", | ||
:locals => {:build => @build, :project => @project} | ||
) | ||
) | ||
end | ||
|
||
def build_still_fails(build, config) | ||
@build = build | ||
@project = @build.project | ||
|
||
send_im( | ||
config, | ||
mail.body = render_to_string( | ||
"xmpp/build_still_fails", | ||
:locals => {:build => @build, :project => @project} | ||
) | ||
) | ||
end | ||
|
||
def build_fixed(build, config) | ||
@build = build | ||
@project = @build.project | ||
|
||
send_im( | ||
config, | ||
mail.body = render_to_string( | ||
"xmpp/build_fixed", | ||
:locals => {:build => @build, :project => @project} | ||
) | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
%div | ||
= label_tag("Send with this XMPP/GoogleTalk account") | ||
%br | ||
= text_field_tag("configuration[sender_full_jid]", @hook.configuration["sender_full_jid"]) | ||
|
||
%div | ||
= label_tag("Identified by this password") | ||
%br | ||
= password_field_tag("configuration[sender_password]", @hook.configuration["sender_password"]) | ||
|
||
%div | ||
= label_tag("Send to these recipients (separated by comma)") | ||
%br | ||
= text_area_tag("configuration[recipients]", @hook.configuration["recipients"], :cols => 50) | ||
|
||
%p.hint= "Tip: You can enter your <a href='http://partychapp.appspot.com/' target='_blank'>partychat</a> room there".html_safe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Build '<%=@build.display_name%>' in '<%=@project.name%>' failed (<%=build_url(@build)%>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Build '<%=@build.display_name%>' in '<%=@project.name%>' fixed (<%=build_url(@build)%>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Build '<%=@build.display_name%>' in '<%=@project.name%>' still fails (<%=build_url(@build)%>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
require 'test_helper' | ||
|
||
class XmppHookTest < ActiveSupport::TestCase | ||
def setup | ||
super | ||
`cd test/files; mkdir koss; cd koss; git init; echo "my file" > file; git add file; git commit -m "my file added"` | ||
end | ||
|
||
def teardown | ||
FileUtils.rm_rf("test/files/koss") | ||
FileUtils.rm_rf("builds/koss") | ||
super | ||
end | ||
|
||
test "xmpp message stating that build failed is sent when build failed" do | ||
BigTuna::Hooks::Xmpp::Sender.any_instance.expects(:send_im).at_least_once.returns(true) | ||
|
||
project = xmpp_project_with_steps("ls invalid_file_here") | ||
assert_difference("Delayed::Job.count", +2) do # 1 job + 1 for sending the xmpp message | ||
job = project.build! | ||
job.invoke_job | ||
end | ||
build = project.recent_build | ||
job = Delayed::Job.order("created_at DESC").first | ||
msg = YAML.load(job.handler).perform | ||
assert msg.body.include? "Build '#{build.display_name}' in '#{project.name}' failed" | ||
end | ||
|
||
test "xmpp message stating that build is back to normal is sent when build fixed" do | ||
BigTuna::Hooks::Xmpp::Sender.any_instance.expects(:send_im).at_least_once.returns(true) | ||
|
||
project = xmpp_project_with_steps("ls invalid_file_here") | ||
job = project.build! | ||
job.invoke_job | ||
project.update_attributes!(:steps => "ls .") | ||
assert_difference("Delayed::Job.count", +2) do # 1 job + 1 for sending the xmpp message | ||
job = project.build! | ||
job.invoke_job | ||
end | ||
build = project.recent_build | ||
job = Delayed::Job.order("created_at DESC").first | ||
msg = YAML.load(job.handler).perform | ||
assert msg.body.include? "Build '#{build.display_name}' in '#{project.name}' fixed" | ||
end | ||
|
||
test "xmpp message stating that build is still failing is sent when build still fails" do | ||
BigTuna::Hooks::Xmpp::Sender.any_instance.expects(:send_im).at_least_once.returns(true) | ||
|
||
project = xmpp_project_with_steps("ls invalid_file_here") | ||
job = project.build! | ||
job.invoke_job | ||
assert_difference("Delayed::Job.count", +2) do # 1 job + 1 for sending the xmpp message | ||
job = project.build! | ||
job.invoke_job | ||
end | ||
build = project.recent_build | ||
job = Delayed::Job.order("created_at DESC").first | ||
msg = YAML.load(job.handler).perform | ||
assert msg.body.include? "Build '#{build.display_name}' in '#{project.name}' still fails" | ||
end | ||
|
||
test "no xmpp message sent when build is ok but was ok before" do | ||
project = xmpp_project_with_steps("ls .") | ||
assert_difference("Delayed::Job.count", +2) do # 2 jobs, nothing sent via xmpp | ||
2.times do | ||
job = project.build! | ||
job.invoke_job | ||
end | ||
end | ||
end | ||
|
||
def xmpp_project_with_steps(steps) | ||
project = Project.make(:steps => steps, :name => "Koss", :vcs_source => "test/files/koss", :vcs_type => "git", :max_builds => 2, :hooks => {"xmpp" => "xmpp"}, :hook_update => true) | ||
hook = project.hooks.first | ||
hook.configuration = { | ||
"recipients" => "user1@example.com,user2@example.com,user3@example.com", | ||
"sender_full_jid" => "thesender@example.com", | ||
"sender_password" => "secret" | ||
} | ||
|
||
hook.save! | ||
project | ||
end | ||
end |