gitlab-org--gitlab-foss/app/models/ci/trigger.rb
Tomasz Maczukin 57a67c4fdb Merge branch '8-4-stable' into ci/api-triggers
* 8-4-stable: (280 commits)
  Add Changelog entry for build traces data integrity fix
  Update doc_styleguide.md [ci skip]
  Added hint that you can search users by name, username, or email.
  Add changelog
  Version 8.4.0.rc1
  Randomize metrics sample intervals
  Make the metrics sampler interval configurable
  Don't automatically require awesome_print
  Disable colorization if STDOUT is not a tty
  Block the reported user before destroying the record
  changes `$quote-gray` to `$secondary-text`
  makes message plural for multiple MRs and removes from loop. Duh.
  Prepare Installation and Update docs for 8.4 RC1
  Mention channel/key bug in irkerd docs
  Revert "Remove the `:coffee` and `:coffeescript` Haml filters"
  gets merge request discussion working again
  adds back in discussion.haml.html for issues commenting and closing/reopening properly.
  removing last chunk of MR ajax changes, rest will be in another MR
  reverting more MR ajax files, will appear in different commit
  reverting MR ajax changes, which will be in a different MR
  ...
2016-01-14 10:58:40 +01:00

44 lines
937 B
Ruby

# == Schema Information
#
# Table name: ci_triggers
#
# id :integer not null, primary key
# token :string(255)
# project_id :integer
# deleted_at :datetime
# created_at :datetime
# updated_at :datetime
# gl_project_id :integer
#
module Ci
class Trigger < ActiveRecord::Base
extend Ci::Model
acts_as_paranoid
belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id
has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest'
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
def last_used
last_trigger_request.try(:created_at)
end
def short_token
token[0...10]
end
end
end