Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /app/finders/analytics/cycle_analytics/stage_finder.rb
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'app/finders/analytics/cycle_analytics/stage_finder.rb')
-rw-r--r--app/finders/analytics/cycle_analytics/stage_finder.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/finders/analytics/cycle_analytics/stage_finder.rb b/app/finders/analytics/cycle_analytics/stage_finder.rb
new file mode 100644
index 00000000000..732e9ff3e00
--- /dev/null
+++ b/app/finders/analytics/cycle_analytics/stage_finder.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+module Analytics
+ module CycleAnalytics
+ class StageFinder
+ def initialize(parent:, stage_id:)
+ @parent = parent
+ @stage_id = stage_id
+ end
+
+ def execute
+ build_in_memory_stage_by_name
+ end
+
+ private
+
+ attr_reader :parent, :stage_id
+
+ def build_in_memory_stage_by_name
+ parent.cycle_analytics_stages.build(find_in_memory_stage)
+ end
+
+ def find_in_memory_stage
+ # raise ActiveRecord::RecordNotFound, so it will behave similarly to AR models and produce 404 response in the controller
+ raw_stage = Gitlab::Analytics::CycleAnalytics::DefaultStages.all.find do |hash|
+ hash[:name].eql?(stage_id)
+ end
+
+ raise(ActiveRecord::RecordNotFound, "Stage with id '#{stage_id}' could not be found") unless raw_stage
+
+ raw_stage
+ end
+ end
+ end
+end
+
+Analytics::CycleAnalytics::StageFinder.prepend_mod_with('Analytics::CycleAnalytics::StageFinder')