Commit 1b102f5d authored by Małgorzata Ksionek's avatar Małgorzata Ksionek

Add basic project extraction

To allow project filtering

Prepare summary for accepting multiple groups

Modify deploys group summary class

Add filtering by project name in issues summary

Fix rubocop offences

Add changelog entry

Change name to id in project filtering

Fix rebase problem

Add project extraction
parent f4101aea
...@@ -13,7 +13,8 @@ module CycleAnalytics ...@@ -13,7 +13,8 @@ module CycleAnalytics
def summary def summary
@summary ||= ::Gitlab::CycleAnalytics::GroupStageSummary.new(group, @summary ||= ::Gitlab::CycleAnalytics::GroupStageSummary.new(group,
from: options[:from], from: options[:from],
current_user: options[:current_user]).data current_user: options[:current_user],
options: options).data
end end
def permissions(*) def permissions(*)
......
---
title: Adjust group level analytics to accept multiple ids
merge_request: 30468
author:
type: added
This diff is collapsed.
# frozen_string_literal: true
module Gitlab
module CycleAnalytics
module BaseDataExtraction
private
def projects
group ? extract_projects(options) : [project]
end
def group
@group ||= options.fetch(:group, nil)
end
def project
@project ||= options.fetch(:project, nil)
end
def extract_projects(options)
projects = Project.inside_path(group.full_path)
projects = projects.where(id: options[:projects]) if options[:projects]
projects
end
end
end
end
...@@ -4,6 +4,7 @@ module Gitlab ...@@ -4,6 +4,7 @@ module Gitlab
module CycleAnalytics module CycleAnalytics
class BaseEventFetcher class BaseEventFetcher
include BaseQuery include BaseQuery
include BaseDataExtraction
attr_reader :projections, :query, :stage, :order, :options attr_reader :projections, :query, :stage, :order, :options
...@@ -73,18 +74,6 @@ module Gitlab ...@@ -73,18 +74,6 @@ module Gitlab
def serialization_context def serialization_context
{} {}
end 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 end
end end
...@@ -4,6 +4,7 @@ module Gitlab ...@@ -4,6 +4,7 @@ module Gitlab
module CycleAnalytics module CycleAnalytics
class BaseStage class BaseStage
include BaseQuery include BaseQuery
include BaseDataExtraction
attr_reader :options attr_reader :options
...@@ -77,18 +78,6 @@ module Gitlab ...@@ -77,18 +78,6 @@ module Gitlab
def event_options def event_options
options.merge(start_time_attrs: start_time_attrs, end_time_attrs: end_time_attrs) options.merge(start_time_attrs: start_time_attrs, end_time_attrs: end_time_attrs)
end 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 end
end end
...@@ -3,15 +3,16 @@ ...@@ -3,15 +3,16 @@
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class GroupStageSummary class GroupStageSummary
def initialize(group, from:, current_user:) def initialize(group, from:, current_user:, options:)
@group = group @group = group
@from = from @from = from
@current_user = current_user @current_user = current_user
@options = options
end end
def data def data
[serialize(Summary::Group::Issue.new(group: @group, from: @from, current_user: @current_user)), [serialize(Summary::Group::Issue.new(group: @group, from: @from, current_user: @current_user, options: @options)),
serialize(Summary::Group::Deploy.new(group: @group, from: @from))] serialize(Summary::Group::Deploy.new(group: @group, from: @from, options: @options))]
end end
private private
......
...@@ -5,9 +5,10 @@ module Gitlab ...@@ -5,9 +5,10 @@ module Gitlab
module Summary module Summary
module Group module Group
class Base class Base
def initialize(group:, from:) def initialize(group:, from:, options:)
@group = group @group = group
@from = from @from = from
@options = options
end end
def title def title
......
...@@ -10,15 +10,19 @@ module Gitlab ...@@ -10,15 +10,19 @@ module Gitlab
end end
def value def value
@value ||= Deployment.joins(:project) @value ||= find_deployments
.where(projects: { id: projects })
.where("deployments.created_at > ?", @from)
.success
.count
end end
private private
def find_deployments
deployments = Deployment.joins(:project)
.where(projects: { id: projects })
.where("deployments.created_at > ?", @from)
deployments = deployments.where(projects: { id: @options[:projects] }) if @options[:projects]
deployments.success.count
end
def projects def projects
Project.inside_path(@group.full_path).ids Project.inside_path(@group.full_path).ids
end end
......
...@@ -5,10 +5,11 @@ module Gitlab ...@@ -5,10 +5,11 @@ module Gitlab
module Summary module Summary
module Group module Group
class Issue < Group::Base class Issue < Group::Base
def initialize(group:, from:, current_user:) def initialize(group:, from:, current_user:, options:)
@group = group @group = group
@from = from @from = from
@current_user = current_user @current_user = current_user
@options = options
end end
def title def title
...@@ -16,7 +17,15 @@ module Gitlab ...@@ -16,7 +17,15 @@ module Gitlab
end end
def value 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 end
end end
......
...@@ -8,7 +8,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do ...@@ -8,7 +8,7 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do
let(:from) { 1.day.ago } let(:from) { 1.day.ago }
let(:user) { create(:user, :admin) } let(:user) { create(:user, :admin) }
subject { described_class.new(group, from: Time.now, current_user: user).data } subject { described_class.new(group, from: Time.now, current_user: user, options: {}).data }
describe "#new_issues" do describe "#new_issues" do
context 'with from date' do context 'with from date' do
...@@ -32,6 +32,18 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do ...@@ -32,6 +32,18 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do
expect(subject.first[:value]).to eq(3) expect(subject.first[:value]).to eq(3)
end end
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, from: Time.now, current_user: user, options: { projects: [project.id, project_2.id] }).data }
it 'finds issues from those projects' do
expect(subject.first[:value]).to eq(2)
end
end
end end
context 'with other projects' do context 'with other projects' do
...@@ -71,6 +83,20 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do ...@@ -71,6 +83,20 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do
expect(subject.second[:value]).to eq(3) expect(subject.second[:value]).to eq(3)
end end
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, from: Time.now, current_user: user, options: { projects: [project.id, project_2.id] }).data }
it 'shows deploys from those projects' do
expect(subject.second[:value]).to eq(2)
end
end
end end
context 'with other projects' do context 'with other projects' do
...@@ -84,5 +110,6 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do ...@@ -84,5 +110,6 @@ describe Gitlab::CycleAnalytics::GroupStageSummary do
expect(subject.second[:value]).to eq(0) expect(subject.second[:value]).to eq(0)
end end
end end
end end
end end
...@@ -71,6 +71,29 @@ describe Gitlab::CycleAnalytics::IssueStage do ...@@ -71,6 +71,29 @@ describe Gitlab::CycleAnalytics::IssueStage do
end end
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
it 'exposes merge requests that close issues' do
result = stage.events
expect(result.count).to eq(1)
expect(result.map { |event| event[:title] }).to contain_exactly(issue_2_1.title)
end
end
end
context 'when subgroup is given' do context 'when subgroup is given' do
let(:subgroup) { create(:group, parent: group) } let(:subgroup) { create(:group, parent: group) }
let(:project_4) { create(:project, group: subgroup) } 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