Module: Dapp::Dapp::OptionTags

Included in:
Dapp::Dapp
Defined in:
lib/dapp/dapp/option_tags.rb

Instance Method Summary collapse

Instance Method Details

#branch_tagsObject

Raises:



33
34
35
36
37
# File 'lib/dapp/dapp/option_tags.rb', line 33

def branch_tags
  return {} unless options[:tag_branch]
  raise Error::Dapp, code: :git_branch_without_name if (branch = git_local_repo.branch) == 'HEAD'
  { git_branch: [branch] }
end

#build_tagsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dapp/dapp/option_tags.rb', line 44

def build_tags
  return {} unless options[:tag_build_id]

  if ENV['GITLAB_CI']
    build_id = ENV['CI_BUILD_ID']
  elsif ENV['TRAVIS']
    build_id = ENV['TRAVIS_BUILD_NUMBER']
  else
    raise Error::Dapp, code: :ci_environment_required
  end

  { ci: [build_id] }
end

#ci_tagsObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dapp/dapp/option_tags.rb', line 58

def ci_tags
  return {} unless options[:tag_ci]

  {}.tap do |tags_by_scheme|
    if ENV['GITLAB_CI']
      tags_by_scheme[:git_branch] = [ENV['CI_BUILD_REF_NAME']]
      tags_by_scheme[:git_tag]    = [ENV['CI_BUILD_TAG']]
    elsif ENV['TRAVIS']
      tags_by_scheme[:git_branch] = [ENV['TRAVIS_BRANCH']]
      tags_by_scheme[:git_tag]    = [ENV['TRAVIS_TAG']]
    else
      raise Error::Dapp, code: :ci_environment_required
    end

    tags_by_scheme.delete_if { |_, tags| tags.first.nil? }
  end
end

#commit_tagsObject



39
40
41
42
# File 'lib/dapp/dapp/option_tags.rb', line 39

def commit_tags
  return {} unless options[:tag_commit]
  { git_commit: [git_local_repo.latest_commit] }
end

#git_local_repoObject



4
5
6
# File 'lib/dapp/dapp/option_tags.rb', line 4

def git_local_repo
  @git_repo ||= ::Dapp::Dimg::GitRepo::Own.new(self)
end

#option_tagsObject



25
26
27
# File 'lib/dapp/dapp/option_tags.rb', line 25

def option_tags
  tags_by_scheme.values.flatten
end

#simple_tagsObject



29
30
31
# File 'lib/dapp/dapp/option_tags.rb', line 29

def simple_tags
  { custom: options[:tag] }
end

#tagging_schemesObject



8
9
10
# File 'lib/dapp/dapp/option_tags.rb', line 8

def tagging_schemes
  %w(git_tag git_branch git_commit custom ci)
end

#tags_by_schemeObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dapp/dapp/option_tags.rb', line 12

def tags_by_scheme
  @tags_by_scheme_name ||= begin
    [simple_tags, branch_tags, commit_tags, build_tags, ci_tags].reduce({}) do |some_tags_by_scheme, tags_by_scheme|
      tags_by_scheme.in_depth_merge(some_tags_by_scheme)
    end.tap do |tags_by_scheme|
      [:git_branch, :git_tag].each do |scheme|
        tags_by_scheme[scheme].map!(&method(:consistent_uniq_slugify)) unless tags_by_scheme[scheme].nil?
      end
      tags_by_scheme[:custom] = [:latest] if tags_by_scheme.values.flatten.empty?
    end
  end
end