Skip to content
Snippets Groups Projects
Commit 2c2dd5e3 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 2ff184ad
No related branches found
No related tags found
No related merge requests found
Showing
with 303 additions and 27 deletions
Loading
Loading
@@ -92,6 +92,15 @@ module API
 
present paginate(groups), options
end
def delete_group(group)
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/46285')
destroy_conditionally!(group) do |group|
::Groups::DestroyService.new(group, current_user).async_execute
end
accepted!
end
end
 
resource :groups do
Loading
Loading
@@ -187,12 +196,7 @@ module API
group = find_group!(params[:id])
authorize! :admin_group, group
 
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/46285')
destroy_conditionally!(group) do |group|
::Groups::DestroyService.new(group, current_user).async_execute
end
accepted!
delete_group(group)
end
 
desc 'Get a list of projects in this group.' do
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@ module Gitlab
 
def self.with_context(args, &block)
application_context = new(**args)
Labkit::Context.with_context(application_context.to_lazy_hash, &block)
application_context.use(&block)
end
 
def self.push(args)
Loading
Loading
@@ -42,6 +42,10 @@ module Gitlab
end
end
 
def use
Labkit::Context.with_context(to_lazy_hash) { yield }
end
private
 
attr_reader :set_values
Loading
Loading
Loading
Loading
@@ -18,6 +18,7 @@ module Gitlab
chain.add Labkit::Middleware::Sidekiq::Server
chain.add Gitlab::SidekiqMiddleware::InstrumentationLogger
chain.add Gitlab::SidekiqStatus::ServerMiddleware
chain.add Gitlab::SidekiqMiddleware::WorkerContext::Server
end
end
 
Loading
Loading
# frozen_string_literal: true
module Gitlab
module SidekiqMiddleware
module WorkerContext
class Server
def call(worker, job, _queue, &block)
worker_class = worker.class
# This is not a worker we know about, perhaps from a gem
return yield unless worker_class.respond_to?(:get_worker_context)
# Use the context defined on the class level as a base context
wrap_in_optional_context(worker_class.get_worker_context, &block)
end
private
def wrap_in_optional_context(context, &block)
return yield unless context
context.use(&block)
end
end
end
end
end
Loading
Loading
@@ -3014,6 +3014,9 @@ msgstr ""
msgid "CI / CD"
msgstr ""
 
msgid "CI / CD Analytics"
msgstr ""
msgid "CI / CD Charts"
msgstr ""
 
Loading
Loading
@@ -14310,9 +14313,6 @@ msgstr ""
msgid "Project '%{project_name}' will be deleted on %{date}"
msgstr ""
 
msgid "Project Analytics"
msgstr ""
msgid "Project Badges"
msgstr ""
 
Loading
Loading
@@ -15769,6 +15769,9 @@ msgstr ""
msgid "Repository"
msgstr ""
 
msgid "Repository Analytics"
msgstr ""
msgid "Repository Graph"
msgstr ""
 
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@
require 'spec_helper'
 
describe Admin::RunnersController do
let!(:runner) { create(:ci_runner) }
let_it_be(:runner) { create(:ci_runner) }
 
before do
sign_in(create(:admin))
Loading
Loading
@@ -36,6 +36,16 @@ describe Admin::RunnersController do
end
 
describe '#show' do
render_views
let_it_be(:project) { create(:project) }
let_it_be(:project_two) { create(:project) }
before_all do
create(:ci_build, runner: runner, project: project)
create(:ci_build, runner: runner, project: project_two)
end
it 'shows a particular runner' do
get :show, params: { id: runner.id }
 
Loading
Loading
@@ -47,6 +57,21 @@ describe Admin::RunnersController do
 
expect(response).to have_gitlab_http_status(404)
end
it 'avoids N+1 queries', :request_store do
get :show, params: { id: runner.id }
control_count = ActiveRecord::QueryRecorder.new { get :show, params: { id: runner.id } }.count
new_project = create(:project)
create(:ci_build, runner: runner, project: new_project)
# There is one additional query looking up subject.group in ProjectPolicy for the
# needs_new_sso_session permission
expect { get :show, params: { id: runner.id } }.not_to exceed_query_limit(control_count + 1)
expect(response).to have_gitlab_http_status(200)
end
end
 
