Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2024-11-10 18:24:01 +00:00
parent c6ba88c778
commit ac1d884532
26 changed files with 94 additions and 68 deletions

View File

@ -62,21 +62,6 @@ Layout/LineLength:
- 'app/finders/projects/members/effective_access_level_finder.rb'
- 'app/finders/releases/group_releases_finder.rb'
- 'app/finders/security/security_jobs_finder.rb'
- 'app/finders/todos_finder.rb'
- 'app/finders/user_group_notification_settings_finder.rb'
- 'app/graphql/batch_loaders/merge_request_diff_summary_batch_loader.rb'
- 'app/graphql/mutations/alert_management/http_integration/create.rb'
- 'app/graphql/mutations/alert_management/http_integration/http_integration_base.rb'
- 'app/graphql/mutations/alert_management/http_integration/update.rb'
- 'app/graphql/mutations/customer_relations/contacts/create.rb'
- 'app/graphql/mutations/customer_relations/contacts/update.rb'
- 'app/graphql/mutations/customer_relations/organizations/create.rb'
- 'app/graphql/mutations/customer_relations/organizations/update.rb'
- 'app/graphql/mutations/environments/canary_ingress/update.rb'
- 'app/graphql/mutations/issues/move.rb'
- 'app/graphql/mutations/issues/set_confidential.rb'
- 'app/graphql/mutations/issues/set_crm_contacts.rb'
- 'app/graphql/mutations/issues/set_locked.rb'
- 'app/graphql/mutations/todos/mark_all_done.rb'
- 'app/graphql/resolvers/container_repository_tags_resolver.rb'
- 'app/graphql/resolvers/project_merge_requests_resolver.rb'

View File

@ -16,12 +16,3 @@ Performance/FlatMap:
- 'lib/gitlab/testing/request_inspector_middleware.rb'
- 'lib/gitlab/usage_data_counters/hll_redis_counter.rb'
- 'qa/qa/tools/ci/non_empty_suites.rb'
- 'spec/controllers/projects/issues_controller_spec.rb'
- 'spec/lib/bulk_imports/groups/stage_spec.rb'
- 'spec/lib/bulk_imports/projects/stage_spec.rb'
- 'spec/lib/gitlab/ci/parsers/test/junit_spec.rb'
- 'spec/requests/api/graphql/ci/pipelines_spec.rb'
- 'spec/services/ci/create_pipeline_service/evaluate_runner_tags_spec.rb'
- 'spec/services/git/process_ref_changes_service_spec.rb'
- 'spec/support/shared_examples/models/with_debian_distributions_shared_examples.rb'
- 'spec/support/shared_examples/requests/api/graphql/issue_list_shared_examples.rb'

View File

@ -24,7 +24,9 @@ class TodosFinder
NONE = '0'
TODO_TYPES = Set.new(%w[Commit Issue WorkItem MergeRequest DesignManagement::Design AlertManagement::Alert Namespace Project Key]).freeze
TODO_TYPES = Set.new(
%w[Commit Issue WorkItem MergeRequest DesignManagement::Design AlertManagement::Alert Namespace Project Key]
).freeze
attr_accessor :current_user, :params
@ -134,7 +136,9 @@ class TodosFinder
end
def invalid_type_message
_("Unsupported todo type passed. Supported todo types are: %{todo_types}") % { todo_types: self.class.todo_types.to_a.join(', ') }
_("Unsupported todo type passed. Supported todo types are: %{todo_types}") % {
todo_types: self.class.todo_types.to_a.join(', ')
}
end
def sort(items)

View File

@ -9,7 +9,8 @@ class UserGroupNotificationSettingsFinder
def execute
groups_with_ancestors = groups.self_and_ancestors
@loaded_groups_with_ancestors = groups_with_ancestors.index_by(&:id)
@loaded_notification_settings = user.notification_settings_for_groups(groups_with_ancestors).preload_source_route.index_by(&:source_id)
@loaded_notification_settings = user.notification_settings_for_groups(groups_with_ancestors)
.preload_source_route.index_by(&:source_id)
preload_emails_enabled

View File

