diff --git a/lib/modulesync/source_code.rb b/lib/modulesync/source_code.rb index 8e4ce61c..a0c292a0 100644 --- a/lib/modulesync/source_code.rb +++ b/lib/modulesync/source_code.rb @@ -49,7 +49,9 @@ def path(*parts) end def open_pull_request - git_service = GitService.instantiate type: git_service_type, options: @options[git_service_type] + git_service_options = @options[git_service_type] || {} + git_service_options[:base_url] = git_service_api_endpoint + git_service = GitService.instantiate type: git_service_type, options: git_service_options git_service.open_pull_request( repo_path: repository_path, namespace: repository_namespace, @@ -66,6 +68,10 @@ def git_service_type @git_service_type ||= guess_git_service_type end + def git_service_api_endpoint + @git_service_api_endpoint ||= @options.dig(git_service_type, 'base_url') || guess_git_service_api_endpoint + end + private def _repository_remote @@ -80,5 +86,13 @@ def guess_git_service_type return :gitlab if repository_remote.include? 'gitlab' :unknown end + + def guess_git_service_api_endpoint + return unless git_service_type == :gitlab + + pattern = /^git@(.*):(.*).git$/ + return nil unless repository_remote.match?(pattern) + repository_remote.sub(pattern, 'https://\1/api/v4') + end end end