<commit_before>include ActionView::Helpers::TextHelper

class GitoliteHooksController < ApplicationController

  skip_before_filter :verify_authenticity_token, :check_if_login_required
  before_filter      :find_project_and_repository

  helper :git_hosting
  include GitHostingHelper


  def stub
    # Stub method simply to generate correct urls, just return a 404 to any user requesting this
    render(:code => 404)
  end


  def post_receive
    if not @repository.extra.validate_encoded_time(params[:clear_time], params[:encoded_time])
      render(:text => "The hook key provided is not valid. Please let your server admin know about it")
      return
    end

    ## Clear existing cache
    RedmineGitolite::Cache.clear_cache_for_repository(@repository)

    self.response.headers["Content-Type"] = "text/plain;"

    self.response_body = Enumerator.new do |y|

      ## Fetch commits from the repository
      message = "Fetching changesets for '#{@project.identifier}' repository"
      logger.info message
      y << message

      begin
        @repository.fetch_changesets
      rescue Redmine::Scm::Adapters::CommandFailed => e
        logger.error "Error during fetching changesets: #{e.message}"
      end

      y << "Done\n"

      payloads = []

      if @repository.repository_mirrors.has_explicit_refspec.any? || @repository.repository_post_receive_urls.any?
        payloads = post_receive_payloads(params[:refs])
      end

      ## Push to each mirror
      @repository.repository_mirrors.all(:order => 'active DESC, created_at ASC', :conditions => "active=1").each do |mirror|
        if mirror.needs_push(payloads)
          message = "Pushing changes to #{mirror.url} ..."

          logger.info message
          y << message

          (mirror_error, mirror_message) = mirror.push

          if mirror_error
            logger.error "Failed!"
            logger.error "#{mirror_message}"
            y << "[failure]\n"
          else
            logger.info "Succeeded!"
            y << "[success]\n"
          end
        end
      end if @repository.repository_mirrors.any?


      ## Post to each post-receive URL
      @repository.repository_post_receive_urls.all(:order => "active DESC, created_at ASC", :conditions => "active=1").each do |prurl|
        if prurl.mode == :github
          message = "Sending #{pluralize(payloads.length, 'notification')} to #{prurl.url} ..."
        else
          message = "Notifying #{prurl.url} ..."
        end

        y << message

        uri  = URI(prurl.url)
        http = Net::HTTP.new(uri.host, uri.port)<commit_msg>Minor change<commit_after>include ActionView::Helpers::TextHelper

class GitoliteHooksController < ApplicationController

  skip_before_filter :verify_authenticity_token, :check_if_login_required
  before_filter      :find_project_and_repository

  helper :git_hosting
  include GitHostingHelper


  def stub
    # Stub method simply to generate correct urls, just return a 404 to any user requesting this
    render(:code => 404)
  end


  def post_receive
    if not @repository.extra.validate_encoded_time(params[:clear_time], params[:encoded_time])
      render(:text => "The hook key provided is not valid. Please let your server admin know about it")
      return
    end

    ## Clear existing cache
    RedmineGitolite::Cache.clear_cache_for_repository(@repository)

    self.response.headers["Content-Type"] = "text/plain;"

    self.response_body = Enumerator.new do |y|

      ## Fetch commits from the repository
      message = "Fetching changesets for '#{@project.identifier}' repository"
      logger.info message
      y << message

      begin
        @repository.fetch_changesets
      rescue Redmine::Scm::Adapters::CommandFailed => e
        logger.error "Error during fetching changesets: #{e.message}"
      end

      y << "Done\n"

      payloads = []

      if @repository.repository_mirrors.has_explicit_refspec.any? || @repository.repository_post_receive_urls.any?
        payloads = post_receive_payloads(params[:refs])
      end

      ## Push to each mirror
      @repository.repository_mirrors.all(:order => 'active DESC, created_at ASC', :conditions => "active=1").each do |mirror|
        if mirror.needs_push(payloads)
          message = "Pushing changes to #{mirror.url} ..."

          logger.info message
          y << message

          push_failed, push_message = mirror.push

          if push_failed
            logger.error "Failed!"
            logger.error "#{push_message}"
            y << "[failure]\n"
          else
            logger.info "Succeeded!"
            y << "[success]\n"
          end
        end
      end if @repository.repository_mirrors.any?


      ## Post to each post-receive URL
      @repository.repository_post_receive_urls.all(:order => "active DESC, created_at ASC", :conditions => "active=1").each do |prurl|
        if prurl.mode == :github
          message = "Sending #{pluralize(payloads.length, 'notification')} to #{prurl.url} ..."
        else
          message = "Notifying #{prurl.url} ..."
        end

        y << message

        uri  = URI(prurl.url)
        http = Net::HTTP.new(uri.host, uri.port)
{'fraction_non_alphanumeric': 0.10406629408363846, 'fraction_numerical': 0.0030834457506263247, 'mean_word_length': 2.7177650429799427, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 17, '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': '3423743', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1447, 'n_words': 370}