Sha256: 98247907dd56af6d22a3a58e0928c467b5341cb19928f78dd8d88e69e4a91933

Contents?: true

Size: 875 Bytes

Versions: 46

Compression:

Stored size: 875 Bytes

Contents

require "danger/ci_source/support/repo_info"

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

    # Regex used to extract info from Bitbucket server URLs, as they use a quite different format
    REGEXPBB = %r{
      (?:[/:])projects
      /([^/.]+)
      /repos/([^/.]+)
      /pull-requests
      /(\d+)
    }x.freeze

    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

46 entries across 46 versions & 2 rubygems

Version Path
danger-9.5.1 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-9.5.0 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-9.4.3 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-9.4.2 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-9.4.1 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-9.4.0 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-9.3.2 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.36 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.35 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.34 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.33 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.32 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.31 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.30 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.29 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.28 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.27 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.26 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.25 lib/danger/ci_source/support/find_repo_info_from_url.rb
danger-additional-logging-0.0.24 lib/danger/ci_source/support/find_repo_info_from_url.rb