Commit 33651e72 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by ayufanpl

Account shared runner minutes to top-level namespace

parent 497a2070
......@@ -500,6 +500,10 @@ class Project < ActiveRecord::Base
.base_and_ancestors(upto: top)
end
def top_level_ancestor
@top_level_ancestor ||= ancestors_upto.last
end
def lfs_enabled?
return namespace.lfs_enabled? if self[:lfs_enabled].nil?
......
- if project.namespace.shared_runners_minutes_used?
- quota_used = project.namespace.shared_runners_minutes
- quota_limit = project.namespace.actual_shared_runners_minutes_limit
- if project.shared_runners_limit_namespace.shared_runners_minutes_used?
- quota_used = project.shared_runners_limit_namespace.shared_runners_minutes
- quota_limit = project.shared_runners_limit_namespace.actual_shared_runners_minutes_limit
.bs-callout.bs-callout-warning
%p
You have used all your shared Runners pipeline minutes.
......
- project = local_assigns.fetch(:project, nil)
- namespace = local_assigns.fetch(:namespace, project && project.namespace)
- namespace = local_assigns.fetch(:namespace, project && project.shared_runners_limit_namespace)
- scope = (project || namespace).full_path
- has_limit = (project || namespace).shared_runners_minutes_limit_enabled?
- can_see_status = project.nil? || can?(current_user, :create_pipeline, project)
......
---
title: Account shared runner minutes to top-level namespace
merge_request:
author:
type: fixed
......@@ -4,6 +4,16 @@ class Groups::PipelineQuotaController < Groups::ApplicationController
layout 'group_settings'
def index
@projects = @group.projects.with_shared_runners_limit_enabled.page(params[:page])
@projects = all_projects.with_shared_runners_limit_enabled.page(params[:page])
end
private
def all_projects
if Feature.enabled?(:account_on_namespace)
@group.all_projects
else
@group.projects
end
end
end
......@@ -54,7 +54,7 @@ module EE
to: :statistics, allow_nil: true
delegate :actual_shared_runners_minutes_limit,
:shared_runners_minutes_used?, to: :namespace
:shared_runners_minutes_used?, to: :shared_runners_limit_namespace
validates :repository_size_limit,
numericality: { only_integer: true, greater_than_or_equal_to: 0, allow_nil: true }
......@@ -82,6 +82,14 @@ module EE
end
end
def shared_runners_limit_namespace
if Feature.enabled?(:account_on_namespace)
top_level_ancestor
else
namespace
end
end
def mirror
super && feature_available?(:repository_mirrors)
end
......@@ -190,11 +198,12 @@ module EE
end
def shared_runners_available?
super && !namespace.shared_runners_minutes_used?
super && !shared_runners_limit_namespace.shared_runners_minutes_used?
end
def shared_runners_minutes_limit_enabled?
!public? && shared_runners_enabled? && namespace.shared_runners_minutes_limit_enabled?
!public? && shared_runners_enabled? &&
shared_runners_limit_namespace.shared_runners_minutes_limit_enabled?
end
def feature_available?(feature, user = nil)
......
......@@ -17,8 +17,7 @@ module EE
end
def builds_check_limit
::Namespace.reorder(nil)
.where('namespaces.id = projects.namespace_id')
all_namespaces
.joins('LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id')
.where('COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) = 0 OR ' \
'COALESCE(namespace_statistics.shared_runners_seconds, 0) < COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) * 60',
......@@ -26,6 +25,16 @@ module EE
.select('1')
end
def all_namespaces
if Feature.enabled?(:account_on_namespace)
::Gitlab::GroupHierarchy.new(::Namespace.where('namespaces.id = projects.namespace_id'))
.roots
else
::Namespace.reorder(nil)
.where('namespaces.id = projects.namespace_id')
end
end
def application_shared_runners_minutes
current_application_settings.shared_runners_minutes
end
......
......@@ -22,6 +22,10 @@ class UpdateBuildMinutesService < BaseService
end
def namespace
if Feature.enabled(:account_on_top_level)
project.namespace.top_level_parent
else
project.namespace
end
end
end
......@@ -33,6 +33,10 @@ module Gitlab
base_and_ancestors(upto: upto).where.not(id: ancestors_base.select(:id))
end
def roots
base_and_ancestors.where(namespaces: { parent_id: nil })
end
# Returns a relation that includes the ancestors_base set of groups
# and all their ancestors (recursively).
#
......
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