Module: Avm::EacWebappBase0::Instances::Deploy::Scm

Defined in:
lib/avm/eac_webapp_base0/instances/deploy/scm.rb

Constant Summary collapse

DEFAULT_REMOTE_NAME =
'origin'
DEFAULT_REMOTE_READ =
true
DEFAULT_REMOTE_WRITE =
true

Instance Method Summary collapse

Instance Method Details

#commit_reference_uncachedObject

Raises:

  • (::Avm::Result::Error)


12
13
14
15
16
17
18
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 12

def commit_reference_uncached
  git_fetch
  r = git.rev_parse(git_reference_found)
  return r if r

  raise ::Avm::Result::Error, "No commit SHA1 found for \"#{git_reference_found}\""
end

#git_fetch_uncachedObject



20
21
22
23
24
25
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 20

def git_fetch_uncached
  return unless remote_read?

  infom "Fetching remote \"#{git_remote_name}\" from \"#{git_repository_path}\"..."
  git.remote(git_remote_name).fetch
end

#git_referenceObject



27
28
29
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 27

def git_reference
  options[OPTION_REFERENCE] || DEFAULT_REFERENCE
end

#git_reference_found_uncachedObject



31
32
33
34
35
36
37
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 31

def git_reference_found_uncached
  %w[git_reference instance_branch master_branch].map { |b| send(b) }.find(&:present?) ||
    raise(
      ::Avm::Result::Error,
      'No git reference found (Searched for option, instance and master)'
    )
end

#git_remote_hashs_uncachedObject



39
40
41
42
43
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 39

def git_remote_hashs_uncached
  return {} unless remote_read?

  git.remote(git_remote_name).ls.hashes
end

#git_remote_nameObject



45
46
47
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 45

def git_remote_name
  DEFAULT_REMOTE_NAME
end

#git_repository_pathObject



49
50
51
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 49

def git_repository_path
  instance.source_instance.read_entry(::Avm::Instances::EntryKeys::INSTALL_PATH)
end

#git_uncachedEacGit::Local

Returns:

  • (EacGit::Local)


54
55
56
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 54

def git_uncached
  scm.git_repo
end

#instance_branchObject



58
59
60
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 58

def instance_branch
  remote_branch(instance.id)
end

#master_branchObject



66
67
68
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 66

def master_branch
  remote_branch('master')
end

#remote_branch(name) ⇒ Object



62
63
64
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 62

def remote_branch(name)
  git_remote_hashs.key?("refs/heads/#{name}") ? "#{git_remote_name}/#{name}" : nil
end

#remote_read?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 71

def remote_read?
  options.if_key(OPTION_REMOTE_READ, DEFAULT_REMOTE_READ).to_bool
end

#remote_write?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 76

def remote_write?
  options.if_key(OPTION_REMOTE_WRITE, DEFAULT_REMOTE_WRITE).to_bool
end

#scmAvm::Scms::Base

Returns:

  • (Avm::Scms::Base)


81
82
83
# File 'lib/avm/eac_webapp_base0/instances/deploy/scm.rb', line 81

def scm
  instance.application.local_source.scm
end