diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /lib/atlassian/jira_connect/serializers/feature_flag_entity.rb | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'lib/atlassian/jira_connect/serializers/feature_flag_entity.rb')
-rw-r--r-- | lib/atlassian/jira_connect/serializers/feature_flag_entity.rb | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/atlassian/jira_connect/serializers/feature_flag_entity.rb b/lib/atlassian/jira_connect/serializers/feature_flag_entity.rb new file mode 100644 index 00000000000..e17c150aacb --- /dev/null +++ b/lib/atlassian/jira_connect/serializers/feature_flag_entity.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +module Atlassian + module JiraConnect + module Serializers + class FeatureFlagEntity < Grape::Entity + include Gitlab::Routing + + alias_method :flag, :object + + format_with(:string, &:to_s) + + expose :schema_version, as: :schemaVersion + expose :id, format_with: :string + expose :name, as: :key + expose :update_sequence_id, as: :updateSequenceId + expose :name, as: :displayName + expose :summary + expose :details + expose :issue_keys, as: :issueKeys + + def issue_keys + @issue_keys ||= JiraIssueKeyExtractor.new(flag.description).issue_keys + end + + def schema_version + '1.0' + end + + def update_sequence_id + options[:update_sequence_id] || Client.generate_update_sequence_id + end + + STRATEGY_NAMES = { + ::Operations::FeatureFlags::Strategy::STRATEGY_DEFAULT => 'All users', + ::Operations::FeatureFlags::Strategy::STRATEGY_GITLABUSERLIST => 'User List', + ::Operations::FeatureFlags::Strategy::STRATEGY_GRADUALROLLOUTUSERID => 'Percent of users', + ::Operations::FeatureFlags::Strategy::STRATEGY_FLEXIBLEROLLOUT => 'Percent rollout', + ::Operations::FeatureFlags::Strategy::STRATEGY_USERWITHID => 'User IDs' + }.freeze + + private + + # The summary does not map very well to our FeatureFlag model. + # + # We allow feature flags to have multiple strategies, depending + # on the environment. Jira expects a single rollout strategy. + # + # Also, we don't actually support showing a single flag, so we use the + # edit path as an interim solution. + def summary(strategies = flag.strategies) + { + url: project_url(flag.project) + "/-/feature_flags/#{flag.id}/edit", + lastUpdated: flag.updated_at.iso8601, + status: { + enabled: flag.active, + defaultValue: '', + rollout: { + percentage: strategies.map do |s| + s.parameters['rollout'] || s.parameters['percentage'] + end.compact.first&.to_f, + text: strategies.map { |s| STRATEGY_NAMES[s.name] }.compact.join(', ') + }.compact + } + } + end + + def details + envs = flag.strategies.flat_map do |s| + s.scopes.map do |es| + env_type = es.environment_scope.scan(/development|testing|staging|production/).first + [es.environment_scope, env_type, s] + end + end + + envs.map do |env_name, env_type, strat| + summary([strat]).merge(environment: { name: env_name, type: env_type }.compact) + end + end + end + end + end +end |