Class: Danger::FindRepoInfoFromURL

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/ci_source/support/find_repo_info_from_url.rb

Constant Summary collapse

REGEXP =
%r{
  ://[^/]+/
  (([^/]+/){1,2}_git/)?
  (?<slug>[^/]+(/[^/]+){0,2})
  (/(pull|pullrequest|merge_requests|pull-requests)/)
  (?<id>\d+)
}x.freeze
REGEXPBB =

Regex used to extract info from Bitbucket server URLs, as they use a quite different format

%r{
  (?:[/:])projects
  /([^/.]+)
  /repos/([^/.]+)
  /pull-requests
  /(\d+)
}x.freeze

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ FindRepoInfoFromURL

Returns a new instance of FindRepoInfoFromURL.



22
23
24
# File 'lib/danger/ci_source/support/find_repo_info_from_url.rb', line 22

def initialize(url)
  @url = url
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/danger/ci_source/support/find_repo_info_from_url.rb', line 26

def call
  matched = url.match(REGEXPBB)

  if matched
    RepoInfo.new("#{matched[1]}/#{matched[2]}", matched[3])
  else
    matched = url.match(REGEXP)
    if matched
      RepoInfo.new(matched[:slug], matched[:id])
    end
  end
end