diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-10 00:10:12 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-10 00:10:12 +0300 |
commit | dc22d7faa23a7988be2b70da2bfb956de4df00f0 (patch) | |
tree | cf79ae05494af210a53390fd8bd7ade54d54bad8 /app/models/onboarding | |
parent | 7c0e5472c80f1826b36916a95e6f9d84a7b68fe3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/onboarding')
-rw-r--r-- | app/models/onboarding/completion.rb | 70 | ||||
-rw-r--r-- | app/models/onboarding/learn_gitlab.rb | 38 |
2 files changed, 108 insertions, 0 deletions
diff --git a/app/models/onboarding/completion.rb b/app/models/onboarding/completion.rb new file mode 100644 index 00000000000..49fdb102209 --- /dev/null +++ b/app/models/onboarding/completion.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +module Onboarding + class Completion + include Gitlab::Utils::StrongMemoize + include Gitlab::Experiment::Dsl + + ACTION_ISSUE_IDS = { + pipeline_created: 7, + trial_started: 2, + required_mr_approvals_enabled: 11, + code_owners_enabled: 10 + }.freeze + + ACTION_PATHS = [ + :issue_created, + :git_write, + :merge_request_created, + :user_added + ].freeze + + def initialize(namespace, current_user = nil) + @namespace = namespace + @current_user = current_user + end + + def percentage + 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? } + + (completed_actions.to_f / total_actions * 100).round + end + + private + + def onboarding_progress + strong_memoize(:onboarding_progress) do + ::Onboarding::Progress.find_by(namespace: namespace) + end + end + + def action_columns + strong_memoize(:action_columns) do + tracked_actions.map { |action_key| ::Onboarding::Progress.column_name(action_key) } + end + end + + def tracked_actions + ACTION_ISSUE_IDS.keys + ACTION_PATHS + deploy_section_tracked_actions + end + + def deploy_section_tracked_actions + experiment( + :security_actions_continuous_onboarding, + 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 + end +end diff --git a/app/models/onboarding/learn_gitlab.rb b/app/models/onboarding/learn_gitlab.rb new file mode 100644 index 00000000000..d7a189ed6e2 --- /dev/null +++ b/app/models/onboarding/learn_gitlab.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Onboarding + class LearnGitlab + PROJECT_NAME = 'Learn GitLab' + PROJECT_NAME_ULTIMATE_TRIAL = 'Learn GitLab - Ultimate trial' + BOARD_NAME = 'GitLab onboarding' + LABEL_NAME = 'Novice' + + def initialize(current_user) + @current_user = current_user + end + + def available? + project && board && label + end + + def project + @project ||= current_user.projects.find_by_name([PROJECT_NAME, PROJECT_NAME_ULTIMATE_TRIAL]) + end + + def board + return unless project + + @board ||= project.boards.find_by_name(BOARD_NAME) + end + + def label + return unless project + + @label ||= project.labels.find_by_name(LABEL_NAME) + end + + private + + attr_reader :current_user + end +end |