class Pantograph::Actions::ClocAction

Public Class Methods

authors() click to toggle source
# File pantograph/lib/pantograph/actions/cloc.rb, line 78
def self.authors
  ['johnknapprs']
end
available_options() click to toggle source
# File pantograph/lib/pantograph/actions/cloc.rb, line 30
def self.available_options
  [
    PantographCore::ConfigItem.new(
      key: :binary_path,
      env_name: 'CLOC_BINARY_PATH',
      description: 'Where the cloc binary lives on your system (full path including "cloc")',
      optional: true,
      is_string: true,
      default_value: '/usr/local/bin/cloc'
    ),
    PantographCore::ConfigItem.new(
      key: :exclude_dir,
      env_name: 'CLOC_EXCLUDE_DIR',
      description: 'Comma separated list of directories to exclude',
      optional: true,
      is_string: true
    ),
    PantographCore::ConfigItem.new(
      key: :source_directory,
      env_name: 'CLOC_SOURCE_DIRECTORY',
      description: 'Starting point for Cloc analysis',
      is_string: true,
      default_value: '.'
    ),
    PantographCore::ConfigItem.new(
      key: :output_directory,
      env_name: 'CLOC_OUTPUT_DIRECTORY',
      description: 'Where to put the generated report file',
      is_string: true,
      default_value: 'pantograph/reports'
    ),
    PantographCore::ConfigItem.new(
      key: :output_type,
      env_name: 'CLOC_OUTPUT_TYPE',
      description: 'Output file type: xml, yaml, cvs, json',
      is_string: true,
      default_value: 'yaml'
    ),
    PantographCore::ConfigItem.new(
      key: :list_each_file,
      env_name: 'CLOC_LIST_EACH_FILE',
      description: 'List each individual file in cloc report',
      is_string: false,
      default_value: true
    )
  ]
end
category() click to toggle source
# File pantograph/lib/pantograph/actions/cloc.rb, line 99
def self.category
  :misc
end
description() click to toggle source
# File pantograph/lib/pantograph/actions/cloc.rb, line 19
def self.description
  'Generates a Code Count that can be read by Jenkins (xml format)'
end
details() click to toggle source
# File pantograph/lib/pantograph/actions/cloc.rb, line 23
def self.details
  [
    'This action will run cloc to generate a code count report',
    'See [https://github.com/AlDanial/cloc](https://github.com/AlDanial/cloc) for more information.'
  ].join("\n")
end
example_code() click to toggle source
# File pantograph/lib/pantograph/actions/cloc.rb, line 86
def self.example_code
  [
    '  # Generate JSON report of project code count
    cloc(
       exclude_dir: "build",
       source_directory: ".",
       output_directory: "pantograph/reports",
       output_type: "json"
    )
    '
  ]
end
is_supported?(platform) click to toggle source
# File pantograph/lib/pantograph/actions/cloc.rb, line 82
def self.is_supported?(platform)
  [:mac].include?(platform)
end
run(params) click to toggle source
# File pantograph/lib/pantograph/actions/cloc.rb, line 4
def self.run(params)
  output_type = params[:output_type]

  cloc_cmd = []
  cloc_cmd << params[:binary_path]
  cloc_cmd << params[:source_directory]
  cloc_cmd << "--exclude-dir=#{params[:exclude_dir]}" if params[:exclude_dir]
  cloc_cmd << '--by-file' if params[:list_each_file]
  cloc_cmd << "--#{output_type}"
  cloc_cmd << "--report-file=#{params[:output_directory]}/cloc.#{output_type}"
  cloc_cmd = cloc_cmd.join(' ').strip

  Actions.sh(cloc_cmd)
end