Commit cd286e9d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'pipelines-quota-for-user-profile' into 'master'

Pipelines quota for user profile

Closes gitlab-ce#30228

See merge request !1536
parents c75bf8af ebf23cfd
......@@ -117,6 +117,14 @@
}
}
.user-settings-pipeline-quota {
margin-top: $gl-padding;
.pipeline-quota {
border-top: none;
}
}
table.pipeline-project-metrics tr td {
padding: $gl-padding;
}
......
class Profiles::PipelineQuotaController < Profiles::ApplicationController
def index
@namespace = current_user.namespace
@projects = @namespace.projects.with_shared_runners_limit_enabled.page(params[:page])
end
end
module EE
module GroupsHelper
def group_shared_runner_limits_quota(group)
used = group.shared_runners_minutes.to_i
module NamespaceHelper
def namespace_shared_runner_limits_quota(namespace)
used = namespace.shared_runners_minutes.to_i
if group.shared_runners_minutes_limit_enabled?
limit = group.actual_shared_runners_minutes_limit
status = group.shared_runners_minutes_used? ? 'over_quota' : 'under_quota'
if namespace.shared_runners_minutes_limit_enabled?
limit = namespace.actual_shared_runners_minutes_limit
status = namespace.shared_runners_minutes_used? ? 'over_quota' : 'under_quota'
else
limit = 'Unlimited'
status = 'disabled'
......@@ -16,14 +16,14 @@ module EE
end
end
def group_shared_runner_limits_percent_used(group)
return 0 unless group.shared_runners_minutes_limit_enabled?
def namespace_shared_runner_limits_percent_used(namespace)
return 0 unless namespace.shared_runners_minutes_limit_enabled?
100 * group.shared_runners_minutes.to_i / group.actual_shared_runners_minutes_limit
100 * namespace.shared_runners_minutes.to_i / namespace.actual_shared_runners_minutes_limit
end
def group_shared_runner_limits_progress_bar(group)
percent = [group_shared_runner_limits_percent_used(group), 100].min
def namespace_shared_runner_limits_progress_bar(namespace)
percent = [namespace_shared_runner_limits_percent_used(namespace), 100].min
status =
if percent == 100
......
......@@ -9,44 +9,5 @@
%strong= @group.name
group
.pipeline-quota.container-fluid
.row
.col-sm-6
%strong
- last_reset = @group.shared_runners_seconds_last_reset
- if last_reset
Usage since
= last_reset.strftime('%b %d, %Y')
- else
Current period usage
%div
= group_shared_runner_limits_quota(@group)
minutes
.col-sm-6.right
- if @group.shared_runners_minutes_limit_enabled?
#{group_shared_runner_limits_percent_used(@group)}% used
- else
Unlimited
= group_shared_runner_limits_progress_bar(@group)
%table.table.pipeline-project-metrics
%thead
%tr
%th Project
%th Minutes
%tbody
- @projects.each do |project|
%tr
%td
.avatar-container.s20.hidden-xs
= project_icon(project, alt: '', class: 'avatar project-avatar s20')
%strong= link_to project.name, project
%td
= project.shared_runners_minutes
- if @projects.blank?
%tr
%td{ colspan: 2 }
.nothing-here-block This group has no projects which use shared runners
= paginate @projects, theme: "gitlab"
= render "namespaces/pipelines_quota/list",
locals: { namespace: @group, projects: @projects }
......@@ -51,3 +51,7 @@
= link_to audit_log_profile_path, title: 'Authentication log' do
%span
Authentication log
= nav_link(path: 'profiles#pipeline_quota') do
= link_to profile_pipeline_quota_path, title: 'Pipeline quota' do
%span
Pipeline quota
......@@ -3,5 +3,5 @@
%li
%span.light Pipeline minutes quota:
%strong
= group_shared_runner_limits_quota(namespace)
= namespace_shared_runner_limits_quota(namespace)
= link_to icon('question-circle'), help_page_path("user/admin_area/settings/continuous_integration", anchor: "shared-runners-build-minutes-quota"), target: '_blank'
- namespace = locals.fetch(:namespace)
- projects = locals.fetch(:projects)
.pipeline-quota.container-fluid
.row
.col-sm-6
%strong
- last_reset = namespace.shared_runners_seconds_last_reset
- if last_reset
Usage since
= last_reset.strftime('%b %d, %Y')
- else
Current period usage
%div
= namespace_shared_runner_limits_quota(namespace)
minutes
.col-sm-6.right
- if namespace.shared_runners_minutes_limit_enabled?
#{namespace_shared_runner_limits_percent_used(namespace)}% used
- else
Unlimited
= namespace_shared_runner_limits_progress_bar(namespace)
%table.table.pipeline-project-metrics
%thead
%tr
%th Project
%th Minutes
%tbody
- projects.each do |project|
%tr
%td
.avatar-container.s20.hidden-xs
= project_icon(project, alt: '', class: 'avatar project-avatar s20')
%strong= link_to project.name, project
%td
= project.shared_runners_minutes
- if projects.blank?
%tr
%td{ colspan: 2 }
.nothing-here-block This group has no projects which use shared runners
= paginate projects, theme: "gitlab"
- page_title 'Personal pipelines quota'
= render 'profiles/head'
.user-settings-pipeline-quota.row
.profile-settings-sidebar.col-lg-3
%h4
Personal pipelines quota
= link_to icon('question-circle'), help_page_path("user/admin_area/settings/continuous_integration", anchor: "shared-runners-build-minutes-quota"), target: '_blank'
%p.light
Monthly build minutes usage across shared Runners
.col-lg-9
= render "namespaces/pipelines_quota/list",
locals: { namespace: @namespace, projects: @projects }
---
title: Allow to view Personal pipelines quota
merge_request:
author:
......@@ -47,5 +47,9 @@ resource :profile, only: [:show, :update] do
end
resources :u2f_registrations, only: [:destroy]
## EE-specific
resources :pipeline_quota, only: [:index]
## EE-specific
end
end
......@@ -31,6 +31,7 @@ scope(constraints: { username: Gitlab::PathRegex.root_namespace_route_regex }) d
get :contributed, as: :contributed_projects
get :snippets
get :exists
get :pipelines_quota
get '/', to: redirect('/%{username}'), as: nil
end
......
require 'spec_helper'
feature 'Profile > Pipeline Quota', feature: true do
let(:user) { create(:user) }
let(:namespace) { create(:namespace, owner: user) }
let!(:project) { create(:empty_project, namespace: namespace, shared_runners_enabled: true) }
before do
login_with(user)
end
it 'is linked within the profile page' do
visit profile_path
page.within('.layout-nav') do
expect(page).to have_selector(:link_or_button, 'Pipeline quota')
end
end
context 'with no quota' do
let(:namespace) { create(:namespace, :with_build_minutes, owner: user) }
it 'shows correct group quota info' do
visit profile_pipeline_quota_path
page.within('.pipeline-quota') do
expect(page).to have_content("400 / Unlimited minutes")
expect(page).to have_selector('.progress-bar-success')
end
end
end
context 'with no projects using shared runners' do
let(:namespace) { create(:namespace, :with_not_used_build_minutes_limit, owner: user) }
let!(:project) { create(:empty_project, namespace: namespace, shared_runners_enabled: false) }
it 'shows correct group quota info' do
visit profile_pipeline_quota_path
page.within('.pipeline-quota') do
expect(page).to have_content("300 / Unlimited minutes")
expect(page).to have_selector('.progress-bar-success')
end
page.within('.pipeline-project-metrics') do
expect(page).to have_content('This group has no projects which use shared runners')
end
end
end
context 'minutes under quota' do
let(:namespace) { create(:namespace, :with_not_used_build_minutes_limit, owner: user) }
it 'shows correct group quota info' do
visit profile_pipeline_quota_path
page.within('.pipeline-quota') do
expect(page).to have_content("300 / 500 minutes")
expect(page).to have_content("60% used")
expect(page).to have_selector('.progress-bar-success')
end
end
end
context 'minutes over quota' do
let(:namespace) { create(:namespace, :with_used_build_minutes_limit, owner: user) }
let!(:other_project) { create(:empty_project, namespace: namespace, shared_runners_enabled: false) }
it 'shows correct group quota and projects info' do
visit profile_pipeline_quota_path
page.within('.pipeline-quota') do
expect(page).to have_content("1000 / 500 minutes")
expect(page).to have_content("200% used")
expect(page).to have_selector('.progress-bar-danger')
end
page.within('.pipeline-project-metrics') do
expect(page).to have_content(project.name)
expect(page).not_to have_content(other_project.name)
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