class KnapsackPro::RepositoryAdapters::GitAdapter

Public Instance Methods

branch() click to toggle source
# File lib/knapsack_pro/repository_adapters/git_adapter.rb, line 10
def branch
  `git -C "#{working_dir}" rev-parse --abbrev-ref HEAD`.strip
end
branches() click to toggle source
# File lib/knapsack_pro/repository_adapters/git_adapter.rb, line 14
def branches
  str_branches = `git rev-parse --abbrev-ref --branches`
  str_branches.split("\n")
end
build_author() click to toggle source
# File lib/knapsack_pro/repository_adapters/git_adapter.rb, line 35
def build_author
  author = KnapsackPro::MaskString.call(git_build_author.strip)
  raise if author.empty?
  author
rescue Exception
  "no git <no.git@example.com>"
end
commit_authors() click to toggle source
# File lib/knapsack_pro/repository_adapters/git_adapter.rb, line 19
def commit_authors
  authors = git_commit_authors
    .split("\n")
    .map { |line| line.strip }
    .map { |line| line.split("\t") }
    .map do |commits, author|
      { commits: commits.to_i, author: KnapsackPro::MaskString.call(author) }
    end

  raise if authors.empty?

  authors
rescue Exception
  []
end
commit_hash() click to toggle source
# File lib/knapsack_pro/repository_adapters/git_adapter.rb, line 6
def commit_hash
  `git -C "#{working_dir}" rev-parse HEAD`.strip
end

Private Instance Methods

git_build_author() click to toggle source
# File lib/knapsack_pro/repository_adapters/git_adapter.rb, line 60
def git_build_author
  `git log --format="%aN <%aE>" -1 2>/dev/null`
end
git_commit_authors() click to toggle source
# File lib/knapsack_pro/repository_adapters/git_adapter.rb, line 45
def git_commit_authors
  if KnapsackPro::Config::Env.ci? && shallow_repository?
    command = 'git fetch --shallow-since "one month ago" --quiet 2>/dev/null'
    begin
      Timeout.timeout(5) do
        `#{command}`
      end
    rescue Timeout::Error
      KnapsackPro.logger.debug("Skip the `#{command}` command because it took too long.")
    end
  end

  `git log --since "one month ago" 2>/dev/null | git shortlog --summary --email 2>/dev/null`
end
shallow_repository?() click to toggle source
# File lib/knapsack_pro/repository_adapters/git_adapter.rb, line 64
def shallow_repository?
  result = `git rev-parse --is-shallow-repository 2>/dev/null`
  result.strip == 'true'
end
working_dir() click to toggle source
# File lib/knapsack_pro/repository_adapters/git_adapter.rb, line 69
def working_dir
  dir = KnapsackPro::Config::Env.project_dir
  File.expand_path(dir)
end