Skip to content

Instantly share code, notes, and snippets.

@le0pard
Created November 19, 2010 12:07
Show Gist options
  • Save le0pard/706435 to your computer and use it in GitHub Desktop.
Save le0pard/706435 to your computer and use it in GitHub Desktop.
Capistrano recipes for update GD after deploy
require "google_spreadsheet"
namespace :deploy do
desc "Notify GD"
task :gd_notify, :except => { :no_release => true } do
rails_env = fetch(:rails_env, "production")
local_user = ENV['USER'] || ENV['USERNAME']
local_branch = fetch(:branch, "HEAD")
SPECIAL_TOKEN = 'SpecialTokenForSearch'
#get git data
tag = {:rails_env => rails_env, :current_revision => current_revision, :repository => repository, :local_user => local_user, :local_branch => local_branch}
cmd = `git show --pretty='format:#{SPECIAL_TOKEN}|%H|%d|%cD|%ci|%ct|%an|%ae|%f' --no-notes #{current_revision}`
line = nil
cmd.each do |l|
if l.match(/^#{SPECIAL_TOKEN}/)
line = l.chomp
break
end
end
if line
line_array = line.split("|")
tag[:git_branch] = line_array[2]
tag[:date] = line_array[4]
tag[:unix_date] = line_array[5]
tag[:username] = line_array[6]
tag[:email] = line_array[7]
tag[:comment] = line_array[8]
end
# google docs
gd_index = case rails_env
when 'production'
2
when 'qa1'
3
when 'qa2'
4
when 'staging'
5
else # the else clause is optional
15
end
session = GoogleSpreadsheet.login("some_email@adility.com", "password")
ws = session.spreadsheet_by_key("tnegtLmukDCNnH8MXo96wcA").worksheets[0] # this take from url of google spreadsheet in "key" param
ws[1, 1] = "Deployed On"
ws[1, 2] = "Branch"
ws[1, 3] = "Time (deploy)"
ws[1, 4] = "Revision"
ws[1, 5] = "Revision link"
ws[1, 6] = "By"
ws[1, 7] = "Commiter (last)"
ws[1, 8] = "Last comment of commit"
ws[1, 9] = "Repository"
ws[gd_index, 1] = tag[:rails_env]
ws[gd_index, 2] = "#{tag[:local_branch]} - #{tag[:git_branch]}"
ws[gd_index, 3] = Time.now.strftime("%d.%m.%Y %H:%M")
ws[gd_index, 4] = tag[:current_revision]
ws[gd_index, 5] = "https://github.com/some_platform/tree/#{tag[:current_revision]}"
ws[gd_index, 6] = tag[:local_user]
ws[gd_index, 7] = "#{tag[:username]} (#{tag[:email]})"
ws[gd_index, 8] = tag[:comment]
ws[gd_index, 9] = tag[:repository]
ws.save()
puts "Google Docs Notification Complete."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment