Class: HudsonToPissWhistle
- Inherits:
-
Object
- Object
- HudsonToPissWhistle
- Defined in:
- lib/hudson_to_pisswhistle.rb
Class Method Summary collapse
-
.change_dots_to_hyphens_in_keys(hash_or_array) ⇒ Object
Hudson’s XML keys contain dots, but BSON doesn’t like that.
- .run(net_client = HTTParty) ⇒ Object
Class Method Details
.change_dots_to_hyphens_in_keys(hash_or_array) ⇒ Object
Hudson’s XML keys contain dots, but BSON doesn’t like that.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hudson_to_pisswhistle.rb', line 8 def self.change_dots_to_hyphens_in_keys(hash_or_array) case hash_or_array when Hash hash_or_array.inject({}) do |h, (k,v)| h[k.to_s.gsub(".", "-")] = change_dots_to_hyphens_in_keys(v) h end when Array hash_or_array.map { |value| change_dots_to_hyphens_in_keys(value) } else hash_or_array end end |
.run(net_client = HTTParty) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/hudson_to_pisswhistle.rb', line 22 def self.run(net_client=HTTParty) %w(STREAM OAUTH_TOKEN WORKSPACE BUILD_ID).each do |setting| raise "#{setting} was not set" unless ENV[setting] end project_name = ENV["WORKSPACE"].split("/")[-2] build_directory = File.(File.join(ENV["WORKSPACE"], "..", "builds", ENV["BUILD_ID"])) build_log = File.join(build_directory, "build.xml") # puts "sleeping while i wait for build.xml to appear" x = 0 until File.exists?(build_log) || x > 10 do sleep(1) # puts "chekcing for #{build_log}" x += 1 end # puts "awake again #{x}" data = Crack::XML.parse(File.read(build_log)) data = change_dots_to_hyphens_in_keys(data) data["changelog"] = File.read(File.join(build_directory, "changelog.xml")).strip revision = data["changelog"].split(" ").last data["message"] = if data["build"]["result"] == "SUCCESS" "#{project_name} (#{revision}) built successfully" else "#{project_name} (#{revision}) failed!" end # legacy CI message compatibility data["result"] = data["build"]["result"] stream_url = "http://#{ENV["HOST"] || "localhost"}/#{ENV["STREAM"]}/messages" query = {:type => "hudson", :oauth_token => ENV["OAUTH_TOKEN"], :payload => data.to_json} net_client.post(stream_url, :query => query) end |