require 'evrone/ci/message' require 'evrone/ci/common' module Evrone module CI class Router class Build STARTED = 2 FINISHED = 3 FAILED = 5 include Router::Helper::Logger include Router::Helper::Config attr_reader :message, :output attr_accessor :matrix, :jobs_count, :commit_info def initialize(perform_build_message) @output = '' @message = perform_build_message end def to_perform_job_message(travis, job_id) script_builder = travis.to_script_builder job_message = Message::PerformJob.new( id: message.id, name: message.name, src: message.src, sha: message.sha, pull_request_id: message.pull_request_id, deploy_key: message.deploy_key, job_id: job_id, before_script: script_builder.to_before_script, script: script_builder.to_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, tm_usec: tm.usec, matrix: matrix || [], jobs_count: jobs_count || 0, } if commit_info attributes.merge!( commit_author: commit_info.author, commit_author_email: commit_info.email, commit_sha: commit_info.sha, commit_message: commit_info.message ) end Message::BuildStatus.new attributes end def add_to_output(str) output << str logger.debug str.strip if logger.level == 0 BuildLogsConsumer.publish create_build_log_message(str) end def add_command_to_output(cmd) add_to_output "$ #{cmd}\n" end def create_build_log_message(data) tm = Time.now Message::BuildLog.new( build_id: message.id, tm: tm.to_i, tm_usec: tm.usec, log: data ) end end end end end