describe '#update' do
Loading
Loading
Loading
Loading
@@ -7,6 +7,8 @@ describe 'Project active tab' do
let(:project) { create(:project, :repository) }
 
before do
stub_feature_flags(analytics_pages_under_project_analytics_sidebar: { enabled: false, thing: project })
project.add_maintainer(user)
sign_in(user)
end
Loading
Loading
@@ -17,21 +19,6 @@ describe 'Project active tab' do
end
end
 
shared_examples 'page has active tab' do |title|
it "activates #{title} tab" do
expect(page).to have_selector('.sidebar-top-level-items > li.active', count: 1)
expect(find('.sidebar-top-level-items > li.active')).to have_content(title)
end
end
shared_examples 'page has active sub tab' do |title|
it "activates #{title} sub tab" do
expect(page).to have_selector('.sidebar-sub-level-items > li.active:not(.fly-out-top-item)', count: 1)
expect(find('.sidebar-sub-level-items > li.active:not(.fly-out-top-item)'))
.to have_content(title)
end
end
context 'on project Home' do
before do
visit project_path(project)
Loading
Loading
@@ -136,4 +123,35 @@ describe 'Project active tab' do
it_behaves_like 'page has active sub tab', 'Repository'
end
end
context 'when `analytics_pages_under_project_analytics_sidebar` feature flag is enabled' do
before do
stub_feature_flags(analytics_pages_under_project_analytics_sidebar: { enabled: true, thing: project })
end
context 'on project Analytics' do
before do
visit charts_project_graph_path(project, 'master')
end
context 'on project Analytics/Repository Analytics' do
it_behaves_like 'page has active tab', _('Analytics')
it_behaves_like 'page has active sub tab', _('Repository Analytics')
end
context 'on project Analytics/Repository Analytics' do
it_behaves_like 'page has active tab', _('Analytics')
it_behaves_like 'page has active sub tab', _('Repository Analytics')
end
context 'on project Analytics/Cycle Analytics' do
before do
click_tab(_('CI / CD Analytics'))
end
it_behaves_like 'page has active tab', _('Analytics')
it_behaves_like 'page has active sub tab', _('CI / CD Analytics')
end
end
end
end
Loading
Loading
@@ -7,6 +7,8 @@ describe 'User uses shortcuts', :js do
let(:user) { create(:user) }
 
before do
stub_feature_flags(analytics_pages_under_project_analytics_sidebar: { enabled: false, thing: project })
project.add_maintainer(user)
sign_in(user)
 
Loading
Loading
@@ -156,4 +158,18 @@ describe 'User uses shortcuts', :js do
expect(page).to have_active_navigation('Wiki')
end
end
context 'when `analytics_pages_under_project_analytics_sidebar` feature flag is enabled' do
before do
stub_feature_flags(analytics_pages_under_project_analytics_sidebar: { enabled: true, thing: project })
end
it 'redirects to the repository charts page' do
find('body').native.send_key('g')
find('body').native.send_key('d')
expect(page).to have_active_navigation(_('Analytics'))
expect(page).to have_active_sub_navigation(_('Repository Analytics'))
end
end
end
Loading
Loading
@@ -79,4 +79,18 @@ describe Gitlab::ApplicationContext do
.to include(project: project.full_path, root_namespace: project.full_path_components.first)
end
end
describe '#use' do
let(:context) { described_class.new(user: build(:user)) }
it 'yields control' do
expect { |b| context.use(&b) }.to yield_control
end
it 'passes the expected context on to labkit' do
expect(Labkit::Context).to receive(:with_context).with(a_hash_including(user: duck_type(:call)))
context.use {}
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::SidekiqMiddleware::WorkerContext::Server do
let(:worker_class) do
Class.new do
def self.name
"TestWorker"
end
# To keep track of the context that was active for certain arguments
cattr_accessor(:contexts) { {} }
include ApplicationWorker
worker_context user: nil
def perform(identifier, *args)
self.class.contexts.merge!(identifier => Labkit::Context.current.to_h)
end
end
end
let(:other_worker) do
Class.new do
def self.name
"OtherWorker"
end
include Sidekiq::Worker
def perform
end
end
end
before do
stub_const("TestWorker", worker_class)
stub_const("OtherWorker", other_worker)
end
around do |example|
Sidekiq::Testing.inline! { example.run }
end
before(:context) do
Sidekiq::Testing.server_middleware do |chain|
chain.add described_class
end
end
after(:context) do
Sidekiq::Testing.server_middleware do |chain|
chain.remove described_class
end
end
describe "#call" do
it 'applies a class context' do
Gitlab::ApplicationContext.with_context(user: build_stubbed(:user)) do
TestWorker.perform_async("identifier", 1)
end
expect(TestWorker.contexts['identifier'].keys).not_to include('meta.user')
end
it "doesn't fail for unknown workers" do
expect { OtherWorker.perform_async }.not_to raise_error
end
end
end
Loading
Loading
@@ -44,7 +44,8 @@ describe Gitlab::SidekiqMiddleware do
Gitlab::SidekiqMiddleware::ServerMetrics,
Gitlab::SidekiqMiddleware::ArgumentsLogger,
Gitlab::SidekiqMiddleware::MemoryKiller,
Gitlab::SidekiqMiddleware::RequestStoreMiddleware
Gitlab::SidekiqMiddleware::RequestStoreMiddleware,
Gitlab::SidekiqMiddleware::WorkerContext::Server
]
end
let(:enabled_sidekiq_middlewares) { all_sidekiq_middlewares - disabled_sidekiq_middlewares }
Loading
Loading
Loading
Loading
@@ -63,6 +63,16 @@ describe SystemNoteService do
end
end
 
