Class: KnapsackPro::RepositoryAdapters::GitAdapter

Inherits:
BaseAdapter
  • Object
show all
Defined in:
lib/knapsack_pro/repository_adapters/git_adapter.rb

Instance Method Summary collapse

Instance Method Details

#branchObject



10
11
12
# File 'lib/knapsack_pro/repository_adapters/git_adapter.rb', line 10

def branch
  `git -C "#{working_dir}" rev-parse --abbrev-ref HEAD`.strip
end

#branchesObject



14
15
16
17
# 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_authorObject



35
36
37
38
39
40
41
# 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_authorsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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_hashObject



6
7
8
# File 'lib/knapsack_pro/repository_adapters/git_adapter.rb', line 6

def commit_hash
  `git -C "#{working_dir}" rev-parse HEAD`.strip
end