Class: Slugforge::Commands::Tag
- Inherits:
-
SubCommand
- Object
- Thor
- Slugforge::Command
- SubCommand
- Slugforge::Commands::Tag
- Defined in:
- lib/slugforge/commands/tag.rb
Instance Method Summary collapse
- #clean ⇒ Object
- #clone(tag, new_tag) ⇒ Object
- #delete(tag) ⇒ Object
- #history(tag) ⇒ Object
- #list ⇒ Object
- #migrate ⇒ Object
- #set(tag, name_part) ⇒ Object
- #show(tag) ⇒ Object
Methods inherited from SubCommand
Methods inherited from Slugforge::Command
Methods included from Helper
Constructor Details
This class inherits a constructor from Slugforge::Command
Instance Method Details
#clean ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/slugforge/commands/tag.rb', line 5 def clean verify_project_name! = tag_manager.(project_name) .delete('production-current') bucket # initialize value before using threads logger.say_status :clean, "Reviewing #{.count} tags for #{project_name}", :cyan results = .parallel_map do |tag| begin slug_file = tag_manager.slug_for_tag(project_name, tag) if !slug_file.nil? && bucket.files.head(slug_file) logger.say '.', :green, false [tag, :valid] else if pretend? [tag, :pretend] else tag_manager.delete_tag(project_name, tag) logger.say '.', :red, false [tag, :deleted] end end rescue Excon::Errors::Forbidden logger.say '.', :yellow, false [tag, :forbidden] end end.sort {|a,b| b[1].to_s <=> a[1].to_s} logger.say results.each do |result| tag, status = result next if status == :valid logger.say_status status, tag, (status == :deleted) ? :red : :yellow end end |
#clone(tag, new_tag) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/slugforge/commands/tag.rb', line 43 def clone(tag, new_tag) verify_project_name! slug_name = tag_manager.slug_for_tag(project_name, tag) unless slug_name.nil? tag_manager.clone_tag(project_name, tag, new_tag) logger.say_json :project => project_name, :tag => new_tag, :slug => slug_name logger.say_status :set, "#{project_name} #{new_tag} to Slug #{slug_name}" true else logger.say_json :tag => tag, :exists => false logger.say_status :clone, "could not find existing tag #{tag} for project '#{project_name}'", :red false end end |
#delete(tag) ⇒ Object
135 136 137 138 139 140 141 142 143 144 |
# File 'lib/slugforge/commands/tag.rb', line 135 def delete(tag) verify_project_name! if [:yes] || (ask("Are you sure you wish to delete tag '#{tag}'? [Yn]").downcase != 'n') tag_manager.delete_tag(project_name, tag) logger.say_status :delete, "#{project_name} #{tag}" else logger.say_status :keep, "#{project_name} #{tag}" end end |
#history(tag) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/slugforge/commands/tag.rb', line 60 def history(tag) verify_project_name! slug_names = tag_manager.slugs_for_tag(project_name, tag) unless slug_names.empty? logger.say_json :project => project_name, :tag => tag, :slug_names => slug_names, :exists => true slug_names.each.with_index(0) do |slug_name, index| logger.say_status (index == 0 ? 'current' : "-#{index}"), slug_name, :yellow end else logger.say_json :tag => tag, :exists => false end end |
#list ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/slugforge/commands/tag.rb', line 75 def list verify_project_name! = tag_manager.(project_name) pc = .delete('production-current') if json? logger.say_json else logger.say "Tags for #{project_name}" logger.say_status :'production-current', tag_manager.slug_for_tag(project_name, 'production-current') unless pc.nil? tag_list = .parallel_map do |tag| [tag, tag_manager.slug_for_tag(project_name, tag)] end tag_list.sort {|a,b| b[1].to_s<=>a[1].to_s }.each do |tag, slug| logger.say_status tag, slug, :yellow end end end |
#migrate ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/slugforge/commands/tag.rb', line 97 def migrate = JSON.parse(bucket.files.get('projects.json').body) .each do |project, data| data['tags'].each do |tag, value| puts "create_tag(#{project}, #{tag}, #{value['s3']})" tag_manager.create_tag(project, tag, value['s3']) end end end |
#set(tag, name_part) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/slugforge/commands/tag.rb', line 122 def set(tag, name_part) verify_project_name! slug = find_slug(name_part) tag_manager.create_tag(project_name, tag, slug.key) logger.say_json :project => project_name, :tag => tag, :slug => slug.key logger.say_status :set, "#{project_name} #{tag} to Slug #{slug.key}" end |
#show(tag) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/slugforge/commands/tag.rb', line 108 def show(tag) verify_project_name! slug_name = tag_manager.slug_for_tag(project_name, tag) unless slug_name.nil? exists = !bucket.files.head(slug_name).nil? logger.say_json :project => project_name, :tag => tag, :slug_name => slug_name, :exists => exists logger.say_status tag, "#{slug_name} (#{exists ? "exists" : "missing"})", :yellow else logger.say_json :tag => tag, :exists => false end end |