<commit_before>class EventPresenter

  class PushSummaryEvent < self
    COMMIT_LIMIT = 2

    attr_reader :event_data
    private :event_data

    attr_reader :commits

    def initialize(*)
      super
      initialize_event_data
      initialize_commits
    end

    def action
      link_title = commit_count > 1 ? "#{commit_count} commits" : "1 commit"
      diff_link = link_to(link_title, diff_url)
      action_for_event(:event_pushed_n, :commit_link => diff_link) {
        ['to', commit_link(h("#{title}:#{branch}"))].join(' ')
      }
    end

    def category
      'push'
    end

    def body
      view.content_tag(:ul, :class => 'gts-event-commit-list') {
        inner_html = commits.map { |commit| render_commit(commit) }

        if commit_count > COMMIT_LIMIT
          inner_html << content_tag(:li) {
            link_to("View all &raquo;".html_safe, diff_url)
          }
        end

        inner_html.join("\n").html_safe
      }
    end

    def render_commit(commit, options = {})
      user    = commit.committer_user
      message = commit.summary

      link = link_to(
        view.content_tag('code', commit.short_oid).html_safe,
        view.project_repository_commit_path(project, repository, commit.id)
      )

      content =
        if user
          "#{view.avatar(user, :size => 16, :class => 'gts-avatar')} #{link} #{message}"
        else
          "#{commit.actor_display} #{link} #{message}"
        end

      view.content_tag(:li, content.html_safe, options)
    end

    def title
      repo_title(repository, project)
    end

    def commit_link(title)
      url = view.project_repository_commits_in_ref_path(
        repository.project, repository, ensplat_path(branch)
      )

      link_to(title, url)
    end

    private

    def first_sha
      event_data[:start_sha]
    end

    def last_sha
      event_data[:end_sha]
    end

    def branch
      event_data[:branch]
    end

    def commit_count
      event_data[:commit_count].to_i
    end

    def diff_url
      view.project_repository_commit_compare_path(
        target.project, target, :from_id => first_sha, :id => last_sha
      )
    end

    def repository
      target
    end

    def initialize_event_data
      @event_data = PushEventLogger.parse_event_data(data)
    end

    def initialize_commits
      # FIXME: this won't be needed when we convert old push/commit events to
      #        push summary events
      first_commit = fetch_first_commit

      @commits =
        if first_commit
          [CommitPresenter.new(repository, first_commit)]
        else
          []
        end
    end

    def fetch_first_commit
      repository.git.commits_between(first_sha, last_sha).first
    end

    def visible_commits
      commits[0, COMMIT_LIMIT]
    end

    def hidden_commits
      Array(commits[COMMIT_LIMIT+1, commits.size]).compact
    end

  end

end<commit_msg>Avoid loading both start/end commits if it is just 1-commit push<commit_after>class EventPresenter

  class PushSummaryEvent < self
    COMMIT_LIMIT = 2

    attr_reader :event_data
    private :event_data

    attr_reader :commits

    def initialize(*)
      super
      initialize_event_data
      initialize_commits
    end

    def action
      link_title = commit_count > 1 ? "#{commit_count} commits" : "1 commit"
      diff_link = link_to(link_title, diff_url)
      action_for_event(:event_pushed_n, :commit_link => diff_link) {
        ['to', commit_link(h("#{title}:#{branch}"))].join(' ')
      }
    end

    def category
      'push'
    end

    def body
      view.content_tag(:ul, :class => 'gts-event-commit-list') {
        inner_html = commits.map { |commit| render_commit(commit) }

        if commit_count > COMMIT_LIMIT
          inner_html << content_tag(:li) {
            link_to("View all &raquo;".html_safe, diff_url)
          }
        end

        inner_html.join("\n").html_safe
      }
    end

    def render_commit(commit, options = {})
      user    = commit.committer_user
      message = commit.summary

      link = link_to(
        view.content_tag('code', commit.short_oid).html_safe,
        view.project_repository_commit_path(project, repository, commit.id)
      )

      content =
        if user
          "#{view.avatar(user, :size => 16, :class => 'gts-avatar')} #{link} #{message}"
        else
          "#{commit.actor_display} #{link} #{message}"
        end

      view.content_tag(:li, content.html_safe, options)
    end

    def title
      repo_title(repository, project)
    end

    def commit_link(title)
      url = view.project_repository_commits_in_ref_path(
        repository.project, repository, ensplat_path(branch)
      )

      link_to(title, url)
    end

    private

    def first_sha
      event_data[:start_sha]
    end

    def last_sha
      event_data[:end_sha]
    end

    def branch
      event_data[:branch]
    end

    def commit_count
      event_data[:commit_count].to_i
    end

    def diff_url
      view.project_repository_commit_compare_path(
        target.project, target, :from_id => first_sha, :id => last_sha
      )
    end

    def repository
      target
    end

    def initialize_event_data
      @event_data = PushEventLogger.parse_event_data(data)
    end

    def initialize_commits
      # FIXME: this won't be needed when we convert old push/commit events to
      #        push summary events
      first_commit = fetch_first_commit

      @commits =
        if first_commit
          [CommitPresenter.new(repository, first_commit)]
        else
          []
        end
    end

    def fetch_first_commit
      if commit_count > 1
        repository.git.commits_between(first_sha, last_sha).first
      else
        repository.git.commit(last_sha)
      end
    end

    def visible_commits
      commits[0, COMMIT_LIMIT]
    end

    def hidden_commits
      Array(commits[COMMIT_LIMIT+1, commits.size]).compact
    end

  end

end
{'fraction_non_alphanumeric': 0.08863101244534141, 'fraction_numerical': 0.0026908846283215607, 'mean_word_length': 2.300221975582686, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, 'https://': 0, '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': '1456300', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1835, 'n_words': 395}