Skip to content

Instantly share code, notes, and snippets.

@bmidgley
Last active June 27, 2019 19:58
Show Gist options
  • Save bmidgley/8c014cf3f3a4be787a0a8067ec87aaa3 to your computer and use it in GitHub Desktop.
Save bmidgley/8c014cf3f3a4be787a0a8067ec87aaa3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'getoptlong'
require 'tty/tree'
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--brief', '-b', GetoptLong::NO_ARGUMENT ],
)
verbose = true
opts.each do |opt, arg|
case opt
when '--help'
puts <<-EOF
INST_CRED=user:pass what-is-staged.rb [branch_name]
-h, --help:
show help
--brief, -b:
show only top-level branch names that are staged
EOF
exit
when '--brief'
verbose = false
end
end
if verbose
puts "\nfetching..."
`git fetch`
puts "\ncalculating..."
else
`git fetch >/dev/null 2>&1`
end
def unmerged_branches(branch)
`git branch -r --no-merged origin/#{branch}`.split("\n").map(&:strip).map{|m| m.gsub('origin/','')}
end
def staged_by(branch)
@contained[branch] ||= begin
unstaged_branches = unmerged_branches(branch)
staged = @all_unmerged_branches - unstaged_branches - [branch]
contained_branches = []
staged.map do |staged_branch|
contained_branches += staged_by(staged_branch)
end
staged - contained_branches
end
end
def tree_from(branch)
{ branch => @contained[branch].map{|n| tree_from(n) } }
end
staging_branch_name = ARGV[0] || "staging1_rc"
@contained = {}
@all_unmerged_branches = unmerged_branches("master")
staged = staged_by(staging_branch_name)
if verbose
url = case staging_branch_name
when "staging1_rc" then "https://app.staging1.mavenlink.net/version.txt"
else "https://app.#{staging_branch_name.split("_rc").first}.mvn.link/version.txt"
end
version = `curl --user #{ENV["INST_CRED"]} #{url} 2>/dev/null`.strip
commit = `git rev-parse origin/#{staging_branch_name}`.strip
puts "#{staging_branch_name} is now on commit #{commit}"
puts "version on #{url} is #{version}"
puts
data = tree_from(staging_branch_name)
tree = TTY::Tree.new(data)
puts tree.render
exit version == commit
else
puts "#{staged.join("\n")}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment