Sha256: d8b99064c76be1e1b61c87df2203c6276809aa941f3cff5b8722e2a942a7057a

Contents?: true

Size: 1.64 KB

Versions: 20

Compression:

Stored size: 1.64 KB

Contents

require "safe_yaml/load"

module CC
  module CLI
    class Prepare
      class Quality < Command
        ENGINES_CONFIG = {
          "complexity-ruby" => {
            "enabled" => true,
            "channel" => "beta",
          },
          "duplication" => {
            "enabled" => true,
            "channel" => "cronopio",
            "config" => {
              "languages" => [
                "ruby",
              ],
            },
          },
        }.freeze

        def execute
          Dir.chdir(CC::Analyzer::MountedPath.code.container_path) do
            content =
              if (existing_contents = read_codeclimate_yml)
                modify(existing_contents)
              else
                { "engines" => ENGINES_CONFIG }
              end

            write_codeclimate_yml(content)
          end
        end

        private

        def modify(content)
          content.delete("ratings")
          content["engines"] ||= {}
          content["engines"].merge!(ENGINES_CONFIG)
          content
        end

        def read_codeclimate_yml
          SafeYAML.load_file(CODECLIMATE_YAML)
        rescue Errno::ENOENT
          CLI.debug("No .codeclimate.yml present")
        rescue => ex
          message = "Error reading existing #{CODECLIMATE_YAML}, overwriting."
          $stderr.puts(colorize("WARNING: #{message}", :yellow))
          CLI.debug("error: #{ex.class} - #{ex.message}")
        end

        def write_codeclimate_yml(content)
          yaml = YAML.dump(content)
          CLI.debug("Writing .codeclimate.yml")
          CLI.debug(yaml)
          File.write(CODECLIMATE_YAML, yaml)
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
codeclimate-0.69.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.68.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.67.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.66.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.65.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.64.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.63.7 lib/cc/cli/prepare/quality.rb
codeclimate-0.63.6 lib/cc/cli/prepare/quality.rb
codeclimate-0.63.5 lib/cc/cli/prepare/quality.rb
codeclimate-0.63.4 lib/cc/cli/prepare/quality.rb
codeclimate-0.63.3 lib/cc/cli/prepare/quality.rb
codeclimate-0.63.2 lib/cc/cli/prepare/quality.rb
codeclimate-0.63.1 lib/cc/cli/prepare/quality.rb
codeclimate-0.63.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.62.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.61.1 lib/cc/cli/prepare/quality.rb
codeclimate-0.61.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.60.1 lib/cc/cli/prepare/quality.rb
codeclimate-0.60.0 lib/cc/cli/prepare/quality.rb
codeclimate-0.59.1 lib/cc/cli/prepare/quality.rb