Class: Scc::DeployInfo::Extractor::Git

Inherits:
Dummy
  • Object
show all
Defined in:
lib/scc/deploy_info/extractor/git.rb

Defined Under Namespace

Classes: NotAGitRootError

Constant Summary collapse

GIT_SHOW_SEPARATOR =
"|-*-|"
GIT_SHOW_FORMAT =
%w[%D %H %s %aI].join(GIT_SHOW_SEPARATOR).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: ".") ⇒ Git



18
19
20
# File 'lib/scc/deploy_info/extractor/git.rb', line 18

def initialize(root: ".")
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



16
17
18
# File 'lib/scc/deploy_info/extractor/git.rb', line 16

def root
  @root
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/scc/deploy_info/extractor/git.rb', line 22

def call
  parts = Dir.chdir(root) do
    IO.popen(git_show_command, err: "/dev/null", &:read).strip.split(GIT_SHOW_SEPARATOR)
  end

  raise NotAGitRootError, "'#{root}' is not a git repo" unless $CHILD_STATUS.success?

  deploy_ref, commit_sha, commit_subject, commit_date = parts
  deploy_ref = deploy_ref.split(" ")[2].to_s.tr(",", "")

  commit_date = Utils.try_parse_date(commit_date)

  super.merge({
    deploy_ref: deploy_ref,
    commit_sha: commit_sha,
    commit_date: commit_date,
    commit_subject: commit_subject,
    origin: :git
  }.compact)
rescue Errno::ENOENT
  raise NotAGitRootError, "git root not found at '#{root}'"
end