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:
Diffstat (limited to 'app/finders/packages/go/module_finder.rb')
-rw-r--r--app/finders/packages/go/module_finder.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/app/finders/packages/go/module_finder.rb b/app/finders/packages/go/module_finder.rb
new file mode 100644
index 00000000000..ed8bd5599d9
--- /dev/null
+++ b/app/finders/packages/go/module_finder.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+module Packages
+ module Go
+ class ModuleFinder
+ include Gitlab::Golang
+
+ attr_reader :project, :module_name
+
+ def initialize(project, module_name)
+ module_name = Pathname.new(module_name).cleanpath.to_s
+
+ @project = project
+ @module_name = module_name
+ end
+
+ def execute
+ return if @module_name.blank? || !@module_name.start_with?(local_module_prefix)
+
+ module_path = @module_name[local_module_prefix.length..].split('/')
+ project_path = project.full_path.split('/')
+ module_project_path = module_path.shift(project_path.length)
+ return unless module_project_path == project_path
+
+ Packages::Go::Module.new(@project, @module_name, module_path.join('/'))
+ end
+ end
+ end
+end