summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-08-26 15:45:00 +0530
committerTimothy Andrew <mail@timothyandrew.net>2016-08-26 16:28:20 +0530
commitdf6c9c33b69e411d4f7d27cc46e9769a07d12285 (patch)
tree0a6e0a20a2371c0462371001542a34a9c9d00537
parenta81de9ab4fc3c3720449069e91ee2431fd9eb024 (diff)
downloadgitlab-ce-df6c9c33b69e411d4f7d27cc46e9769a07d12285.tar.gz
Scope Cycle Analytics queries to a project
-rw-r--r--app/controllers/projects/cycle_analytics_controller.rb2
-rw-r--r--app/models/cycle_analytics.rb18
-rw-r--r--app/models/cycle_analytics/queries.rb8
-rw-r--r--spec/models/cycle_analytics/issue_spec.rb21
4 files changed, 29 insertions, 20 deletions
diff --git a/app/controllers/projects/cycle_analytics_controller.rb b/app/controllers/projects/cycle_analytics_controller.rb
index 9dab7bfa380..85c81cba511 100644
--- a/app/controllers/projects/cycle_analytics_controller.rb
+++ b/app/controllers/projects/cycle_analytics_controller.rb
@@ -1,5 +1,5 @@
class Projects::CycleAnalyticsController < Projects::ApplicationController
def show
- @cycle_analytics = CycleAnalytics.new
+ @cycle_analytics = CycleAnalytics.new(@project)
end
end
diff --git a/app/models/cycle_analytics.rb b/app/models/cycle_analytics.rb
index 34a841ff5ce..331bb450e08 100644
--- a/app/models/cycle_analytics.rb
+++ b/app/models/cycle_analytics.rb
@@ -1,42 +1,46 @@
class CycleAnalytics
+ def initialize(project)
+ @project = project
+ end
+
def issue
- calculate_metric(Queries::issues,
+ calculate_metric(Queries::issues(@project),
-> (data_point) { data_point[:issue].created_at },
[Queries::issue_first_associated_with_milestone_at, Queries::issue_first_added_to_list_label_at])
end
def plan
- calculate_metric(Queries::issues,
+ calculate_metric(Queries::issues(@project),
[Queries::issue_first_associated_with_milestone_at, Queries::issue_first_added_to_list_label_at],
Queries::issue_closing_merge_request_opened_at)
end
def code
- calculate_metric(Queries::merge_requests_closing_issues,
+ calculate_metric(Queries::merge_requests_closing_issues(@project),
-> (data_point) { data_point[:merge_request].created_at },
[Queries::merge_request_first_assigned_to_user_other_than_author_at, Queries::merge_request_wip_flag_first_removed_at])
end
def test
- calculate_metric(Queries::merge_requests_closing_issues,
+ calculate_metric(Queries::merge_requests_closing_issues(@project),
Queries::merge_request_build_started_at,
Queries::merge_request_build_finished_at)
end
def review
- calculate_metric(Queries::merge_requests_closing_issues,
+ calculate_metric(Queries::merge_requests_closing_issues(@project),
[Queries::merge_request_first_assigned_to_user_other_than_author_at, Queries::merge_request_wip_flag_first_removed_at],
[Queries::merge_request_first_closed_at, Queries::merge_request_merged_at])
end
def staging
- calculate_metric(Queries::merge_requests_closing_issues,
+ calculate_metric(Queries::merge_requests_closing_issues(@project),
Queries::merge_request_merged_at,
Queries::merge_request_deployed_to_any_environment_at)
end
def production
- calculate_metric(Queries::merge_requests_closing_issues,
+ calculate_metric(Queries::merge_requests_closing_issues(@project),
-> (data_point) { data_point[:issue].created_at },
Queries::merge_request_deployed_to_production_at)
end
diff --git a/app/models/cycle_analytics/queries.rb b/app/models/cycle_analytics/queries.rb
index 1074b62039b..122b2599bd3 100644
--- a/app/models/cycle_analytics/queries.rb
+++ b/app/models/cycle_analytics/queries.rb
@@ -1,12 +1,12 @@
class CycleAnalytics
module Queries
class << self
- def issues
- Issue.all.to_a.map { |issue| { issue: issue } }
+ def issues(project)
+ project.issues.map { |issue| { issue: issue } }
end
- def merge_requests_closing_issues
- issues.map do |data_point|
+ def merge_requests_closing_issues(project)
+ issues(project).map do |data_point|
merge_requests = data_point[:issue].closed_by_merge_requests(nil, check_if_open: false)
merge_requests.map { |merge_request| { issue: data_point[:issue], merge_request: merge_request } }
end.flatten
diff --git a/spec/models/cycle_analytics/issue_spec.rb b/spec/models/cycle_analytics/issue_spec.rb
index ba66c99631c..6fdce020642 100644
--- a/spec/models/cycle_analytics/issue_spec.rb
+++ b/spec/models/cycle_analytics/issue_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe 'CycleAnalytics#issue', models: true do
let(:project) { create(:project) }
- subject { CycleAnalytics.new }
+ subject { CycleAnalytics.new(project) }
context "when calculating the median of times between:
start: issue created_at
@@ -26,6 +26,16 @@ describe 'CycleAnalytics#issue', models: true do
median_start_time, median_end_time = start_and_end_times[2]
expect(subject.issue).to eq(median_end_time - median_start_time)
end
+
+ it "does not include issues from other projects" do
+ 5.times do
+ milestone = create(:milestone, project: project)
+ issue = create(:issue)
+ issue.update(milestone: milestone)
+ end
+
+ expect(subject.issue).to be_nil
+ end
end
context "when a label is added to the issue" do
@@ -47,14 +57,9 @@ describe 'CycleAnalytics#issue', models: true do
it "does not make a calculation for regular labels" do
5.times do
- start_time = Time.now
- end_time = rand(1..10).days.from_now
-
regular_label = create(:label)
- issue = Timecop.freeze(start_time) { create(:issue, project: project) }
- Timecop.freeze(end_time) { issue.update(label_ids: [regular_label.id]) }
-
- [start_time, end_time]
+ issue = create(:issue, project: project)
+ issue.update(label_ids: [regular_label.id])
end
expect(subject.issue).to be_nil