Class: LockDiff::Github::RepositoryNameDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/lock_diff/github/repository_name_detector.rb

Constant Summary collapse

REGEXP =
%r!github\.com[/:](.*?)(?:\.git)?\z!

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ RepositoryNameDetector

Returns a new instance of RepositoryNameDetector.



6
7
8
# File 'lib/lock_diff/github/repository_name_detector.rb', line 6

def initialize(url)
  @url = url
end

Instance Method Details

#callObject



10
11
12
13
14
15
16
# File 'lib/lock_diff/github/repository_name_detector.rb', line 10

def call
  return unless @url
  path = @url.match(REGEXP).to_a.last&.split('#')&.first
  return unless path
  repository_name = path.split("/").first(2).join("/")
  repository_name if repository_name.match?(/.+\/.+/)
end