Sha256: 07b7bc52e3aff775773459372132fbe871a221d5db5d89f9618e003b9459083e

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

module Evrone
  module CI
    class Router
      module Middleware

        CreateBuildMatrix = Struct.new(:app) do

          include Helper::Logger

          def call(env)
            if create_build_matrix_and_delivery(env)
              app.call env
            else
              -1
            end
          end

          private

            def create_build_matrix_and_delivery(env)
              source_travis = load_travis(env.repo_dir)
              if source_travis
                matrix = Router::BuildMatrix.new source_travis
                update_build env.build, matrix

                matrix.travises.each_with_index do |travis, idx|
                  delivery_job env.build, travis, idx+1
                end
                true
              else
                false
              end
            end

            def delivery_job(build, travis, number)
              message = build.to_perform_job_message travis, number
              logger.info "delivery job #{message.id}.#{number} #{travis.to_matrix_s}"
              Router::JobsConsumer.publish message
            end

            def update_build(build, matrix)
              build.matrix     = matrix.keys
              build.jobs_count = matrix.travises.size
            end

            def load_travis(repo_dir)
              Router::Travis.from_file repo_dir.join(".travis.yml")
            end

        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evrone-ci-router-0.2.0.pre0 lib/evrone/ci/router/middleware/create_build_matrix.rb