Commit 9de87b0e authored by Albert Salim's avatar Albert Salim

Merge branch 'test-danger-bot' into 'master'

Callout message to finish global rollout before releasing the feature with feature flag

See merge request gitlab-org/gitlab!64680
parents badf7c34 2461ef1f
......@@ -41,6 +41,19 @@ def message_for_feature_flag_missing_group!(feature_flag:, mr_group_label:)
end
end
def message_for_global_rollout(feature_flag)
return unless feature_flag.default_enabled == true
message = <<~SUGGEST_COMMENT
You're about to [release the feature with the feature flag](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/issue_templates/Feature%20Flag%20Roll%20Out.md#optional-release-the-feature-with-the-feature-flag).
This process can only be done **after** the [global rollout on production](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/issue_templates/Feature%20Flag%20Roll%20Out.md#global-rollout-on-production).
Please make sure in [the rollout issue](#{feature_flag.rollout_issue_url}) that the preliminary steps have already been done. Otherwise, changing the YAML definition might not have the desired effect.
SUGGEST_COMMENT
mr_line = feature_flag.raw.lines.find_index { |l| l.include?('default_enabled:') }
markdown(message, file: feature_flag.path, line: mr_line.succ)
end
def message_for_feature_flag_with_group!(feature_flag:, mr_group_label:)
return if feature_flag.group_match_mr_label?(mr_group_label)
......@@ -65,6 +78,10 @@ feature_flag.feature_flag_files(change_type: :added).each do |feature_flag|
check_feature_flag_yaml(feature_flag)
end
feature_flag.feature_flag_files(change_type: :modified).each do |feature_flag|
message_for_global_rollout(feature_flag)
end
if helper.security_mr? && feature_flag_file_added?
fail "Feature flags are discouraged from security merge requests. Read the [security documentation](https://gitlab.com/gitlab-org/release/docs/-/blob/master/general/security/utilities/feature_flags.md) for details."
end
......@@ -87,7 +87,11 @@ RSpec.describe Tooling::Danger::FeatureFlag do
let(:feature_flag_path) { 'config/feature_flags/development/entry.yml' }
let(:group) { 'group::source code' }
let(:raw_yaml) do
YAML.dump('group' => group)
YAML.dump(
'group' => group,
'default_enabled' => true,
'rollout_issue_url' => 'https://gitlab.com/gitlab-org/gitlab/-/issues/1'
)
end
subject(:found) { described_class.new(feature_flag_path) }
......@@ -109,6 +113,18 @@ RSpec.describe Tooling::Danger::FeatureFlag do
end
end
describe '#default_enabled' do
it 'returns the default_enabled found in the YAML' do
expect(found.default_enabled).to eq(true)
end
end
describe '#rollout_issue_url' do
it 'returns the rollout_issue_url found in the YAML' do
expect(found.rollout_issue_url).to eq('https://gitlab.com/gitlab-org/gitlab/-/issues/1')
end
end
describe '#group_match_mr_label?' do
subject(:result) { found.group_match_mr_label?(mr_group_label) }
......
......@@ -29,6 +29,14 @@ module Tooling
@group ||= yaml['group']
end
def default_enabled
@default_enabled ||= yaml['default_enabled']
end
def rollout_issue_url
@rollout_issue_url ||= yaml['rollout_issue_url']
end
def group_match_mr_label?(mr_group_label)
mr_group_label == group
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