Commit 074ff58f authored by charlie ablett's avatar charlie ablett

Merge branch 'ag-add-time-summary' into 'master'

Add endpoint for time summary in group level VSA

See merge request gitlab-org/gitlab!29791
parents 69677adf 569a4bf4
...@@ -8,18 +8,23 @@ module Analytics ...@@ -8,18 +8,23 @@ module Analytics
check_feature_flag Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG check_feature_flag Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG
before_action :load_group before_action :load_group
before_action :authorize_access
before_action :validate_params before_action :validate_params
def show def show
return render_403 unless can?(current_user, :read_group_cycle_analytics, @group)
group_level = GroupLevel.new(group: @group, options: options(group_params))
render json: group_level.summary render json: group_level.summary
end end
def time_summary
render json: group_level.time_summary
end
private private
def group_level
@group_level ||= GroupLevel.new(group: @group, options: options(group_params))
end
def group_params def group_params
hash = { created_after: request_params.created_after, created_before: request_params.created_before } hash = { created_after: request_params.created_after, created_before: request_params.created_before }
hash[:project_ids] = request_params.project_ids if request_params.project_ids.any? hash[:project_ids] = request_params.project_ids if request_params.project_ids.any?
...@@ -42,6 +47,10 @@ module Analytics ...@@ -42,6 +47,10 @@ module Analytics
def allowed_params def allowed_params
params.permit(:created_after, :created_before, project_ids: []) params.permit(:created_after, :created_before, project_ids: [])
end end
def authorize_access
return render_403 unless can?(current_user, :read_group_cycle_analytics, @group)
end
end end
end end
end end
...@@ -15,8 +15,15 @@ module Analytics ...@@ -15,8 +15,15 @@ module Analytics
def summary def summary
@summary ||= @summary ||=
Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary Gitlab::Analytics::CycleAnalytics::Summary::Group::StageSummary
.new(group, options: options) .new(group, options: options)
.data .data
end
def time_summary
@time_summary ||=
Gitlab::Analytics::CycleAnalytics::GroupStageTimeSummary
.new(group, options: options)
.data
end end
def permissions(*) def permissions(*)
......
...@@ -14,6 +14,7 @@ namespace :analytics do ...@@ -14,6 +14,7 @@ namespace :analytics do
end end
end end
resource :summary, controller: :summary, only: :show resource :summary, controller: :summary, only: :show
get '/time_summary' => 'summary#time_summary'
end end
get '/cycle_analytics', to: redirect('-/analytics/value_stream_analytics') get '/cycle_analytics', to: redirect('-/analytics/value_stream_analytics')
end end
......
...@@ -36,6 +36,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do ...@@ -36,6 +36,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
end end
end end
resource :summary, controller: :summary, only: :show resource :summary, controller: :summary, only: :show
get '/time_summary' => 'summary#time_summary'
end end
get '/cycle_analytics', to: redirect('-/analytics/value_stream_analytics') get '/cycle_analytics', to: redirect('-/analytics/value_stream_analytics')
end end
......
...@@ -15,9 +15,7 @@ describe Analytics::CycleAnalytics::SummaryController do ...@@ -15,9 +15,7 @@ describe Analytics::CycleAnalytics::SummaryController do
sign_in(user) sign_in(user)
end end
describe 'GET `show`' do shared_examples 'summary endpoint' do
subject { get :show, params: params }
it 'succeeds' do it 'succeeds' do
subject subject
...@@ -46,4 +44,16 @@ describe Analytics::CycleAnalytics::SummaryController do ...@@ -46,4 +44,16 @@ describe Analytics::CycleAnalytics::SummaryController do
include_examples 'cycle analytics data endpoint examples' include_examples 'cycle analytics data endpoint examples'
include_examples 'group permission check on the controller level' include_examples 'group permission check on the controller level'
end end
describe 'GET "show"' do
subject { get :show, params: params }
it_behaves_like 'summary endpoint'
end
describe 'GET "time_summary"' do
subject { get :time_summary, params: params }
it_behaves_like 'summary endpoint'
end
end end
...@@ -12,6 +12,10 @@ describe Analytics::CycleAnalytics::GroupLevel do ...@@ -12,6 +12,10 @@ describe Analytics::CycleAnalytics::GroupLevel do
let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") } let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") }
let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) } let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr.source_branch, sha: mr.source_branch_sha, head_pipeline_of: mr) }
around do |example|
Timecop.freeze { example.run }
end
subject { described_class.new(group: group, options: { from: from_date, current_user: user }) } subject { described_class.new(group: group, options: { from: from_date, current_user: user }) }
describe '#permissions' do describe '#permissions' do
...@@ -41,4 +45,22 @@ describe Analytics::CycleAnalytics::GroupLevel do ...@@ -41,4 +45,22 @@ describe Analytics::CycleAnalytics::GroupLevel do
expect(subject.summary.map { |summary| summary[:value] }).to contain_exactly('0.1', '1', '1') expect(subject.summary.map { |summary| summary[:value] }).to contain_exactly('0.1', '1', '1')
end end
end end
describe '#time_summary' do
let(:issue) { create(:issue, project: project) }
before do
# lead_time: 1 day, cycle_time: 2 days
issue.update!(created_at: 5.days.ago)
issue.metrics.update!(first_mentioned_in_commit_at: 4.days.ago)
issue.update!(closed_at: 3.days.ago)
end
it 'returns medians for lead time and cycle type' do
expect(subject.time_summary.map { |summary| summary[:value] }).to contain_exactly('1.0', '2.0')
end
end
end end
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