2018-08-03 13:22:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class Issue::Metrics < ApplicationRecord
|
2016-08-24 10:47:48 -04:00
|
|
|
belongs_to :issue
|
|
|
|
|
2019-12-04 13:08:46 -05:00
|
|
|
scope :for_issues, ->(issues) { where(issue: issues) }
|
|
|
|
scope :with_first_mention_not_earlier_than, -> (timestamp) {
|
|
|
|
where(first_mentioned_in_commit_at: nil)
|
|
|
|
.or(where(arel_table['first_mentioned_in_commit_at'].gteq(timestamp)))
|
|
|
|
}
|
|
|
|
|
2016-08-24 10:47:48 -04:00
|
|
|
def record!
|
|
|
|
if issue.milestone_id.present? && self.first_associated_with_milestone_at.blank?
|
2020-05-22 05:08:09 -04:00
|
|
|
self.first_associated_with_milestone_at = Time.current
|
2016-08-24 10:47:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if issue_assigned_to_list_label? && self.first_added_to_board_at.blank?
|
2020-05-22 05:08:09 -04:00
|
|
|
self.first_added_to_board_at = Time.current
|
2016-08-24 10:47:48 -04:00
|
|
|
end
|
|
|
|
|
2016-09-20 08:43:11 -04:00
|
|
|
self.save
|
2016-08-24 10:47:48 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def issue_assigned_to_list_label?
|
|
|
|
issue.labels.any? { |label| label.lists.present? }
|
|
|
|
end
|
|
|
|
end
|