Sha256: b51d772bf6308e4d2d9bfbdafe59ae73827acd2e8c8d6ae75f2a955df43b2d40

Contents?: true

Size: 892 Bytes

Versions: 2

Compression:

Stored size: 892 Bytes

Contents

# frozen_string_literal: true

module Unwrappr
  module Researchers
    # Checks the gem metadata to obtain a Github source repository if available.
    #
    # Implements the `gem_researcher` interface required by the
    # LockFileAnnotator.
    class GithubRepo
      GITHUB_URI_PATTERN = %r{^https?://
                              github.com/
                              (?<repo>[^/]+/[[:alnum:]_.-]+)
                              }ix.freeze

      def research(_gem_change, gem_change_info)
        repo = match_repo(gem_change_info, 'source_code_uri') ||
               match_repo(gem_change_info, 'homepage_uri')
        gem_change_info.merge(github_repo: repo)
      end

      def match_repo(gem_change_info, uri_name)
        uri = gem_change_info.dig(:ruby_gems, uri_name)
        match = GITHUB_URI_PATTERN.match(uri)
        match[:repo] if match
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unwrappr-0.8.2 lib/unwrappr/researchers/github_repo.rb
unwrappr-0.8.1 lib/unwrappr/researchers/github_repo.rb