Commit e54f976f authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents 5556c76d 5032df86
......@@ -11,9 +11,7 @@ module CycleAnalytics
end
def summary
@summary ||= ::Gitlab::CycleAnalytics::GroupStageSummary.new(group,
from: options[:from],
current_user: options[:current_user]).data
@summary ||= ::Gitlab::CycleAnalytics::GroupStageSummary.new(group, options: options).data
end
def permissions(*)
......
---
title: Adjust group level analytics to accept multiple ids
merge_request: 30744
author:
type: added
......@@ -4,6 +4,7 @@ module Gitlab
module CycleAnalytics
class BaseEventFetcher
include BaseQuery
include GroupProjectsProvider
attr_reader :projections, :query, :stage, :order, :options
......@@ -73,18 +74,6 @@ module Gitlab
def serialization_context
{}
end
def projects
group ? Project.inside_path(group.full_path) : [project]
end
def group
@group ||= options.fetch(:group, nil)
end
def project
@project ||= options.fetch(:project, nil)
end
end
end
end
......@@ -4,6 +4,7 @@ module Gitlab
module CycleAnalytics
class BaseStage
include BaseQuery
include GroupProjectsProvider
attr_reader :options
......@@ -77,18 +78,6 @@ module Gitlab
def event_options
options.merge(start_time_attrs: start_time_attrs, end_time_attrs: end_time_attrs)
end
def projects
group ? Project.inside_path(group.full_path) : [project]
end
def group
@group ||= options.fetch(:group, nil)
end
def project
@project ||= options.fetch(:project, nil)
end
end
end
end
# frozen_string_literal: true
module Gitlab
module CycleAnalytics
module GroupProjectsProvider
def projects
group ? projects_for_group : [project]
end
def group
@group ||= options.fetch(:group, nil)
end
def project
@project ||= options.fetch(:project, nil)
end
private
def projects_for_group
projects = Project.inside_path(group.full_path)
projects = projects.where(id: options[:projects]) if options[:projects]
projects
end
end
end
end
......@@ -3,15 +3,18 @@
module Gitlab
module CycleAnalytics
class GroupStageSummary
def initialize(group, from:, current_user:)
attr_reader :group, :from, :current_user, :options
def initialize(group, options:)
@group = group
@from = from
@current_user = current_user
@from = options[:from]
@current_user = options[:current_user]
@options = options
end
def data
[serialize(Summary::Group::Issue.new(group: @group, from: @from, current_user: @current_user)),
serialize(Summary::Group::Deploy.new(group: @group, from: @from))]
[serialize(Summary::Group::Issue.new(group: group, from: from, current_user: current_user, options: options)),
serialize(Summary::Group::Deploy.new(group: group, from: from, options: options))]
end
private
......
......@@ -5,9 +5,12 @@ module Gitlab
module Summary
module Group
class Base
def initialize(group:, from:)
attr_reader :group, :from, :options
def initialize(group:, from:, options:)
@group = group
@from = from
@options = options
end
def title
......
......@@ -5,22 +5,23 @@ module Gitlab
module Summary
module Group
class Deploy < Group::Base
include GroupProjectsProvider
def title
n_('Deploy', 'Deploys', value)
end
def value
@value ||= Deployment.joins(:project)
.where(projects: { id: projects })
.where("deployments.created_at > ?", @from)
.success
.count
@value ||= find_deployments
end
private
def projects
Project.inside_path(@group.full_path).ids
def find_deployments
deployments = Deployment.joins(:project).merge(Project.inside_path(group.full_path))
deployments = deployments.where(projects: { id: options[:projects] }) if options[:projects]
deployments = deployments.where("deployments.created_at > ?", from)
deployments.success.count
end
end
end
......
......@@ -5,10 +5,13 @@ module Gitlab
module Summary
module Group
class Issue < Group::Base
def initialize(group:, from:, current_user:)
attr_reader :group, :from, :current_user, :options
def initialize(group:, from:, current_user:, options:)
@group = group
@from = from
@current_user = current_user
@options = options
end
def title
......@@ -16,7 +19,15 @@ module Gitlab
end
def value
@value ||= IssuesFinder.new(@current_user, group_id: @group.id, include_subgroups: true, created_after: @from).execute.count
@value ||= find_issues
end
private
def find_issues
issues = IssuesFinder.new(current_user, group_id: group.id, include_subgroups: true, created_after: from).execute
issues = issues.where(projects: { id: options[:projects] }) if options[:projects]
issues.count
end
end
end
......
......@@ -8,7 +8,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do
let(:from) { 1.day.ago }
let(:user) { create(:user, :admin) }
subject { described_class.new(group, from: Time.now, current_user: user).data }
subject { described_class.new(group, options: { from: Time.now, current_user: user }).data }
describe "#new_issues" do
context 'with from date' do
......@@ -32,6 +32,18 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do
expect(subject.first[:value]).to eq(3)
end
end
context 'with projects specified in options' do
before do
Timecop.freeze(5.days.from_now) { create(:issue, project: create(:project, namespace: group)) }
end
subject { described_class.new(group, options: { from: Time.now, current_user: user, projects: [project.id, project_2.id] }).data }
it 'finds issues from those projects' do
expect(subject.first[:value]).to eq(2)
end
end
end
context 'with other projects' do
......@@ -71,6 +83,20 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do
expect(subject.second[:value]).to eq(3)
end
end
context 'with projects specified in options' do
before do
Timecop.freeze(5.days.from_now) do
create(:deployment, :success, project: create(:project, :repository, namespace: group, name: 'not_applicable'))
end
end
subject { described_class.new(group, options: { from: Time.now, current_user: user, projects: [project.id, project_2.id] }).data }
it 'shows deploys from those projects' do
expect(subject.second[:value]).to eq(2)
end
end
end
context 'with other projects' do
......
......@@ -71,6 +71,29 @@ describe Gitlab::CycleAnalytics::IssueStage do
end
end
context 'when only part of projects is chosen' do
let(:stage) { described_class.new(options: { from: 2.days.ago, current_user: user, group: group, projects: [project_2.id] }) }
describe '#group_median' do
around do |example|
Timecop.freeze { example.run }
end
it 'counts median from issues with metrics' do
expect(stage.group_median).to eq(ISSUES_MEDIAN)
end
end
describe '#events' do
subject { stage.events }
it 'exposes merge requests that close issues' do
expect(subject.count).to eq(1)
expect(subject.map { |event| event[:title] }).to contain_exactly(issue_2_1.title)
end
end
end
context 'when subgroup is given' do
let(:subgroup) { create(:group, parent: group) }
let(:project_4) { create(:project, group: subgroup) }
......
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