Sha256: ef2c6d498b0b9c2cb888c661ae2acc1854dd132cd9f93061606751c31b888c49

Contents?: true

Size: 833 Bytes

Versions: 50

Compression:

Stored size: 833 Bytes

Contents

require "danger/ci_source/support/repo_info"

module Danger
  class FindRepoInfoFromURL
    REGEXP = %r{
      ://[^/]+/
      (?<slug>[^/]+(/[^/]+){1,2})
      (/(pull|merge_requests|pull-requests)/)
      (?<id>\d+)
    }x
    
    # Regex used to extract info from Bitbucket server URLs, as they use a quite different format
    REGEXPBB = %r{
      (?:[\/:])projects
      \/([^\/.]+)
      \/repos\/([^\/.]+)
      \/pull-requests
      \/(\d+)
    }x

    def initialize(url)
      @url = url
    end

    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

    private

    attr_reader :url
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
danger-9.1.0 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-9.0.0 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.6.1 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.6.0 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.5.0 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.4.5 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.4.4 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.4.3 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.4.2 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.4.1 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.4.0 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.3.1 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.2.3 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.2.2 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.2.1 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.2.0 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.1.0 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.0.6 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.0.5 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-8.0.4 lib/danger/ci_source/support/find_repo_info_from_url.rb