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
end
def test
@opts = { from: start_date, branch: events_params[:branch_name] }
render_events(builds: events.test_events)
end
......@@ -54,12 +56,16 @@ class Projects::CycleAnalytics::EventsController < Projects::ApplicationControll
end
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
def events_params
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
......@@ -3,10 +3,9 @@ module Gitlab
class Events
include ActionView::Helpers::DateHelper
def initialize(project:, from:)
def initialize(project:, options:)
@project = project
@from = from
@fetcher = EventsFetcher.new(project: project, from: from)
@fetcher = EventsFetcher.new(project: project, options: options)
end
def issue_events
......
......@@ -3,8 +3,8 @@ module Gitlab
class EventsFetcher
include MetricsFetcher
def initialize(project:, from:)
@query = EventsQuery.new(project: project, from: from)
def initialize(project:, options:)
@query = EventsQuery.new(project: project, options: options)
end
def fetch(stage:)
......
......@@ -3,9 +3,10 @@ module Gitlab
class EventsQuery
include MetricsFetcher
def initialize(project:, from:)
def initialize(project:, options: {})
@project = project
@from = from
@from = options[:from]
@branch = options[:branch]
end
def execute(stage, &block)
......
......@@ -38,6 +38,8 @@ module Gitlab
where(issue_table[:deleted_at].eq(nil)).
where(issue_table[:created_at].gteq(@from))
query = query.where(build_table[:ref].eq(@branch)) if name == :test && @branch
# Load merge_requests
query = query.join(mr_table, Arel::Nodes::OuterJoin).
on(mr_table[:id].eq(mr_closing_issues_table[:merge_request_id])).
......
......@@ -56,7 +56,7 @@ module Gitlab
{ start_time_attrs: mr_metrics_table[:latest_build_started_at],
end_time_attrs: mr_metrics_table[:latest_build_finished_at],
projections: [build_table[:id]],
order: mr_table[:created_at]
order: build_table[:created_at]
}
end
......
......@@ -6,7 +6,7 @@ describe Gitlab::CycleAnalytics::Events do
let(:user) { create(:user, :admin) }
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
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