Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some deploy tracking on top of git-notes

  • Loading branch information...
commit 147e781d5560177ab31c3c7b1c6f2fda4feaccd9 0 parents
@halorgium authored
Showing with 124 additions and 0 deletions.
  1. +12 −0 add_notes
  2. +103 −0 notes.rb
  3. +9 −0 show_notes
12 add_notes
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+
+$:.unshift File.dirname(__FILE__)
+require 'notes'
+
+c = Commit.new("HEAD")
+c.add_deploy("http://deployer.local/22", "2010-08-26T08:29:54Z", "halorgium")
+c.add_deploy("http://deployer.local/20", "2010-08-26T07:29:54Z", "sr")
+
+c = Commit.new("HEAD^")
+c.add_deploy("http://deployer.local/18", "2010-08-24T08:29:54Z", "sr")
+c.add_deploy("http://deployer.local/12", "2010-08-24T07:29:54Z", "halorgium")
103 notes.rb
@@ -0,0 +1,103 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'pathname'
+require 'time'
+require 'pp'
+
+class Commit
+ def initialize(sha1)
+ @sha1 = sha1
+ end
+
+ def add_deploy(url, timestamp, user)
+ return if deploy?(url)
+
+ puts "adding #{url}, #{timestamp}, #{user} to #{@sha1}"
+
+ dir = Pathname.new(`gmktemp -d`.chomp)
+ note_file = dir.join("note")
+
+ File.open(note_file, "w") do |f|
+ f.puts "Deploy-Url: #{url}"
+ f.puts "Deployed-At: #{timestamp}"
+ f.puts "Deployed-By: #{user}"
+ end
+
+ unless system("#{deploys_prefix} append -F #{note_file} #{@sha1}")
+ raise "Could not save deploy #{url} for #{@sha1}"
+ end
+ end
+
+ def deploy?(url)
+ deploy_urls.include?(url)
+ end
+
+ def deploy_urls
+ deploys.map do |d|
+ d.url
+ end
+ end
+
+ def deploys?
+ system("#{deploys_cmd} 2>/dev/null >/dev/null")
+ end
+
+ def deploys
+ if deploys?
+ output = `#{deploys_cmd}`.chomp
+ output.split("\n\n").map do |lines|
+ Deploy.parse(self, lines)
+ end
+ else
+ []
+ end
+ end
+
+ def deploys_cmd
+ "#{deploys_prefix} show #{@sha1}"
+ end
+
+ def deploys_prefix
+ "git notes --ref deploys"
+ end
+
+ def system(*args)
+ pp args
+ super
+ end
+end
+
+
+class Deploy
+ def self.parse(commit, lines)
+ url = nil
+ timestamp = nil
+ user = nil
+ lines.each do |line|
+ case line
+ when /^Deploy-Url: (.*)$/
+ url = $1
+ when /^Deployed-At: (.*)$/
+ timestamp = $1
+ when /^Deployed-By: (.*)$/
+ user = $1
+ else
+ raise "Unknown line: #{line.inspect}"
+ end
+ end
+ new(commit, url, timestamp, user)
+ end
+
+ def initialize(commit, url, timestamp, user)
+ @commit = commit
+ @url = url
+ @timestamp = timestamp
+ @user = user
+ end
+ attr_reader :commit, :url, :timestamp, :user
+
+ def time
+ Time.parse(@timestamp)
+ end
+end
9 show_notes
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+
+$:.unshift File.dirname(__FILE__)
+require 'notes'
+
+c = Commit.new("HEAD")
+c.deploys.each do |d|
+ pp d.time
+end
Please sign in to comment.
Something went wrong with that request. Please try again.