Sha256: 96bbe439369a18f1ffaa4c3fb580b98f99f0b36a73e9ce81061bc9fbd6d1fd2b

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

require "gems"

module Codestatus
  class RepositoryResolver
    class RubygemsResolver
      GITHUB_REPOSITORY_REGEXP = %r{(https|git)://github.com/(?<owner>[^/]*)/(?<repo>[^/]*)(\.git)?/?.*}.freeze

      def resolve(registry:, package:)
        return unless registry.to_s == 'rubygems'
        @package = package

        github_repository
      end

      attr_reader :package

      private

      def github_repository
        result = nil
        urls.each do |url|
          matched = GITHUB_REPOSITORY_REGEXP.match(url)
          next unless matched

          repo = [matched[:owner], matched[:repo]].join('/')
          result = Codestatus::PackageRepository.new(github: repo)
          break
        end
        result
      end

      def gem_info
        @info ||= Gems.info(package)
      end

      def urls
        [
          source_code_uri,
          homepage_uri,
          bug_tracker_uri,
        ].compact
      end

      def homepage_uri
        gem_info['homepage_uri']
      end

      def source_code_uri
        gem_info['source_code_uri']
      end

      def bug_tracker_uri
        gem_info['bug_tracker_uri']
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codestatus-0.1.1 lib/codestatus/repository_resolver/rubygems_resolver.rb