diff --git a/lib/modulesync/source_code.rb b/lib/modulesync/source_code.rb index 2e93be6b..8e0c5c8a 100644 --- a/lib/modulesync/source_code.rb +++ b/lib/modulesync/source_code.rb @@ -45,7 +45,9 @@ def working_directory 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, @@ -62,6 +64,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 @@ -76,5 +82,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