Module: Capistrano::Tampon::Utilities

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

Instance Method Summary collapse

Instance Method Details

#available_releasesObject



48
49
50
51
# File 'lib/capistrano/tampon/utilities.rb', line 48

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

#available_tagsObject



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

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


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/capistrano/tampon/utilities.rb', line 53

def banner

  <<-BANNER
\nTampon for Gitflow
  ,-------------.
 (o) _ __ _____  )--.
  `-------------'    )
            (     /
             `---'
  BANNER
end

#branchesObject



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

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

#current_branchObject



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

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

#deploy_fromObject



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/capistrano/tampon/utilities.rb', line 67

def deploy_from
  puts banner unless Capistrano::Tampon::Configuration.prude.to_i == 1
  if stage == :production
    available_releases
    from_destination = ask("\nRelease to deploy:".color(:yellow).bright, lastest_release)
  else
    create_tag = ask("Do you want to tag deployment? [y/N]".color(:yellow), 'N')
    return next_tag if create_tag
    available_tags
    from_destination = ask "\nBranch, tag or release to deploy:".color(:yellow).bright, current_branch
  end
  return from_destination
end

#latest_releaseObject



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

def latest_release
  releases.reverse.first.to_s
end

#next_tagObject



81
82
83
84
85
86
87
88
# File 'lib/capistrano/tampon/utilities.rb', line 81

def next_tag
  hwhen   = Date.today.to_s
  what = ask("What does this release introduce? (this will be normalized and used in the tag for this release)".color(:yellow)).to_url
  new_staging_tag = "#{hwhen}-#{who}-#{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/tampon/utilities.rb', line 19

def non_release_tags
  tags - releases 
end

#releasesObject



35
36
37
# File 'lib/capistrano/tampon/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/tampon/utilities.rb', line 15

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

#using_git?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/capistrano/tampon/utilities.rb', line 90

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

#version_tag_prefixObject



31
32
33
# File 'lib/capistrano/tampon/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/tampon/utilities.rb', line 10

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