require 'evrone/ci/message' require 'evrone/ci/common' module Evrone module CI class Router class Build INITIALIED = 0 STARTED = 2 FINISHED = 3 FAILED = 5 include Router::Helper::Logger include Router::Helper::Config attr_reader :message, :output, :output_counter attr_accessor :jobs_count def initialize(perform_build_message) @output_counter = 0 @output = Common::OutputBuffer.new(&method(:publish_build_log_message)) @message = perform_build_message end def release output.close end def to_perform_job_message(travis, job_id) script_builder = travis.to_script_builder(self) job_message = Message::PerformJob.new( id: message.id, name: message.name, job_id: job_id, before_script: script_builder.to_before_script, script: script_builder.to_script, after_script: script_builder.to_after_script, matrix_keys: travis.matrix_keys, ) job_message end def to_build_status_message(status) tm = Time.now attributes = { build_id: message.id, status: status, tm: tm.to_i, jobs_count: jobs_count || 0, } Message::BuildStatus.new attributes end def add_to_output(str) output << str logger.debug str.strip if logger.level == 0 end def add_command_to_output(cmd) add_to_output "$ #{cmd}\n" end def publish_build_log_message(str) @output_counter += 1 log = Message::BuildLog.new( build_id: message.id, tm: output_counter, log: str ) BuildLogsConsumer.publish log log end def scm_class Evrone::CI::SCM::Git end end end end end