cd /path/to/repo
ruby /path/to/docker_github_link.rb
Last active
June 2, 2016 12:18
-
-
Save sue445/10ddbff927e986d3d9a9f2fcda5d8258 to your computer and use it in GitHub Desktop.
Generate tag links for Docker Hub
This file contains 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
# Generate tag links for Docker Hub | |
# fetch remote branch | |
remote_branches = | |
`git branch -r`.lines.map(&:strip). | |
reject { |branch| branch.start_with?("origin/HEAD") }. | |
map { |branch| | |
branch.gsub(%r{^origin/([.\w]+)}) { Regexp.last_match[1] } | |
} | |
# generate GitHub link from remote url | |
fetch_line = `git remote -v`.lines.first | |
fetch_line =~ %r{git@github\.com:(.+)/(.+)\.git} | |
github_url = "https://github.com/#{Regexp.last_match[1]}/#{Regexp.last_match[2]}" | |
# generate markdown format links | |
content = | |
remote_branches.sort_by(&:itself).reverse.each_with_object("") do |branch, content| | |
tag = branch == "master" ? "latest" : branch | |
url = "#{github_url}/blob/#{branch}/Dockerfile" | |
content << "* `#{tag}` [(#{branch}/Dockerfile)](#{url})\n" | |
end | |
puts content |
latest
(master/Dockerfile)16.04
(16.04/Dockerfile)15.10
(15.10/Dockerfile)15.04
(15.04/Dockerfile)14.04.4
(14.04.4/Dockerfile)14.04.3
(14.04.3/Dockerfile)14.04.1
(14.04.1/Dockerfile)14.04
(14.04/Dockerfile)13.10
(13.10/Dockerfile)13.04
(13.04/Dockerfile)12.10
(12.10/Dockerfile)12.04.5
(12.04.5/Dockerfile)12.04
(12.04/Dockerfile)10.04
(10.04/Dockerfile)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment