gitlab-org--gitlab-foss/app/models/ci/trigger.rb

32 lines
601 B
Ruby
Raw Normal View History

2015-08-25 21:42:46 -04:00
module Ci
class Trigger < ActiveRecord::Base
extend Ci::Model
2015-09-10 09:52:52 -04:00
2015-08-25 21:42:46 -04:00
acts_as_paranoid
belongs_to :project, foreign_key: :gl_project_id
has_many :trigger_requests, dependent: :destroy
2015-08-25 21:42:46 -04:00
validates_presence_of :token
validates_uniqueness_of :token
before_validation :set_default_values
def set_default_values
self.token = SecureRandom.hex(15) if self.token.blank?
end
def last_trigger_request
trigger_requests.last
end
2016-01-13 06:16:27 -05:00
def last_used
last_trigger_request.try(:created_at)
end
2015-08-25 21:42:46 -04:00
def short_token
token[0...10]
end
end
end