class GetCloneData::ClonedRepo

Constants

CLONED_REPO_PATH

Attributes

repo_path[R]

Public Class Methods

clone(git_url:) click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 18
def self.clone(git_url:)
  repo_path = self.get_repo_path(git_url: git_url)
  `git clone --depth=1 #{git_url} #{repo_path}`
  return nil unless Dir.exists? repo_path
  new(repo_path: repo_path)
end
get_repo_path(git_url:) click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 33
def self.get_repo_path(git_url:)
  owner, repo = git_url.gsub('.git','').split('/')[3,4]
  File.expand_path(
    File.join(
      CLONED_REPO_PATH, owner, repo, itt.to_s
    )
  )
end
itt() click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 42
def self.itt
  @@itt = @@itt + 1
  @@itt
end
new(repo_path:) click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 14
def initialize(repo_path:)
  @repo_path = repo_path
end
wipe() click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 25
def self.wipe
  `rm -R -f #{CLONED_REPO_PATH}/*`
end

Public Instance Methods

get_flay_score() click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 70
def get_flay_score
  if Dir.exist? @repo_path
    flay = Flay.new
    flay.process(*ruby_files)
    flay.analyze
    flay = flay.summary.values.first
  end
  flay if flay
end
get_flog_scores() click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 55
def get_flog_scores
  if Dir.exist? @repo_path
    flog = Flog.new
    flog.flog(*ruby_files)
    #flog.calculate_total_score
    flog_response = {
      total_score: flog.total_score,
      max_score: flog.max_score,
      average: flog.average
    }
  end
  # reponse is an array of all the flog scores from total , ave, each method...
  flog_response if flog_response
end
get_loc() click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 88
def get_loc
  if Dir.exist? @repo_path
    loc_response = `cloc #{@repo_path}`
    if loc_response.empty?
      loc_response = nil
    else
      loc_response = loc_response.split('SUM').last.split("\n").first
        .split('    ')[2..5].map(&:to_f)
    end
  end
  loc_response
end
get_rubocop_errors() click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 80
def get_rubocop_errors
  if Dir.exist? @repo_path
    rubocop_response = `cd #{@repo_path} ; rubocop --format json`
    summary = JSON.parse(rubocop_response, :symbolize_names => true)[:summary]
    summary
  end
end
ruby_files() click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 47
def ruby_files
  return @ruby_files if @ruby_files

  path_rb_expander = PathExpander.new [@repo_path], "**/*.{rb,rake}"
  @ruby_files = path_rb_expander.process
  @ruby_files
end
wipe() click to toggle source
# File lib/getclonedata/getclonedata_clonerepo.rb, line 29
def wipe
  `rm -R -f #{@repo_path}`
end