Commit bd31f24c authored by James Lopez's avatar James Lopez

Added branch option to test events

Also fixed test events ordering issue
parent eccb6a5e
...@@ -17,6 +17,8 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll ...@@ -17,6 +17,8 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
end end
def test def test
@opts = { from: start_date, branch: events_params[:branch_name] }
render_events(builds: events.test_events) render_events(builds: events.test_events)
end end
...@@ -54,12 +56,16 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll ...@@ -54,12 +56,16 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
end end
def events def events
@events ||= Gitlab::CycleAnalytics::Events.new(project: project, from: start_date) @events ||= Gitlab::CycleAnalytics::Events.new(project: project, options: options)
end
def options
@opts ||= { from: start_date }
end end
def events_params def events_params
return {} unless params[:events].present? return {} unless params[:events].present?
{ start_date: params[:events][:start_date] } { start_date: params[:events][:start_date], branch_name: params[:events][:branch_name] }
end end
end end
...@@ -3,10 +3,9 @@ module Gitlab ...@@ -3,10 +3,9 @@ module Gitlab
class Events class Events
include ActionView::Helpers::DateHelper include ActionView::Helpers::DateHelper
def initialize(project:, from:) def initialize(project:, options:)
@project = project @project = project
@from = from @fetcher = EventsFetcher.new(project: project, options: options)
@fetcher = EventsFetcher.new(project: project, from: from)
end end
def issue_events def issue_events
......
...@@ -3,8 +3,8 @@ module Gitlab ...@@ -3,8 +3,8 @@ module Gitlab
class EventsFetcher class EventsFetcher
include MetricsFetcher include MetricsFetcher
def initialize(project:, from:) def initialize(project:, options:)
@query = EventsQuery.new(project: project, from: from) @query = EventsQuery.new(project: project, options: options)
end end
def fetch(stage:) def fetch(stage:)
......
...@@ -3,9 +3,10 @@ module Gitlab ...@@ -3,9 +3,10 @@ module Gitlab
class EventsQuery class EventsQuery
include MetricsFetcher include MetricsFetcher
def initialize(project:, from:) def initialize(project:, options: {})
@project = project @project = project
@from = from @from = options[:from]
@branch = options[:branch]
end end
def execute(stage, &block) def execute(stage, &block)
......
...@@ -38,6 +38,8 @@ module Gitlab ...@@ -38,6 +38,8 @@ module Gitlab
where(issue_table[:deleted_at].eq(nil)). where(issue_table[:deleted_at].eq(nil)).
where(issue_table[:created_at].gteq(@from)) where(issue_table[:created_at].gteq(@from))
query = query.where(build_table[:ref].eq(@branch)) if name == :test && @branch
# Load merge_requests # Load merge_requests
query = query.join(mr_table, Arel::Nodes::OuterJoin). query = query.join(mr_table, Arel::Nodes::OuterJoin).
on(mr_table[:id].eq(mr_closing_issues_table[:merge_request_id])). on(mr_table[:id].eq(mr_closing_issues_table[:merge_request_id])).
......
...@@ -56,7 +56,7 @@ module Gitlab ...@@ -56,7 +56,7 @@ module Gitlab
{ start_time_attrs: mr_metrics_table[:latest_build_started_at], { start_time_attrs: mr_metrics_table[:latest_build_started_at],
end_time_attrs: mr_metrics_table[:latest_build_finished_at], end_time_attrs: mr_metrics_table[:latest_build_finished_at],
projections: [build_table[:id]], projections: [build_table[:id]],
order: mr_table[:created_at] order: build_table[:created_at]
} }
end end
......
...@@ -6,7 +6,7 @@ describe Gitlab::CycleAnalytics::Events do ...@@ -6,7 +6,7 @@ describe Gitlab::CycleAnalytics::Events do
let(:user) { create(:user, :admin) } let(:user) { create(:user, :admin) }
let!(:context) { create(:issue, project: project, created_at: 2.days.ago) } let!(:context) { create(:issue, project: project, created_at: 2.days.ago) }
subject { described_class.new(project: project, from: from_date) } subject { described_class.new(project: project, options: { from: from_date }) }
before do before do
setup(context) setup(context)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment