Sha256: cf3732877a953d95f195a4fd49c73af87b57fc66c6f4b2b669b7b6f26f2a2931

Contents?: true

Size: 1.11 KB

Versions: 14

Compression:

Stored size: 1.11 KB

Contents

module Shipit
  class Status < ActiveRecord::Base
    include Common
    include DeferredTouch

    STATES = %w(pending success failure error).freeze
    enum state: STATES.zip(STATES).to_h

    belongs_to :stack, required: true
    belongs_to :commit, required: true

    deferred_touch stack: :updated_at, commit: :updated_at

    validates :state, inclusion: {in: STATES, allow_blank: true}, presence: true

    after_create :enable_ci_on_stack
    after_commit :schedule_continuous_delivery, :broadcast_update, on: :create

    delegate :broadcast_update, to: :commit

    class << self
      def replicate_from_github!(stack_id, github_status)
        find_or_create_by!(
          stack_id: stack_id,
          state: github_status.state,
          description: github_status.description,
          target_url: github_status.target_url,
          context: github_status.context,
          created_at: github_status.created_at,
        )
      end
    end

    private

    def enable_ci_on_stack
      commit.stack.enable_ci!
    end

    def schedule_continuous_delivery
      commit.schedule_continuous_delivery
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
shipit-engine-0.25.1 app/models/shipit/status.rb
shipit-engine-0.25.0 app/models/shipit/status.rb
shipit-engine-0.24.0 app/models/shipit/status.rb
shipit-engine-0.23.1 app/models/shipit/status.rb
shipit-engine-0.23.0 app/models/shipit/status.rb
shipit-engine-0.22.0 app/models/shipit/status.rb
shipit-engine-0.21.0 app/models/shipit/status.rb
shipit-engine-0.20.1 app/models/shipit/status.rb
shipit-engine-0.20.0 app/models/shipit/status.rb
shipit-engine-0.19.0 app/models/shipit/status.rb
shipit-engine-0.18.1 app/models/shipit/status.rb
shipit-engine-0.18.0 app/models/shipit/status.rb
shipit-engine-0.17.0 app/models/shipit/status.rb
shipit-engine-0.16.0 app/models/shipit/status.rb