BigW Consortium Gitlab

metrics.rb 661 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class Issue::Metrics < ActiveRecord::Base
  belongs_to :issue

  def record!
    if issue.milestone_id.present? && self.first_associated_with_milestone_at.blank?
      self.first_associated_with_milestone_at = Time.now
    end

    if issue_assigned_to_list_label? && self.first_added_to_board_at.blank?
      self.first_added_to_board_at = Time.now
    end

    self.save if self.changed?
  end

16 17 18 19
  def record_commit_mention!(commit_time)
    self.update(first_mentioned_in_commit_at: commit_time) if self.first_mentioned_in_commit_at.blank?
  end

20 21 22 23 24 25
  private

  def issue_assigned_to_list_label?
    issue.labels.any? { |label| label.lists.present? }
  end
end