class Object

Public Instance Methods

language_stats(path) click to toggle source
# File bin/project-report, line 51
def language_stats(path)
  repo = Rugged::Repository.new(path)
  Linguist::Repository.new(repo, repo.head.target_id)
end
parse_options() click to toggle source
# File bin/project-report, line 7
def parse_options
  ARGV.push('-h') if ARGV.empty?
  options = { :name => "",
              :tags => "",
  }
  OptionParser.new do |opts|
    opts.banner = "Generate statistics about project, such as used languages, row counts and dependencies.
  Usage: project-report [options] -r<paths to git repository in local directory>

  Example: ./project-report -r . -n\"Project Report\" --tags=\"OSS,Reporting\"

  Options:
"

    opts.on("-oFILE", "--output-file=FILE", "Write output to this file. Otherwise to STDOUT") do |o|
      options[:output] = o
    end
    opts.on("-nNAME", "--project-name=NAME", "Project name, will be prompted if not set") do |name|
      options[:name] = name
    end
    opts.on("-tTAGS", "--tags=TAGS", Array, "Tags for project. This can be things as business area, open source etc... Will be prompted if not set") do |tags|
      options[:tags] = tags
    end
    opts.on("-h", "--help", "Show this message") do
      puts opts
      exit
    end
    opts.on("-rX,Y,Z --repos=X,Y,Z", Array, "Comma separated list of repository paths to scan. All repositories are assumed to be under the same project") do |list|
      options[:repos] = list
      options[:repos].each do |repo|
        raise "#{repo} must be a git directory" unless File.directory?("#{repo}/.git")
      end
    end
  end.parse!

  mandatory = [:repos]
  missing = mandatory.select { |param| options[param].nil? }
  unless missing.empty?
    raise OptionParser::MissingArgument.new(missing.join(', ')) #
  end

  options
end
repo_stats(repo_path) click to toggle source
# File bin/project-report, line 68
def repo_stats(repo_path)
  stats = language_stats(repo_path)
  files = stats.repository.index.map { |h| h[:path] }
  scans = scan_package_manager_data(repo_path, files)
  {
    "path" => repo_path,
    "languages" => stats.languages,
    "subprojects" => scans.map { |scan|
      {
        "platform" => scan[:platform],
        "path" => scan[:path],
        "dependencies" => scan[:dependencies].map { |dep|
          {
            "name" => dep[:name],
            "type" => dep[:type].to_s,
            "requirement" => dep[:requirement]
          }
        }
      }
    }
  }
end
scan_package_manager_data(root, paths) click to toggle source

Scan Package manager data

# File bin/project-report, line 57
def scan_package_manager_data(root, paths)
  manifests = Bibliothecary.identify_manifests(paths)
  project_analyses = manifests.flat_map do |manifest|
    Bibliothecary.analyse_file("#{root}/#{manifest}", File.open("#{root}/#{manifest}").read)
  end
  project_analyses.filter do |analysis|
    # TODO flag for lockfile data? Drop them for now
    analysis[:kind] != "lockfile"
  end
end