debian-mirror-gitlab/app/models/onboarding/completion.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
1.7 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
2022-10-11 01:57:18 +05:30
module Onboarding
class Completion
2021-06-08 01:23:25 +05:30
include Gitlab::Utils::StrongMemoize
2022-08-13 15:12:31 +05:30
include Gitlab::Experiment::Dsl
2021-06-08 01:23:25 +05:30
ACTION_ISSUE_IDS = {
pipeline_created: 7,
trial_started: 2,
required_mr_approvals_enabled: 11,
code_owners_enabled: 10
}.freeze
2022-05-07 20:08:51 +05:30
ACTION_PATHS = [
:issue_created,
:git_write,
:merge_request_created,
2022-08-13 15:12:31 +05:30
:user_added
2022-05-07 20:08:51 +05:30
].freeze
2021-06-08 01:23:25 +05:30
2022-08-13 15:12:31 +05:30
def initialize(namespace, current_user = nil)
2021-06-08 01:23:25 +05:30
@namespace = namespace
2022-08-13 15:12:31 +05:30
@current_user = current_user
2021-06-08 01:23:25 +05:30
end
2022-10-11 01:57:18 +05:30
def percentage
2021-06-08 01:23:25 +05:30
return 0 unless onboarding_progress
attributes = onboarding_progress.attributes.symbolize_keys
total_actions = action_columns.count
completed_actions = action_columns.count { |column| attributes[column].present? }
2022-10-11 01:57:18 +05:30
(completed_actions.to_f / total_actions * 100).round
2021-06-08 01:23:25 +05:30
end
private
def onboarding_progress
strong_memoize(:onboarding_progress) do
2022-10-11 01:57:18 +05:30
::Onboarding::Progress.find_by(namespace: namespace)
2021-06-08 01:23:25 +05:30
end
end
def action_columns
strong_memoize(:action_columns) do
2022-10-11 01:57:18 +05:30
tracked_actions.map { |action_key| ::Onboarding::Progress.column_name(action_key) }
2021-06-08 01:23:25 +05:30
end
end
def tracked_actions
2022-08-13 15:12:31 +05:30
ACTION_ISSUE_IDS.keys + ACTION_PATHS + deploy_section_tracked_actions
2021-06-08 01:23:25 +05:30
end
2022-08-13 15:12:31 +05:30
def deploy_section_tracked_actions
2022-10-11 01:57:18 +05:30
experiment(
:security_actions_continuous_onboarding,
2022-08-13 15:12:31 +05:30
namespace: namespace,
user: current_user,
sticky_to: current_user
) do |e|
e.control { [:security_scan_enabled] }
e.candidate { [:license_scanning_run, :secure_dependency_scanning_run, :secure_dast_run] }
end.run
end
attr_reader :namespace, :current_user
2021-06-08 01:23:25 +05:30
end
end