@ -12,12 +12,22 @@ module BatchLoaders
metrics = merge_request.metrics
summary = if metrics && metrics.added_lines && metrics.removed_lines
{ additions: metrics.added_lines, deletions: metrics.removed_lines, file_count: merge_request.merge_request_diff&.files_count || 0 }
{
additions: metrics.added_lines,
deletions: metrics.removed_lines,
file_count: merge_request.merge_request_diff&.files_count || 0
}
elsif merge_request.diff_stats.blank?
NIL_STATS
else
merge_request.diff_stats.each_with_object(NIL_STATS.dup) do |status, summary|
summary.merge!(additions: status.additions, deletions: status.deletions, file_count: 1) { |_, x, y| x + y }
summary.merge!(
additions: status.additions,
deletions: status.deletions,
file_count: 1
) do |_, x, y|
x + y
end
end
end

View File

@ -34,4 +34,4 @@ module Mutations
end
end
Mutations::AlertManagement::HttpIntegration::Create.prepend_mod_with('Mutations::AlertManagement::HttpIntegration::Create')
Mutations::AlertManagement::HttpIntegration::Create.prepend_mod

View File

@ -29,4 +29,4 @@ module Mutations
end
end
Mutations::AlertManagement::HttpIntegration::HttpIntegrationBase.prepend_mod_with('Mutations::AlertManagement::HttpIntegration::HttpIntegrationBase')
Mutations::AlertManagement::HttpIntegration::HttpIntegrationBase.prepend_mod

View File

@ -32,4 +32,4 @@ module Mutations
end
end
Mutations::AlertManagement::HttpIntegration::Update.prepend_mod_with('Mutations::AlertManagement::HttpIntegration::Update')
Mutations::AlertManagement::HttpIntegration::Update.prepend_mod

View File

@ -40,7 +40,11 @@ module Mutations
group = authorized_find!(id: args[:group_id])
set_organization!(args)
result = ::CustomerRelations::Contacts::CreateService.new(group: group, current_user: current_user, params: args).execute
result = ::CustomerRelations::Contacts::CreateService.new(
group: group,
current_user: current_user,
params: args
).execute
{ contact: result.payload, errors: result.errors }
end
end

View File

@ -39,14 +39,21 @@ module Mutations
description: 'State of the contact.'
def resolve(args)
contact = ::Gitlab::Graphql::Lazy.force(GitlabSchema.object_from_id(args.delete(:id), expected_type: ::CustomerRelations::Contact))
contact = ::Gitlab::Graphql::Lazy.force(GitlabSchema.object_from_id(
args.delete(:id),
expected_type: ::CustomerRelations::Contact)
)
raise_resource_not_available_error! unless contact
group = contact.group
authorize!(group)
set_organization!(args)
result = ::CustomerRelations::Contacts::UpdateService.new(group: group, current_user: current_user, params: args).execute(contact)
result = ::CustomerRelations::Contacts::UpdateService.new(
group: group,
current_user: current_user,
params: args
).execute(contact)
{ contact: result.payload, errors: result.errors }
end
end

View File

@ -38,7 +38,11 @@ module Mutations
def resolve(args)
group = authorized_find!(id: args[:group_id])
result = ::CustomerRelations::Organizations::CreateService.new(group: group, current_user: current_user, params: args).execute
result = ::CustomerRelations::Organizations::CreateService.new(
group: group,
current_user: current_user,
params: args
).execute
{ organization: result.payload, errors: result.errors }
end
end

View File

@ -39,13 +39,20 @@ module Mutations
description: 'State of the organization.'
def resolve(args)
organization = ::Gitlab::Graphql::Lazy.force(GitlabSchema.object_from_id(args.delete(:id), expected_type: ::CustomerRelations::Organization))
organization = ::Gitlab::Graphql::Lazy.force(
GitlabSchema.object_from_id(args.delete(:id),
expected_type: ::CustomerRelations::Organization)
)
raise_resource_not_available_error! unless organization
group = organization.group
authorize!(group)
result = ::CustomerRelations::Organizations::UpdateService.new(group: group, current_user: current_user, params: args).execute(organization)
result = ::CustomerRelations::Organizations::UpdateService.new(
group: group,
current_user: current_user,
params: args
).execute(organization)
{ organization: result.payload, errors: result.errors }
end
end

