Skip to content

Commit

Permalink
WIP: Guess API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
neomilium committed Apr 23, 2021
1 parent ab6f822 commit ad16266
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/modulesync/source_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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

0 comments on commit ad16266

Please sign in to comment.