<commit_before># rubocop:disable Style/FrozenStringLiteralComment

require "asciidoctor"
require "octokit"
require "time"
require "digest/sha1"


def index_l10n_doc(filter_tags, doc_list, get_content)

  ActiveRecord::Base.logger.level = Logger::WARN
  rebuild = ENV["REBUILD_DOC"]
  rerun = ENV["RERUN"] || rebuild || false

  filter_tags.call(rebuild, false).sort_by { |tag| Version.version_to_num(tag.first[1..-1]) }.each do |tag|
    name, commit_sha, tree_sha, ts = tag
    puts "#{name}: #{ts}, #{commit_sha[0, 8]}, #{tree_sha[0, 8]}"

    stag = Version.where(name: name.gsub("v", "l10n")).first_or_create

    next if (stag.commit_sha == commit_sha) && !rerun

    stag.commit_sha = commit_sha
    stag.tree_sha = tree_sha
    stag.committed = ts
    stag.save

    tag_files = doc_list.call(tree_sha)
    doc_files = tag_files.select { |ent| ent.first =~
        /^([_\w]+)\/(
          (
            git.*
        )\.txt)/x
    }

    puts "Found #{doc_files.size} entries"
    doc_limit = ENV["ONLY_BUILD_DOC"]

    get_content_f = Proc.new do |source, target|
      name = File.join(File.dirname(source), target)
        content_file = tag_files.detect { |ent| ent.first == name }
        if content_file
          new_content = get_content.call (content_file.second)
        else
          puts "can not resolve #{name}\n"
        end
        [new_content, name]
    end

    def expand!(path, content, get_f_content , categories)
      content.gsub!(/include::(\S+)\.txt/) do |line|
        line.gsub!("include::", "")
        if categories[line]
          new_content = categories[line]
        else
          new_content, path = get_f_content.call(path, line)
        end
        if new_content
          expand!(path, new_content, get_f_content, categories)
        end
      end
      return content
    end
<commit_msg>manpages l10n: add a warning when missing include file<commit_after># rubocop:disable Style/FrozenStringLiteralComment

require "asciidoctor"
require "octokit"
require "time"
require "digest/sha1"


def index_l10n_doc(filter_tags, doc_list, get_content)

  ActiveRecord::Base.logger.level = Logger::WARN
  rebuild = ENV["REBUILD_DOC"]
  rerun = ENV["RERUN"] || rebuild || false

  filter_tags.call(rebuild, false).sort_by { |tag| Version.version_to_num(tag.first[1..-1]) }.each do |tag|
    name, commit_sha, tree_sha, ts = tag
    puts "#{name}: #{ts}, #{commit_sha[0, 8]}, #{tree_sha[0, 8]}"

    stag = Version.where(name: name.gsub("v", "l10n")).first_or_create

    next if (stag.commit_sha == commit_sha) && !rerun

    stag.commit_sha = commit_sha
    stag.tree_sha = tree_sha
    stag.committed = ts
    stag.save

    tag_files = doc_list.call(tree_sha)
    doc_files = tag_files.select { |ent| ent.first =~
        /^([_\w]+)\/(
          (
            git.*
        )\.txt)/x
    }

    puts "Found #{doc_files.size} entries"
    doc_limit = ENV["ONLY_BUILD_DOC"]

    get_content_f = Proc.new do |source, target|
      name = File.join(File.dirname(source), target)
        content_file = tag_files.detect { |ent| ent.first == name }
        if content_file
          new_content = get_content.call (content_file.second)
        else
          puts "can not resolve #{name}\n"
        end
        [new_content, name]
    end

    def expand!(path, content, get_f_content , categories)
      content.gsub!(/include::(\S+)\.txt/) do |line|
        line.gsub!("include::", "")
        if categories[line]
          new_content = categories[line]
        else
          new_content, path = get_f_content.call(path, line)
        end
        if new_content
          expand!(path, new_content, get_f_content, categories)
        else
          "\n\n[WARNING]\n====\nMissing `#{path}`\n\nSee original version for this content.\n====\n\n"
        end
      end
      return content
    end

{'fraction_non_alphanumeric': 0.13566397078006784, 'fraction_numerical': 0.006261414036003131, 'mean_word_length': 2.68299711815562, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1508085', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1309, 'n_words': 278}