Commit 7f2859db authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '217944-rename-vsa-stagesummary-class' into 'master'

Rename VSA StageSummary class

See merge request gitlab-org/gitlab!53882
parents bf59a42f d379ca3c
......@@ -19,7 +19,7 @@ module Analytics
def time_summary
@time_summary ||=
Gitlab::Analytics::CycleAnalytics::GroupStageTimeSummary
Gitlab::Analytics::CycleAnalytics::Summary::Group::StageTimeSummary
.new(group, options: options)
.data
end
......
# frozen_string_literal: true
module Gitlab
module Analytics
module CycleAnalytics
class GroupStageTimeSummary
attr_reader :group, :current_user, :options
def initialize(group, options:)
@group = group
@current_user = options[:current_user]
@options = options
end
def data
[lead_time, cycle_time]
end
private
def lead_time
serialize(
Summary::Group::LeadTime.new(
group: group, current_user: current_user, options: options
),
with_unit: true
)
end
def cycle_time
serialize(
Summary::Group::CycleTime.new(
group: group, current_user: current_user, options: options
),
with_unit: true
)
end
def serialize(summary_object, with_unit: false)
AnalyticsSummarySerializer.new.represent(
summary_object, with_unit: with_unit)
end
end
end
end
end
......@@ -15,7 +15,7 @@ module Gitlab
end
def data
[lead_time]
[lead_time, cycle_time]
end
private
......@@ -29,6 +29,15 @@ module Gitlab
)
end
def cycle_time
serialize(
Summary::Group::CycleTime.new(
group: group, current_user: current_user, options: options
),
with_unit: true
)
end
def serialize(summary_object, with_unit: false)
AnalyticsSummarySerializer.new.represent(
summary_object, with_unit: with_unit)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Analytics::CycleAnalytics::GroupStageTimeSummary do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, namespace: group) }
let_it_be(:project_2) { create(:project, :repository, namespace: group) }
let_it_be(:user) { create(:user) }
let(:from) { 1.day.ago }
let(:to) { nil }
let(:options) { { from: from, to: to, current_user: user } }
subject { described_class.new(group, options: options).data }
around do |example|
freeze_time { example.run }
end
before do
group.add_owner(user)
end
describe '#lead_time' do
describe 'issuable filter parameters' do
let_it_be(:label) { create(:group_label, group: group) }
before do
create(:closed_issue, project: project, created_at: 1.day.ago, closed_at: Time.zone.now, author: user, labels: [label])
end
context 'when `author_username` is given' do
before do
options[:author_username] = user.username
end
it 'returns the correct lead time' do
expect(subject.first[:value]).to eq('1.0')
end
end
context 'when unknown `author_username` is given' do
before do
options[:author_username] = 'unknown_user'
end
it 'returns `-`' do
expect(subject.first[:value]).to eq('-')
end
end
context 'when `label_name` is given' do
before do
options[:label_name] = [label.name]
end
it 'returns the correct lead time' do
expect(subject.first[:value]).to eq('1.0')
end
end
context 'when unknown `label_name` is given' do
before do
options[:label_name] = ['unknown_label']
end
it 'returns `-`' do
expect(subject.first[:value]).to eq('-')
end
end
end
context 'with `from` date' do
let(:from) { 6.days.ago }
before do
create(:closed_issue, project: project, created_at: 1.day.ago, closed_at: Time.zone.now)
create(:closed_issue, project: project, created_at: 2.days.ago, closed_at: Time.zone.now)
create(:closed_issue, project: project_2, created_at: 4.days.ago, closed_at: Time.zone.now)
end
it 'finds the lead time of issues created after it' do
expect(subject.first[:value]).to eq('2.0')
end
context 'with subgroups' do
let(:subgroup) { create(:group, parent: group) }
let(:project_3) { create(:project, namespace: subgroup) }
before do
create(:closed_issue, created_at: 3.days.ago, closed_at: Time.zone.now, project: project_3)
create(:closed_issue, created_at: 5.days.ago, closed_at: Time.zone.now, project: project_3)
end
it 'finds the lead time of issues from them' do
expect(subject.first[:value]).to eq('3.0')
end
end
context 'with projects specified in options' do
before do
create(:closed_issue, created_at: 3.days.ago, closed_at: Time.zone.now, project: create(:project, namespace: group))
end
subject { described_class.new(group, options: { from: from, current_user: user, projects: [project.id, project_2.id] }).data }
it 'finds the lead time of issues from those projects' do
# Median of 1, 2, 4, not including new issue
expect(subject.first[:value]).to eq('2.0')
end
end
context 'when `from` and `to` parameters are provided' do
let(:from) { 3.days.ago }
let(:to) { Time.zone.now }
it 'finds the lead time of issues from 3 days ago' do
expect(subject.first[:value]).to eq('1.5')
end
end
end
context 'with other projects' do
let(:from) { 4.days.ago }
before do
create(:closed_issue, created_at: 1.day.ago, closed_at: Time.zone.now, project: create(:project, namespace: create(:group)))
create(:closed_issue, created_at: 2.days.ago, closed_at: Time.zone.now, project: project)
create(:closed_issue, created_at: 3.days.ago, closed_at: Time.zone.now, project: project_2)
end
it 'does not find the lead time of issues from them' do
# Median of 2, 3, not including first issue
expect(subject.first[:value]).to eq('2.5')
end
end
end
describe '#cycle_time' do
let(:created_at) { 6.days.ago }
context 'with `from` date' do
let(:from) { 7.days.ago }
before do
issue_1 = create(:closed_issue, project: project, closed_at: Time.zone.now, created_at: created_at)
issue_2 = create(:closed_issue, project: project, closed_at: Time.zone.now, created_at: created_at)
issue_3 = create(:closed_issue, project: project_2, closed_at: Time.zone.now, created_at: created_at)
issue_1.metrics.update!(first_mentioned_in_commit_at: 1.day.ago)
issue_2.metrics.update!(first_mentioned_in_commit_at: 2.days.ago)
issue_3.metrics.update!(first_mentioned_in_commit_at: 4.days.ago)
end
it 'finds the cycle time of issues created after it' do
expect(subject.second[:value]).to eq('2.0')
end
context 'with subgroups' do
let(:subgroup) { create(:group, parent: group) }
let(:project_3) { create(:project, namespace: subgroup) }
before do
issue_4 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: project_3)
issue_5 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: project_3)
issue_4.metrics.update!(first_mentioned_in_commit_at: 3.days.ago)
issue_5.metrics.update!(first_mentioned_in_commit_at: 5.days.ago)
end
it 'finds the cycle time of issues from them' do
expect(subject.second[:value]).to eq('3.0')
end
end
context 'with projects specified in options' do
before do
issue_4 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: create(:project, namespace: group))
issue_4.metrics.update!(first_mentioned_in_commit_at: 3.days.ago)
end
subject { described_class.new(group, options: { from: from, current_user: user, projects: [project.id, project_2.id] }).data }
it 'finds the cycle time of issues from those projects' do
# Median of 1, 2, 4, not including new issue
expect(subject.second[:value]).to eq('2.0')
end
end
context 'when `from` and `to` parameters are provided' do
let(:from) { 5.days.ago }
let(:to) { 2.days.ago }
let(:created_at) { from }
it 'finds the cycle time of issues created between `from` and `to`' do
# Median of 1, 2, 4
expect(subject.second[:value]).to eq('2.0')
end
end
end
context 'with other projects' do
let(:from) { 4.days.ago }
let(:created_at) { from }
before do
issue_1 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: create(:project, namespace: create(:group)))
issue_2 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: project)
issue_3 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: project_2)
issue_1.metrics.update!(first_mentioned_in_commit_at: 1.day.ago)
issue_2.metrics.update!(first_mentioned_in_commit_at: 2.days.ago)
issue_3.metrics.update!(first_mentioned_in_commit_at: 3.days.ago)
end
it 'does not find the cycle time of issues from them' do
# Median of 2, 3, not including first issue
expect(subject.second[:value]).to eq('2.5')
end
end
end
end
......@@ -2,14 +2,15 @@
require 'spec_helper'
RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageTimeSummary do
let(:group) { create(:group) }
let(:project) { create(:project, :repository, namespace: group) }
let(:project_2) { create(:project, :repository, namespace: group) }
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, namespace: group) }
let_it_be(:project_2) { create(:project, :repository, namespace: group) }
let_it_be(:user) { create(:user) }
let(:from) { 1.day.ago }
let(:to) { nil }
let(:user) { create(:user) }
let(:options) { { from: from, to: to, current_user: user } }
subject { described_class.new(group, options: { from: from, to: to, current_user: user }).data }
subject { described_class.new(group, options: options).data }
around do |example|
freeze_time { example.run }
......@@ -20,13 +21,61 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageTimeSumma
end
describe '#lead_time' do
describe 'issuable filter parameters' do
let_it_be(:label) { create(:group_label, group: group) }
before do
create(:closed_issue, project: project, created_at: 1.day.ago, closed_at: Time.zone.now, author: user, labels: [label])
end
context 'when `author_username` is given' do
before do
options[:author_username] = user.username
end
it 'returns the correct lead time' do
expect(subject.first[:value]).to eq('1.0')
end
end
context 'when unknown `author_username` is given' do
before do
options[:author_username] = 'unknown_user'
end
it 'returns `-`' do
expect(subject.first[:value]).to eq('-')
end
end
context 'when `label_name` is given' do
before do
options[:label_name] = [label.name]
end
it 'returns the correct lead time' do
expect(subject.first[:value]).to eq('1.0')
end
end
context 'when unknown `label_name` is given' do
before do
options[:label_name] = ['unknown_label']
end
it 'returns `-`' do
expect(subject.first[:value]).to eq('-')
end
end
end
context 'with `from` date' do
let(:from) { 6.days.ago }
before do
create(:closed_issue, project: project, created_at: 1.day.ago, closed_at: Time.now)
create(:closed_issue, project: project, created_at: 2.days.ago, closed_at: Time.now)
create(:closed_issue, project: project_2, created_at: 4.days.ago, closed_at: Time.now)
create(:closed_issue, project: project, created_at: 1.day.ago, closed_at: Time.zone.now)
create(:closed_issue, project: project, created_at: 2.days.ago, closed_at: Time.zone.now)
create(:closed_issue, project: project_2, created_at: 4.days.ago, closed_at: Time.zone.now)
end
it 'finds the lead time of issues created after it' do
......@@ -38,8 +87,8 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageTimeSumma
let(:project_3) { create(:project, namespace: subgroup) }
before do
create(:closed_issue, created_at: 3.days.ago, closed_at: Time.now, project: project_3)
create(:closed_issue, created_at: 5.days.ago, closed_at: Time.now, project: project_3)
create(:closed_issue, created_at: 3.days.ago, closed_at: Time.zone.now, project: project_3)
create(:closed_issue, created_at: 5.days.ago, closed_at: Time.zone.now, project: project_3)
end
it 'finds the lead time of issues from them' do
......@@ -49,7 +98,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageTimeSumma
context 'with projects specified in options' do
before do
create(:closed_issue, created_at: 3.days.ago, closed_at: Time.now, project: create(:project, namespace: group))
create(:closed_issue, created_at: 3.days.ago, closed_at: Time.zone.now, project: create(:project, namespace: group))
end
subject { described_class.new(group, options: { from: from, current_user: user, projects: [project.id, project_2.id] }).data }
......@@ -62,7 +111,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageTimeSumma
context 'when `from` and `to` parameters are provided' do
let(:from) { 3.days.ago }
let(:to) { Time.now }
let(:to) { Time.zone.now }
it 'finds the lead time of issues from 3 days ago' do
expect(subject.first[:value]).to eq('1.5')
......@@ -74,9 +123,9 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageTimeSumma
let(:from) { 4.days.ago }
before do
create(:closed_issue, created_at: 1.day.ago, closed_at: Time.now, project: create(:project, namespace: create(:group)))
create(:closed_issue, created_at: 2.days.ago, closed_at: Time.now, project: project)
create(:closed_issue, created_at: 3.days.ago, closed_at: Time.now, project: project_2)
create(:closed_issue, created_at: 1.day.ago, closed_at: Time.zone.now, project: create(:project, namespace: create(:group)))
create(:closed_issue, created_at: 2.days.ago, closed_at: Time.zone.now, project: project)
create(:closed_issue, created_at: 3.days.ago, closed_at: Time.zone.now, project: project_2)
end
it 'does not find the lead time of issues from them' do
......@@ -85,4 +134,88 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Summary::Group::StageTimeSumma
end
end
end
describe '#cycle_time' do
let(:created_at) { 6.days.ago }
context 'with `from` date' do
let(:from) { 7.days.ago }
before do
issue_1 = create(:closed_issue, project: project, closed_at: Time.zone.now, created_at: created_at)
issue_2 = create(:closed_issue, project: project, closed_at: Time.zone.now, created_at: created_at)
issue_3 = create(:closed_issue, project: project_2, closed_at: Time.zone.now, created_at: created_at)
issue_1.metrics.update!(first_mentioned_in_commit_at: 1.day.ago)
issue_2.metrics.update!(first_mentioned_in_commit_at: 2.days.ago)
issue_3.metrics.update!(first_mentioned_in_commit_at: 4.days.ago)
end
it 'finds the cycle time of issues created after it' do
expect(subject.second[:value]).to eq('2.0')
end
context 'with subgroups' do
let(:subgroup) { create(:group, parent: group) }
let(:project_3) { create(:project, namespace: subgroup) }
before do
issue_4 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: project_3)
issue_5 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: project_3)
issue_4.metrics.update!(first_mentioned_in_commit_at: 3.days.ago)
issue_5.metrics.update!(first_mentioned_in_commit_at: 5.days.ago)
end
it 'finds the cycle time of issues from them' do
expect(subject.second[:value]).to eq('3.0')
end
end
context 'with projects specified in options' do
before do
issue_4 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: create(:project, namespace: group))
issue_4.metrics.update!(first_mentioned_in_commit_at: 3.days.ago)
end
subject { described_class.new(group, options: { from: from, current_user: user, projects: [project.id, project_2.id] }).data }
it 'finds the cycle time of issues from those projects' do
# Median of 1, 2, 4, not including new issue
expect(subject.second[:value]).to eq('2.0')
end
end
context 'when `from` and `to` parameters are provided' do
let(:from) { 5.days.ago }
let(:to) { 2.days.ago }
let(:created_at) { from }
it 'finds the cycle time of issues created between `from` and `to`' do
# Median of 1, 2, 4
expect(subject.second[:value]).to eq('2.0')
end
end
end
context 'with other projects' do
let(:from) { 4.days.ago }
let(:created_at) { from }
before do
issue_1 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: create(:project, namespace: create(:group)))
issue_2 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: project)
issue_3 = create(:closed_issue, created_at: created_at, closed_at: Time.zone.now, project: project_2)
issue_1.metrics.update!(first_mentioned_in_commit_at: 1.day.ago)
issue_2.metrics.update!(first_mentioned_in_commit_at: 2.days.ago)
issue_3.metrics.update!(first_mentioned_in_commit_at: 3.days.ago)
end
it 'does not find the cycle time of issues from them' do
# Median of 2, 3, not including first issue
expect(subject.second[:value]).to eq('2.5')
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