diff --git a/lib/modulesync/git_service.rb b/lib/modulesync/git_service.rb index 34429512..7a4bbb97 100644 --- a/lib/modulesync/git_service.rb +++ b/lib/modulesync/git_service.rb @@ -3,9 +3,9 @@ class Error < StandardError; end # Namespace for Git service classes (ie. GitHub, GitLab) module GitService - class MissingCredentialsError < Error; end + class MissingCredentialsError < Error; end - def self.instantiate(type:, options:) + def self.instantiate(type:, options:) options ||= {} case type when :github @@ -47,7 +47,7 @@ def self.type_for(sourcecode:) if ENV['GITLAB_TOKEN'].nil? && ENV['GITHUB_TOKEN'].nil? raise ModuleSync::Error, <<~MESSAGE - Unable to guess Git service type with none GITLAB_TOKEN or GITHUB_TOKEN sets. + Unable to guess Git service type without GITLAB_TOKEN or GITHUB_TOKEN sets. MESSAGE end @@ -90,7 +90,7 @@ def self.endpoint_for(sourcecode:, type:) def self.guess_endpoint_from(remote:, type:) pattern = /^git@(.*):(.*)(\.git)*$/ return nil unless remote.match?(pattern) - + endpoint = remote.sub(pattern, 'https://\1') endpoint += '/api/v4' if type == :gitlab endpoint @@ -100,7 +100,8 @@ def self.guess_endpoint_from(remote:, type:) # 2. environment variable depending on type # 3. fails def self.token_for(sourcecode:, type:) - return sourcecode.options[type][:token] unless sourcecode.options.dig(type, :token).nil? + token = sourcecode.options.dig(type, :token) + return token unless token.nil? token = case type when :github