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 22, 2021
1 parent c4e4b2f commit 3e81616
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 @@ -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,
Expand All @@ -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
Expand All @@ -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

0 comments on commit 3e81616

Please sign in to comment.