<commit_before># frozen_string_literal: true

require 'tessellator/fetcher'

class HowIs
  # This entire class is a monstrous hack, because GitHub doesn't provide
  # a good API for Pulse.
  #
  # TODO: Use GitHub's Statistics API to replace this garbage.
  #   See https://github.com/how-is/how_is/issues/122
  class Pulse
    def initialize(repository)
      @repository = repository
      @pulse_page_response = fetch_pulse!(repository)
    end

    # This is probably dead code.
    def text_summary
      raise NotImplementedError
    end

    # Gets the HTML Pulse summary.
    def html_summary
      parts =
        @pulse_page_response.body
          .split('<div class="section diffstat-summary">')

      if parts.length == 1
        return "There hasn't been any activity on #{@repository} in the last month."
      end

      parts
        .last
        .split('</div>').first
        .gsub('<a href="/', '<a href="https://github.com/')
        .strip
    end

    private

    # Fetch Pulse page from GitHub for scraping.
    def fetch_pulse!(repository, period='monthly')
      Tessellator::Fetcher.new.call('get', "https://github.com/#{repository}/pulse/#{period}")
    end
  end
end<commit_msg>[how_is/pulse] remove unnecessary argument<commit_after># frozen_string_literal: true

require 'tessellator/fetcher'

class HowIs
  # This entire class is a monstrous hack, because GitHub doesn't provide
  # a good API for Pulse.
  #
  # TODO: Use GitHub's Statistics API to replace this garbage.
  #   See https://github.com/how-is/how_is/issues/122
  class Pulse
    def initialize(repository)
      @repository = repository
      @pulse_page_response = fetch_pulse!(repository)
    end

    # This is probably dead code.
    def text_summary
      raise NotImplementedError
    end

    # Gets the HTML Pulse summary.
    def html_summary
      parts =
        @pulse_page_response.body
          .split('<div class="section diffstat-summary">')

      if parts.length == 1
        return "There hasn't been any activity on #{@repository} in the last month."
      end

      parts
        .last
        .split('</div>').first
        .gsub('<a href="/', '<a href="https://github.com/')
        .strip
    end

    private

    # Fetch Pulse page from GitHub for scraping.
    def fetch_pulse!(repository)
      Tessellator::Fetcher.new.call('get', "https://github.com/#{repository}/pulse/monthly")
    end
  end
end
{'fraction_non_alphanumeric': 0.1053931659118979, 'fraction_numerical': 0.0032935364347468094, 'mean_word_length': 2.626865671641791, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 6, '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': '1734278', 'n_tokens_mistral': 752, 'n_tokens_neox': 706, 'n_words': 213}