Commit 90bcbb98 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents 965609e5 f1b4df8b
...@@ -87,13 +87,7 @@ class GroupDescendantsFinder ...@@ -87,13 +87,7 @@ class GroupDescendantsFinder
visible_to_user = visible_to_user.or(authorized_to_user) visible_to_user = visible_to_user.or(authorized_to_user)
end end
group_to_query = if Feature.enabled?(:linear_group_descendants_finder, current_user, default_enabled: :yaml) parent_group.descendants.where(visible_to_user)
parent_group
else
hierarchy_for_parent
end
group_to_query.descendants.where(visible_to_user)
# rubocop: enable CodeReuse/Finder # rubocop: enable CodeReuse/Finder
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -159,13 +153,7 @@ class GroupDescendantsFinder ...@@ -159,13 +153,7 @@ class GroupDescendantsFinder
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def projects_matching_filter def projects_matching_filter
# rubocop: disable CodeReuse/Finder # rubocop: disable CodeReuse/Finder
objects_in_hierarchy = if Feature.enabled?(:linear_group_descendants_finder, current_user, default_enabled: :yaml) projects_nested_in_group = Project.where(namespace_id: parent_group.self_and_descendants.as_ids)
parent_group.self_and_descendants.as_ids
else
hierarchy_for_parent.base_and_descendants.select(:id)
end
projects_nested_in_group = Project.where(namespace_id: objects_in_hierarchy)
params_with_search = params.merge(search: params[:filter]) params_with_search = params.merge(search: params[:filter])
ProjectsFinder.new(params: params_with_search, ProjectsFinder.new(params: params_with_search,
......
---
name: linear_group_descendants_finder
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68954
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/339440
milestone: '14.6'
type: development
group: group::access
default_enabled: false
...@@ -87,7 +87,8 @@ Commit message templates support these variables: ...@@ -87,7 +87,8 @@ Commit message templates support these variables:
| `%{merged_by}` | User who merged the merge request. | `Alex Garcia <agarcia@example.com>` | | `%{merged_by}` | User who merged the merge request. | `Alex Garcia <agarcia@example.com>` |
| `%{co_authored_by}` | Names and emails of commit authors in a `Co-authored-by` Git commit trailer format. Limited to authors of 100 most recent commits in merge request. | `Co-authored-by: Zane Doe <zdoe@example.com>` <br> `Co-authored-by: Blake Smith <bsmith@example.com>` | | `%{co_authored_by}` | Names and emails of commit authors in a `Co-authored-by` Git commit trailer format. Limited to authors of 100 most recent commits in merge request. | `Co-authored-by: Zane Doe <zdoe@example.com>` <br> `Co-authored-by: Blake Smith <bsmith@example.com>` |
Empty variables that are the only word in a line are removed, along with all newline characters preceding it. Any line containing only an empty variable is removed. If the line to be removed is both
preceded and followed by an empty line, the preceding empty line is also removed.
## Related topics ## Related topics
......
...@@ -65,9 +65,13 @@ module Gitlab ...@@ -65,9 +65,13 @@ module Gitlab
end end
names_of_empty_variables = values.filter_map { |name, value| name if value.blank? } names_of_empty_variables = values.filter_map { |name, value| name if value.blank? }
# Remove placeholders that correspond to empty values and are the only word in a line # Remove lines that contain empty variable placeholder and nothing else.
# along with all whitespace characters preceding them. if names_of_empty_variables.present?
message = message.gsub(/[\n\r]+#{Regexp.union(names_of_empty_variables)}$/, '') if names_of_empty_variables.present? # If there is blank line or EOF after it, remove blank line before it as well.
message = message.gsub(/\n\n#{Regexp.union(names_of_empty_variables)}(\n\n|\Z)/, '\1')
# Otherwise, remove only the line it is in.
message = message.gsub(/^#{Regexp.union(names_of_empty_variables)}\n/, '')
end
# Substitute all variables with their values. # Substitute all variables with their values.
message = message.gsub(Regexp.union(values.keys), values) if values.present? message = message.gsub(Regexp.union(values.keys), values) if values.present?
......
...@@ -17,7 +17,6 @@ RSpec.describe GroupDescendantsFinder do ...@@ -17,7 +17,6 @@ RSpec.describe GroupDescendantsFinder do
described_class.new(current_user: user, parent_group: group, params: params) described_class.new(current_user: user, parent_group: group, params: params)
end end
shared_examples 'group descentants finder examples' do
describe '#has_children?' do describe '#has_children?' do
it 'is true when there are projects' do it 'is true when there are projects' do
create(:project, namespace: group) create(:project, namespace: group)
...@@ -264,15 +263,4 @@ RSpec.describe GroupDescendantsFinder do ...@@ -264,15 +263,4 @@ RSpec.describe GroupDescendantsFinder do
end end
end end
end end
end
it_behaves_like 'group descentants finder examples'
context 'when feature flag :linear_group_descendants_finder is disabled' do
before do
stub_feature_flags(linear_group_descendants_finder: false)
end
it_behaves_like 'group descentants finder examples'
end
end end
...@@ -292,43 +292,82 @@ RSpec.describe Gitlab::MergeRequests::CommitMessageGenerator do ...@@ -292,43 +292,82 @@ RSpec.describe Gitlab::MergeRequests::CommitMessageGenerator do
context 'when project has merge commit template with approvers' do context 'when project has merge commit template with approvers' do
let(:user1) { create(:user) } let(:user1) { create(:user) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
let(message_template_name) do let(message_template_name) { <<~MSG.rstrip }
"Merge Request approved by:\n%{approved_by}" Merge branch '%{source_branch}' into '%{target_branch}'
end
%{approved_by}
MSG
context "and mr has no approval" do context 'and mr has no approval' do
before do before do
merge_request.approved_by_users = [] merge_request.approved_by_users = []
end end
it "returns empty string" do it 'removes variable and blank line' do
expect(result_message).to eq <<~MSG.rstrip expect(result_message).to eq <<~MSG.rstrip
Merge Request approved by: Merge branch 'feature' into 'master'
MSG
end
context 'when there is blank line after approved_by' do
let(message_template_name) { <<~MSG.rstrip }
Merge branch '%{source_branch}' into '%{target_branch}'
%{approved_by}
Type: merge
MSG
it 'removes blank line before it' do
expect(result_message).to eq <<~MSG.rstrip
Merge branch 'feature' into 'master'
Type: merge
MSG MSG
end end
end end
context "and mr has one approval" do context 'when there is no blank line after approved_by' do
let(message_template_name) { <<~MSG.rstrip }
Merge branch '%{source_branch}' into '%{target_branch}'
%{approved_by}
Type: merge
MSG
it 'does not remove blank line before it' do
expect(result_message).to eq <<~MSG.rstrip
Merge branch 'feature' into 'master'
Type: merge
MSG
end
end
end
context 'and mr has one approval' do
before do before do
merge_request.approved_by_users = [user1] merge_request.approved_by_users = [user1]
end end
it "returns user name and email" do it 'returns user name and email' do
expect(result_message).to eq <<~MSG.rstrip expect(result_message).to eq <<~MSG.rstrip
Merge Request approved by: Merge branch 'feature' into 'master'
Approved-by: #{user1.name} <#{user1.email}> Approved-by: #{user1.name} <#{user1.email}>
MSG MSG
end end
end end
context "and mr has multiple approvals" do context 'and mr has multiple approvals' do
before do before do
merge_request.approved_by_users = [user1, user2] merge_request.approved_by_users = [user1, user2]
end end
it "returns users names and emails" do it 'returns users names and emails' do
expect(result_message).to eq <<~MSG.rstrip expect(result_message).to eq <<~MSG.rstrip
Merge Request approved by: Merge branch 'feature' into 'master'
Approved-by: #{user1.name} <#{user1.email}> Approved-by: #{user1.name} <#{user1.email}>
Approved-by: #{user2.name} <#{user2.email}> Approved-by: #{user2.name} <#{user2.email}>
MSG MSG
......
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