Module: Capistrano::Faucet::Utilities

Defined in:
lib/capistrano/faucet/utilities.rb

Instance Method Summary collapse

Instance Method Details

#available_releasesObject



49
50
51
52
53
# File 'lib/capistrano/faucet/utilities.rb', line 49

def available_releases
  puts "\nAvailable Releases:".color :green
  puts "#{releases.reverse.take(Capistrano::Faucet::Configuration.previous_releases.to_i).join("\n")}"
  puts "\n"
end

#available_tagsObject



43
44
45
46
47
# File 'lib/capistrano/faucet/utilities.rb', line 43

def available_tags
  puts "Available Tags:".color :green
  puts "#{releases.sort.reverse.take(Capistrano::Faucet::Configuration.previous_releases.to_i).join("\n")}"
  puts "\n"
end


55
56
57
58
59
60
# File 'lib/capistrano/faucet/utilities.rb', line 55

def banner

  <<-BANNER
\n Faucet for Gitflow
  BANNER
end

#branchesObject



27
28
29
# File 'lib/capistrano/faucet/utilities.rb', line 27

def branches
 `git branch --no-color`.split("\n")
end

#current_branchObject



23
24
25
# File 'lib/capistrano/faucet/utilities.rb', line 23

def current_branch
  branches.select{|b| b =~ /^\*\s/}.first.gsub(/^\*\s/,"")
end

#deploy_fromObject



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/capistrano/faucet/utilities.rb', line 64

def deploy_from
  puts banner unless Capistrano::Faucet::Configuration.prude.to_i == 1
  if fetch(:stage) == :production
    available_releases
    set :from_destination, ask("\nRelease to deploy:".color(:yellow).bright, latest_release)
  else
    set :create_tag, ask("\nDo you want to tag deployment?".color(:yellow).bright, 'N')
    return next_tag if fetch(:create_tag).downcase =~ /^[Yy]$/
    available_tags
    set :from_destination, ask("\nBranch, tag or release to deploy:".color(:yellow).bright, current_branch)
  end
  return fetch(:from_destination)
end

#latest_releaseObject



39
40
41
# File 'lib/capistrano/faucet/utilities.rb', line 39

def latest_release
  releases.reverse.first.to_s
end

#next_tagObject



78
79
80
81
82
83
84
85
# File 'lib/capistrano/faucet/utilities.rb', line 78

def next_tag
  hwhen   = Date.today.to_s
  set :what, ask("\nWhat does this release introduce?".color(:yellow).bright, nil)
  new_staging_tag = "#{hwhen}-#{who}-#{fetch(:what)}"
  puts "Tagging current branch for deployment to staging as '#{new_staging_tag}'".color(:green)
  system "git tag -a -m 'tagging current code for deployment to staging' #{new_staging_tag}"
  return new_staging_tag
end

#non_release_tagsObject



19
20
21
# File 'lib/capistrano/faucet/utilities.rb', line 19

def non_release_tags
  tags - releases 
end

#releasesObject



35
36
37
# File 'lib/capistrano/faucet/utilities.rb', line 35

def releases
  tags.select{|t| t =~ /^#{version_tag_prefix}(\d+)/}.collect{|version| Versionomy.parse(version) }.sort
end

#tagsObject



15
16
17
# File 'lib/capistrano/faucet/utilities.rb', line 15

def tags
  `git tag`.split("\n").compact
end

#using_git?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/capistrano/faucet/utilities.rb', line 87

def using_git?
  fetch(:scm, :git).to_sym == :git
end

#version_tag_prefixObject



31
32
33
# File 'lib/capistrano/faucet/utilities.rb', line 31

def version_tag_prefix
  `git config gitflow.prefix.versiontag`.split("\n").first
end

#whoObject



10
11
12
13
# File 'lib/capistrano/faucet/utilities.rb', line 10

def who
  identity = (`git config user.name` || `whoami`)
  identity.chomp.to_url
end