<commit_before>require 'cucumber/messages'
require 'sys/uname'
require 'json'

module Cucumber
  module CreateMeta
    CI_DICT = JSON.parse(IO.read(File.join(File.dirname(__FILE__),"ciDict.json")))

    def create_meta(tool_name, tool_version, env=ENV)
      Cucumber::Messages::Meta.new(
        protocol_version: Cucumber::Messages::VERSION,
        implementation: Cucumber::Messages::Meta::Product.new(
          name: tool_name,
          version: tool_version
        ),
        runtime: Cucumber::Messages::Meta::Product.new(
          name: RUBY_ENGINE,
          version: RUBY_VERSION
        ),
        os: Cucumber::Messages::Meta::Product.new(
          name: RbConfig::CONFIG['target_os'],
          version: Sys::Uname.uname.version
        ),
        cpu: Cucumber::Messages::Meta::Product.new(
          name: RbConfig::CONFIG['target_cpu']
        ),
        ci: detect_ci(env)
      )
    end

    def detect_ci(env)
      detected = CI_DICT.map do |ci_name, ci_system|
        create_ci(ci_name, ci_system, env)
      end.compact

      detected.length == 1 ? detected[0] : nil
    end

    def create_ci(ci_name, ci_system, env)
      url = evaluate(ci_system['url'], env)
      return nil if url.nil?

      Cucumber::Messages::Meta::CI.new(
        url: url,
        name: ci_name,
        git: Cucumber::Messages::Meta::CI::Git.new(
          remote: evaluate(ci_system['git']['remote'], env),
          revision: evaluate(ci_system['git']['revision'], env),
          branch: evaluate(ci_system['git']['branch'], env),
          tag: evaluate(ci_system['git']['tag'], env),
        )
      )
    end

    def evaluate(template, env)
      return nil if template.nil?
      begin
        template.gsub(/\${((refbranch|reftag)\s+)?([^\s}]+)(\s+\|\s+([^}]+))?}/) do
          func = $2
          variable = $3
          default_value = $5 == "" ? nil : $5
          value = env[variable] || default_value
<commit_msg>Remove potential sensitive information in Meta.CI.Git.remote message<commit_after>require 'cucumber/messages'
require 'sys/uname'
require 'json'

module Cucumber
  module CreateMeta
    CI_DICT = JSON.parse(IO.read(File.join(File.dirname(__FILE__),"ciDict.json")))

    def create_meta(tool_name, tool_version, env=ENV)
      Cucumber::Messages::Meta.new(
        protocol_version: Cucumber::Messages::VERSION,
        implementation: Cucumber::Messages::Meta::Product.new(
          name: tool_name,
          version: tool_version
        ),
        runtime: Cucumber::Messages::Meta::Product.new(
          name: RUBY_ENGINE,
          version: RUBY_VERSION
        ),
        os: Cucumber::Messages::Meta::Product.new(
          name: RbConfig::CONFIG['target_os'],
          version: Sys::Uname.uname.version
        ),
        cpu: Cucumber::Messages::Meta::Product.new(
          name: RbConfig::CONFIG['target_cpu']
        ),
        ci: detect_ci(env)
      )
    end

    def detect_ci(env)
      detected = CI_DICT.map do |ci_name, ci_system|
        create_ci(ci_name, ci_system, env)
      end.compact

      detected.length == 1 ? detected[0] : nil
    end

    def create_ci(ci_name, ci_system, env)
      url = evaluate(ci_system['url'], env)
      return nil if url.nil?

      Cucumber::Messages::Meta::CI.new(
        url: url,
        name: ci_name,
        git: Cucumber::Messages::Meta::CI::Git.new(
          remote: clean_sensitive_information(evaluate(ci_system['git']['remote'], env)),
          revision: evaluate(ci_system['git']['revision'], env),
          branch: evaluate(ci_system['git']['branch'], env),
          tag: evaluate(ci_system['git']['tag'], env),
        )
      )
    end

    def evaluate(template, env)
      return nil if template.nil?
      begin
        template.gsub(/\${((refbranch|reftag)\s+)?([^\s}]+)(\s+\|\s+([^}]+))?}/) do
          func = $2
          variable = $3
          default_value = $5 == "" ? nil : $5
          value = env[variable] || default_value

{'fraction_non_alphanumeric': 0.14924242424242423, 'fraction_numerical': 0.0030303030303030303, 'mean_word_length': 2.574909747292419, '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': '4616706', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1244, 'n_words': 230}