diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /lib/learn_gitlab | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'lib/learn_gitlab')
-rw-r--r-- | lib/learn_gitlab/onboarding.rb | 57 | ||||
-rw-r--r-- | lib/learn_gitlab/project.rb | 37 |
2 files changed, 94 insertions, 0 deletions
diff --git a/lib/learn_gitlab/onboarding.rb b/lib/learn_gitlab/onboarding.rb new file mode 100644 index 00000000000..38ffa9eb2e6 --- /dev/null +++ b/lib/learn_gitlab/onboarding.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +module LearnGitlab + class Onboarding + include Gitlab::Utils::StrongMemoize + + ACTION_ISSUE_IDS = { + issue_created: 4, + git_write: 6, + pipeline_created: 7, + merge_request_created: 9, + user_added: 8, + trial_started: 2, + required_mr_approvals_enabled: 11, + code_owners_enabled: 10 + }.freeze + + ACTION_DOC_URLS = { + security_scan_enabled: 'https://docs.gitlab.com/ee/user/application_security/security_dashboard/#gitlab-security-dashboard-security-center-and-vulnerability-reports' + }.freeze + + def initialize(namespace) + @namespace = namespace + end + + def completed_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.to_f * 100).round + end + + private + + def onboarding_progress + strong_memoize(:onboarding_progress) do + OnboardingProgress.find_by(namespace: namespace) # rubocop: disable CodeReuse/ActiveRecord + end + end + + def action_columns + strong_memoize(:action_columns) do + tracked_actions.map { |action_key| OnboardingProgress.column_name(action_key) } + end + end + + def tracked_actions + ACTION_ISSUE_IDS.keys + ACTION_DOC_URLS.keys + end + + attr_reader :namespace + end +end diff --git a/lib/learn_gitlab/project.rb b/lib/learn_gitlab/project.rb new file mode 100644 index 00000000000..599f9940e53 --- /dev/null +++ b/lib/learn_gitlab/project.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module LearnGitlab + class Project + PROJECT_NAME = 'Learn GitLab' + 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) + 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 |