<commit_before>require "json"
require "httpclient"
require "net/http"

class CompareLinker
  class GithubLinkFinder
    attr_reader :octokit, :repo_owner, :repo_name, :homepage_uri

    def initialize(octokit)
      @octokit = octokit
    end

    def find(gem_name)
      gem_info = JSON.parse(
        HTTPClient.get_content("https://rubygems.org/api/v1/gems/#{gem_name}.json")
      )

      github_url = [
        gem_info["homepage_uri"],
        gem_info["source_code_uri"]
      ].find { |uri| uri.to_s.match(/github\.com\//) }

      if github_url.nil?
        @homepage_uri = gem_info["homepage_uri"]
      else
        github_url = redirect_url(github_url)
        _, @repo_owner, @repo_name = github_url.match(%r!github\.com/([^/]+)/([^/]+)!).to_a
      end

    rescue JSON::ParserError
      @homepage_uri = "https://rubygems.org/gems/#{gem_name}"
    end

    def repo_full_name
      "#{@repo_owner}/#{repo_name}"
    end<commit_msg>Fix not found error for gems on rails-assets.org<commit_after>require "json"
require "httpclient"
require "net/http"

class CompareLinker
  class GithubLinkFinder
    attr_reader :octokit, :repo_owner, :repo_name, :homepage_uri

    def initialize(octokit)
      @octokit = octokit
    end

    def find(gem_name)
      gem_info = JSON.parse(
        HTTPClient.get_content("https://rubygems.org/api/v1/gems/#{gem_name}.json")
      )

      github_url = [
        gem_info["homepage_uri"],
        gem_info["source_code_uri"]
      ].find { |uri| uri.to_s.match(/github\.com\//) }

      if github_url.nil?
        @homepage_uri = gem_info["homepage_uri"]
      else
        github_url = redirect_url(github_url)
        _, @repo_owner, @repo_name = github_url.match(%r!github\.com/([^/]+)/([^/]+)!).to_a
      end

    rescue HTTPClient::BadResponseError, JSON::ParserError
      @homepage_uri = "https://rubygems.org/gems/#{gem_name}"
    end

    def repo_full_name
      "#{@repo_owner}/#{repo_name}"
    end
{'fraction_non_alphanumeric': 0.14227434982151962, 'fraction_numerical': 0.0010198878123406426, 'mean_word_length': 2.900596421471173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '118615', 'n_tokens_mistral': 723, 'n_tokens_neox': 692, 'n_words': 109}