Sha256: 5f5916b646ac55157916f7ba035747f7c58c625f0232e32ea789f8d12413e50f

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

require "forwardable"

module Integrity
  class ProjectBuilder
    extend Forwardable

    attr_accessor  :project, :scm
    def_delegators :project, :name, :uri, :command, :branch

    def self.build(commit)
      new(commit.project).build(commit)
    end

    def self.delete_working_directory(project)
      new(project).delete_code
    end

    def initialize(project)
      @project = project
      @scm     = SCM.new(uri, branch, export_directory)
    end

    def build(commit)
      build = commit.build
      build.start!

      Integrity.log "Building #{commit.identifier} (#{branch}) of #{name} in" +
        "#{export_directory} using #{scm.name}"

      scm.with_revision(commit.identifier) do
        Integrity.log "Running `#{command}` in #{scm.working_directory}"

        IO.popen("(cd #{scm.working_directory} && #{command}) 2>&1", "r") {
          |output| build.output = output.read }
        build.successful = $?.success?
      end

      build
    ensure
      build.complete!
      commit.update_attributes(scm.info(commit.identifier) || {})
      project.enabled_notifiers.each { |notifier| notifier.notify_of_build(build) }
    end

    def delete_code
      FileUtils.rm_r export_directory
    rescue Errno::ENOENT
      nil
    end

    private
      def export_directory
        Integrity.config[:export_directory] / "#{SCM.working_tree_path(uri)}-#{branch}"
      end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
alphasights-integrity-0.1.9.3 lib/integrity/project_builder.rb
alphasights-integrity-0.1.9.4 lib/integrity/project_builder.rb
alphasights-integrity-0.1.9.5 lib/integrity/project_builder.rb
alphasights-integrity-0.1.9.6 lib/integrity/project_builder.rb
alphasights-integrity-0.1.9.7 lib/integrity/project_builder.rb
alphasights-integrity-0.1.9.8 lib/integrity/project_builder.rb
integrity-integrity-0.1.10 lib/integrity/project_builder.rb
integrity-integrity-0.1.9.3 lib/integrity/project_builder.rb
integrity-0.1.11 lib/integrity/project_builder.rb
integrity-0.1.10 lib/integrity/project_builder.rb