Last active
December 27, 2015 14:59
-
-
Save colinrymer/7343964 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def tag_to_deploy | |
| Capistrano::CLI.ui.choose do |menu| | |
| menu.choices *last_ten_tags | |
| menu.header = "Available tags" | |
| menu.prompt = "Tag to deploy?" | |
| menu.select_by = :index_or_name | |
| end | |
| end | |
| def last_ten_tags | |
| tags = `git tag`.split("\n") | |
| sorted_tags = tags.sort_by{ |version| version.split('.').map{ |version_level| version_level[/\d+/].to_i } } | |
| sorted_tags.last(10) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def tag_to_deploy | |
| Capistrano::CLI.ui.choose do |menu| | |
| menu.choices *last_ten_tags | |
| menu.header = "Available tags" | |
| menu.prompt = "Tag to deploy?" | |
| menu.select_by = :index_or_name | |
| end | |
| end | |
| def last_ten_tags | |
| tags = `git tag`.split("\n") | |
| sorted_tags = tags.sort_by{ |version| version_as_array(version) } | |
| sorted_tags.last(10) | |
| end | |
| def version_as_array(version) | |
| version.split('.').map{ |version_level| version_level[/\d+/].to_i } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def tag_to_deploy | |
| require_annotated = /refs\/tags\/(v.+\^\{\})$/ | |
| all_version_tags = `git ls-remote --tags #{repository}`.scan(require_annotated).flatten | |
| sorted_version_tags = all_version_tags.sort_by{|v| v.split('.').map{|nbr| nbr[/\d+/].to_i}} | |
| stripped_version_tags = sorted_version_tags.map{|tag| tag.strip} | |
| puts "stripped_version_tags: #{stripped_version_tags.class}" | |
| last_x_tags = [] | |
| if stripped_version_tags.size > 10 | |
| last_x_tags = stripped_version_tags[-10..-1] | |
| puts "last_ten_tags: #{last_x_tags}" | |
| else | |
| max = stripped_version_tags.size | |
| last_x_tags = stripped_version_tags[-max..-1] | |
| puts "last_ten_tags: #{last_x_tags}" | |
| end | |
| tag = Capistrano::CLI.ui.choose { |menu| | |
| menu.choices *last_x_tags | |
| menu.header = "Available tags" | |
| menu.prompt = "Tag to deploy?" | |
| menu.select_by = :index_or_name | |
| } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually... you might not need version as array - could you do this?