describe '.close_after_error_tracking_resolve' do
it 'calls IssuableService' do
expect_next_instance_of(::SystemNotes::IssuablesService) do |service|
expect(service).to receive(:close_after_error_tracking_resolve)
end
described_class.close_after_error_tracking_resolve(noteable, project, author)
end
end
describe '.change_milestone' do
let(:milestone) { double }
 
Loading
Loading
Loading
Loading
@@ -630,4 +630,17 @@ describe ::SystemNotes::IssuablesService do
end
end
end
describe '#close_after_error_tracking_resolve' do
subject { service.close_after_error_tracking_resolve }
it_behaves_like 'a system note' do
let(:action) { 'closed' }
end
it 'creates the expected system note' do
expect(subject.note)
.to eq('resolved the corresponding error and closed the issue.')
end
end
end
Loading
Loading
@@ -9,3 +9,18 @@ RSpec.shared_examples 'has nav sidebar' do
expect(rendered).not_to have_selector('.sidebar-expanded-mobile')
end
end
RSpec.shared_examples 'page has active tab' do |title|
it "activates #{title} tab" do
expect(page).to have_selector('.sidebar-top-level-items > li.active', count: 1)
expect(find('.sidebar-top-level-items > li.active')).to have_content(title)
end
end
RSpec.shared_examples 'page has active sub tab' do |title|
it "activates #{title} sub tab" do
expect(page).to have_selector('.sidebar-sub-level-items > li.active:not(.fly-out-top-item)', count: 1)
expect(find('.sidebar-sub-level-items > li.active:not(.fly-out-top-item)'))
.to have_content(title)
end
end
Loading
Loading
@@ -21,4 +21,12 @@ describe CronjobQueue do
it 'disables retrying of failed jobs' do
expect(worker.sidekiq_options['retry']).to eq(false)
end
it 'automatically clears project, user and namespace from the context', :aggregate_failues do
worker_context = worker.get_worker_context.to_lazy_hash.transform_values(&:call)
expect(worker_context[:user]).to be_nil
expect(worker_context[:root_namespace]).to be_nil
expect(worker_context[:project]).to be_nil
end
end
# frozen_string_literal: true
require 'spec_helper'
describe WorkerContext do
let(:worker) do
Class.new do
include WorkerContext
end
end
describe '.worker_context' do
it 'allows modifying the context for the entire worker' do
worker.worker_context(user: build_stubbed(:user))
expect(worker.get_worker_context).to be_a(Gitlab::ApplicationContext)
end
it 'allows fetches the context from a superclass if none was defined' do
worker.worker_context(user: build_stubbed(:user))
subclass = Class.new(worker)
expect(subclass.get_worker_context).to eq(worker.get_worker_context)
end
end
describe '#with_context' do
it 'allows modifying context when the job is running' do
worker.new.with_context(user: build_stubbed(:user, username: 'jane-doe')) do
expect(Labkit::Context.current.to_h).to include('meta.user' => 'jane-doe')
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment