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
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
ACTION_PATHS = [
|
2023-04-23 21:23:45 +05:30
|
|
|
:pipeline_created,
|
2023-05-27 22:25:52 +05:30
|
|
|
:trial_started,
|
|
|
|
:required_mr_approvals_enabled,
|
|
|
|
:code_owners_enabled,
|
2022-05-07 20:08:51 +05:30
|
|
|
:issue_created,
|
|
|
|
:git_write,
|
|
|
|
:merge_request_created,
|
2023-06-20 00:43:36 +05:30
|
|
|
:user_added,
|
|
|
|
:license_scanning_run,
|
|
|
|
:secure_dependency_scanning_run,
|
|
|
|
:secure_dast_run
|
2022-05-07 20:08:51 +05:30
|
|
|
].freeze
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def initialize(project, current_user = nil)
|
|
|
|
@project = project
|
|
|
|
@namespace = project.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
|
|
|
|
|
|
|
|
total_actions = action_columns.count
|
2023-05-27 22:25:52 +05:30
|
|
|
completed_actions = action_columns.count { |column| completed?(column) }
|
2021-06-08 01:23:25 +05:30
|
|
|
|
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
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def completed?(column)
|
|
|
|
if column == :code_added
|
|
|
|
repository.commit_count > 1 || repository.branch_count > 1
|
|
|
|
else
|
|
|
|
attributes[column].present?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
private
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def repository
|
|
|
|
project.repository
|
|
|
|
end
|
|
|
|
strong_memoize_attr :repository
|
|
|
|
|
|
|
|
def attributes
|
|
|
|
onboarding_progress.attributes.symbolize_keys
|
|
|
|
end
|
|
|
|
strong_memoize_attr :attributes
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
def onboarding_progress
|
2023-05-27 22:25:52 +05:30
|
|
|
::Onboarding::Progress.find_by(namespace: namespace)
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
2023-05-27 22:25:52 +05:30
|
|
|
strong_memoize_attr :onboarding_progress
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
def action_columns
|
2023-05-27 22:25:52 +05:30
|
|
|
[:code_added] +
|
2023-06-20 00:43:36 +05:30
|
|
|
ACTION_PATHS.map { |action_key| ::Onboarding::Progress.column_name(action_key) }
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
2023-05-27 22:25:52 +05:30
|
|
|
strong_memoize_attr :action_columns
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
attr_reader :project, :namespace, :current_user
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
end
|