<commit_before>class RepositoriesController < ApplicationController
  before_filter :fetch_report, only: [:show, :refresh, :badge]
  has_scope :language

  rescue_from Octokit::ClientError, with: :not_found_badge

  def index
    @reports = apply_scopes(Report).ready.paginate(page: params[:page] || 1)
    @reports = @reports.with_issues unless params[:language]
    @reports = apply_sort(@reports, default: {
      sortable_direction: "ASC",
      sortable_attr: "pr_close_time"
    })
  end

  def show
  end

  def analysis
  end

  def badge
    if variant
      redirect_to @report.badge_url(variant, style)
    else
      not_found_badge
    end
  end

  def refresh
    @report.fetch_metadata
    @report.bootstrap_async
    render nothing: true
  end

  private

  def fetch_report<commit_msg>set no-cache header for badges<commit_after>class RepositoriesController < ApplicationController
  before_filter :fetch_report, only: [:show, :refresh, :badge]
  has_scope :language

  rescue_from Octokit::ClientError, with: :not_found_badge

  def index
    @reports = apply_scopes(Report).ready.paginate(page: params[:page] || 1)
    @reports = @reports.with_issues unless params[:language]
    @reports = apply_sort(@reports, default: {
      sortable_direction: "ASC",
      sortable_attr: "pr_close_time"
    })
  end

  def show
  end

  def analysis
  end

  def badge
    response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    if variant
      redirect_to @report.badge_url(variant, style)
    else
      not_found_badge
    end
  end

  def refresh
    @report.fetch_metadata
    @report.bootstrap_async
    render nothing: true
  end

  private

  def fetch_report
{'fraction_non_alphanumeric': 0.09179019384264538, 'fraction_numerical': 0.0017103762827822121, 'mean_word_length': 3.606299212598425, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1548947', 'n_tokens_mistral': 586, 'n_tokens_neox': 557, 'n_words': 132}