Skip to content

Instantly share code, notes, and snippets.

@bchase
Created December 24, 2014 01:09
Show Gist options
  • Save bchase/6af6153cb52063a75326 to your computer and use it in GitHub Desktop.
Save bchase/6af6153cb52063a75326 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class Deploy
def self.all(remote='staging')
releases_txt = `heroku releases -r #{remote}`
app_txt, *release_strs = releases_txt.split("\n")
app, remote = app_txt[/===\s+(\S+)/, 1], remote
deploy_strs = release_strs.select {|str| str =~ /^v\d+\s+Deploy/}
deploys = deploy_strs.map {|deploy_str| Deploy.new deploy_str, app, remote}
deploys.reverse
end
# version SHA time
RE = %r{^(v\d+)\s+Deploy\s+(\h+)\s+\S+\s+(.+)}
def initialize(deploy_str, app, remote)
@app, @remote = app, remote
_, @version, @sha, @time = *deploy_str.match(RE)
end
attr_reader :version, :sha, :time, :app, :remote
def commit
Git::Commit.new sha
end
def app_str
"\napp #{app} (remote #{remote})\n\n"
end
end
module Git
class Commit
def initialize(sha)
@sha = sha
@show = `git show #{sha}`[%r{(.+)\n\ndiff}m, 1]
@branch = `git branch --contains #{sha}`[%r{\* (.+)}, 1]
end
attr_reader :sha, :show, :branch
def details
"branch #{branch}\n#{show}\n\n\n"
end
end
end
remote = ARGV[0] || 'staging'
deploys = Deploy.all remote
deploy = deploys.last
puts deploy.app_str
puts deploy.commit.details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment