summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-08-24 20:17:48 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-08-26 16:27:37 +0530
commit516c838a1846d049814765afa85c28a3c14a5b9f (patch)
treea9228fa421e8b03f7a0e6a7486375baa2d369f4d /app
parent1bf2fe276ff084d3b2e0860710ec115a317dd9fc (diff)
downloadgitlab-ce-516c838a1846d049814765afa85c28a3c14a5b9f.tar.gz
Add an `Issue::Metrics` model.
- And store the `first_associated_with_milestone_at` and `first_added_to_board_at` times, when an issue is saved.
Diffstat (limited to 'app')
-rw-r--r--app/models/issue.rb9
-rw-r--r--app/models/issue/metrics.rb21
2 files changed, 30 insertions, 0 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 788611305fe..1aa0cef884e 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -23,6 +23,8 @@ class Issue < ActiveRecord::Base
has_many :events, as: :target, dependent: :destroy
+ has_one :metrics, dependent: :destroy
+
validates :project, presence: true
scope :cared, ->(user) { where(assignee_id: user) }
@@ -36,6 +38,8 @@ class Issue < ActiveRecord::Base
scope :order_due_date_asc, -> { reorder('issues.due_date IS NULL, issues.due_date ASC') }
scope :order_due_date_desc, -> { reorder('issues.due_date IS NULL, issues.due_date DESC') }
+ after_save :record_metrics
+
attr_spammable :title, spam_title: true
attr_spammable :description, spam_description: true
@@ -270,4 +274,9 @@ class Issue < ActiveRecord::Base
def check_for_spam?
project.public?
end
+
+ def record_metrics
+ metrics = Metrics.find_or_create_by(issue_id: self.id)
+ metrics.record!
+ end
end
diff --git a/app/models/issue/metrics.rb b/app/models/issue/metrics.rb
new file mode 100644
index 00000000000..4436696cc1a
--- /dev/null
+++ b/app/models/issue/metrics.rb
@@ -0,0 +1,21 @@
+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
+
+ private
+
+ def issue_assigned_to_list_label?
+ issue.labels.any? { |label| label.lists.present? }
+ end
+end