View File

@ -5,7 +5,8 @@ module Mutations
module CanaryIngress
class Update < ::Mutations::BaseMutation
graphql_name 'EnvironmentsCanaryIngressUpdate'
description '**Deprecated** This endpoint is planned to be removed along with certificate-based clusters. [See this epic](https://gitlab.com/groups/gitlab-org/configure/-/epics/8) for more information.'
description '**Deprecated** This endpoint is planned to be removed along with certificate-based clusters. ' \
'[See this epic](https://gitlab.com/groups/gitlab-org/configure/-/epics/8) for more information.'
authorize :update_environment

View File

@ -18,7 +18,8 @@ module Mutations
target_project = resolve_project(full_path: target_project_path).sync
begin
moved_issue = ::Issues::MoveService.new(container: source_project, current_user: current_user).execute(issue, target_project)
moved_issue = ::Issues::MoveService.new(container: source_project, current_user: current_user)
.execute(issue, target_project)
rescue ::Issues::MoveService::MoveError => e
errors = e.message
end

View File

@ -16,8 +16,12 @@ module Mutations
issue = authorized_find!(project_path: project_path, iid: iid)
project = issue.project
# Changing confidentiality affects spam checking rules, therefore we need to perform a spam check
::Issues::UpdateService.new(container: project, current_user: current_user, params: { confidential: confidential }, perform_spam_check: true)
.execute(issue)
::Issues::UpdateService.new(
container: project,
current_user: current_user,
params: { confidential: confidential },
perform_spam_check: true
).execute(issue)
check_spam_action_response!(issue)
{

View File

@ -38,8 +38,11 @@ module Mutations
:replace_ids
end
response = ::Issues::SetCrmContactsService.new(container: project, current_user: current_user, params: { attribute_name => contact_ids })
.execute(issue)
response = ::Issues::SetCrmContactsService.new(
container: project,
current_user: current_user,
params: { attribute_name => contact_ids }
).execute(issue)
{
issue: issue,

View File

@ -13,8 +13,11 @@ module Mutations
def resolve(project_path:, iid:, locked:)
issue = authorized_find!(project_path: project_path, iid: iid)
::Issues::UpdateService.new(container: issue.project, current_user: current_user, params: { discussion_locked: locked })
.execute(issue)
::Issues::UpdateService.new(
container: issue.project,
current_user: current_user,
params: { discussion_locked: locked }
).execute(issue)
{
issue: issue,

View File

@ -1902,8 +1902,9 @@ RSpec.describe Projects::IssuesController, :request_store, feature_category: :te
context 'user is a guest' do
let(:json_response_note_ids) do
json_response.collect { |discussion| discussion["notes"] }.flatten
.collect { |note| note["id"].to_i }
json_response
.flat_map { |discussion| discussion["notes"] }
.map { |note| note["id"].to_i }
end
before do

View File

@ -34,7 +34,7 @@ RSpec.describe BulkImports::Groups::Stage, feature_category: :importers do
end
it 'only has pipelines with valid keys' do
pipeline_keys = described_class.new(entity).pipelines.collect(&:keys).flatten.uniq
pipeline_keys = described_class.new(entity).pipelines.flat_map(&:keys).uniq
allowed_keys = %i[pipeline stage minimum_source_version maximum_source_version]
expect(pipeline_keys - allowed_keys).to be_empty

View File

@ -20,7 +20,7 @@ RSpec.describe BulkImports::Projects::Stage, feature_category: :importers do
end
it 'only have pipelines with valid keys' do
pipeline_keys = subject.pipelines.collect(&:keys).flatten.uniq
pipeline_keys = subject.pipelines.flat_map(&:keys).uniq
allowed_keys = %i[pipeline stage minimum_source_version maximum_source_version]
expect(pipeline_keys - allowed_keys).to be_empty

View File

@ -546,11 +546,11 @@ RSpec.describe Gitlab::Ci::Parsers::Test::Junit do
private
def flattened_test_cases(test_suite)
test_suite.test_cases.map do |status, value|
value.map do |key, test_case|
test_suite.test_cases.flat_map do |status, value|
value.flat_map do |key, test_case|
test_case
end
end.flatten
end
end
end
end

View File

@ -383,10 +383,10 @@ RSpec.describe 'Query.project(fullPath).pipelines', feature_category: :continuou
pipelines_data = graphql_data.dig('project', 'pipelines', 'nodes')
job_names = pipelines_data.map do |pipeline_data|
job_names = pipelines_data.flat_map do |pipeline_data|
jobs_data = pipeline_data.dig('jobs', 'nodes')
jobs_data.map { |job_data| job_data['name'] }
end.flatten
end
expect(job_names).to contain_exactly('SAST Job 1')
end
@ -490,7 +490,7 @@ RSpec.describe 'Query.project(fullPath).pipelines', feature_category: :continuou
it_behaves_like 'a working graphql query'
it 'returns the downstream pipelines of a pipeline' do
downstream_pipelines_graphql_data = pipelines_graphql_data.map { |pip| pip['downstream']['nodes'] }.flatten
downstream_pipelines_graphql_data = pipelines_graphql_data.flat_map { |pip| pip['downstream']['nodes'] }
expect(
downstream_pipelines_graphql_data.map { |pip| pip['iid'].to_i }

View File

@ -121,7 +121,7 @@ RSpec.describe Ci::CreatePipelineService,
end
context 'with parallel:matrix config' do
let(:tags) { pipeline.builds.map(&:tags).flatten.pluck(:name) }
let(:tags) { pipeline.builds.flat_map(&:tags).pluck(:name) }
let(:config) do
<<~EOS

View File

@ -104,9 +104,9 @@ RSpec.describe Git::ProcessRefChangesService, feature_category: :source_code_man
{ oldrev: Gitlab::Git::SHA1_BLANK_SHA, newrev: '789012', ref: "#{ref_prefix}/create" },
{ oldrev: '123456', newrev: '789012', ref: "#{ref_prefix}/update" },
{ oldrev: '123456', newrev: Gitlab::Git::SHA1_BLANK_SHA, ref: "#{ref_prefix}/delete" }
].map do |change|
].flat_map do |change|
multiple_changes(change, push_event_activities_limit + 1)
end.flatten
end
end
before do

View File

@ -7,12 +7,12 @@ RSpec.shared_examples 'model with Debian distributions' do
let!(:component_files) { create_list("debian_#{container_type}_component_file", 3, component: components[0]) }
it 'removes distribution files on removal' do
distribution_file_paths = distributions.map do |distribution|
distribution_file_paths = distributions.flat_map do |distribution|
[distribution.file.path] +
distribution.component_files.map do |component_file|
distribution.component_files.flat_map do |component_file|
component_file.file.path
end
end.flatten
end
expect { subject.destroy! }
.to change {

View File

@ -719,13 +719,13 @@ RSpec.shared_examples 'graphql issue list request spec' do
end
def response_label_ids(response_data)
response_data.map do |node|
response_data.flat_map do |node|
node['labels']['nodes'].pluck('id')
end.flatten
end
end
def labels_as_global_ids(issues)
issues.map(&:labels).flatten.map(&:to_global_id).map(&:to_s)
issues.flat_map { |issue| issue.labels.map { |label| label.to_global_id.to_s } }
end
it 'avoids N+1 queries', :aggregate_failures do
@ -768,13 +768,13 @@ RSpec.shared_examples 'graphql issue list request spec' do
end
def response_assignee_ids(response_data)
response_data.map do |node|
response_data.flat_map do |node|
node['assignees']['nodes'].pluck('id')
end.flatten
end
end
def assignees_as_global_ids(issues)
issues.map(&:assignees).flatten.map(&:to_global_id).map(&:to_s)
issues.flat_map(&:assignees).map(&:to_global_id).map(&:to_s)
end
it 'avoids N+1 queries', :aggregate_failures do