Skip to content

Instantly share code, notes, and snippets.

@iconnor
Created November 4, 2011 20:28
Show Gist options
  • Save iconnor/1340400 to your computer and use it in GitHub Desktop.
Save iconnor/1340400 to your computer and use it in GitHub Desktop.
Notify github issues when you deploy from master
# To do this, we call this from the deployment rake task:
DEPLOY_TAG = 'last-deploy'
# Tag & comment new issues that have been deployed
previous_deploy, current_deploy, issues = deploy_issues
#which calls this method:
def deploy_issues
update_branch('master')
`git tag -d #{DEPLOY_TAG}`
`git fetch origin tag #{DEPLOY_TAG}`
issues = []
previous_deploy = `git rev-parse #{DEPLOY_TAG}`.strip
current_deploy = `git rev-parse HEAD`.strip
deploy_message = "Deployed on #{Time.now.strftime('%m/%d/%Y at %r')}"
`git tag -f -a -m '#{deploy_message}' #{DEPLOY_TAG} #{current_deploy}`
`git push --tags`
logs = `git log --pretty=oneline #{previous_deploy}..#{current_deploy}`.split("\n")
logs.each do |log|
if m = log.match(/(\w*).*fix(es)?\s*#(\d+)/i)
issues << m[3]
end
end
Rake::Task["github:deploy_issues"].invoke(issues.uniq.join(','), deploy_message) if issues.present?
[previous_deploy, current_deploy, issues]
end
#which calls this rake task:
desc "Deploy issues"
task :deploy_issues, :issues, :message, :needs => :environment do |t, args|
issues = args[:issues].split(',')
message = args[:message]
http = Net::HTTP.new('api.github.com',443)
http.use_ssl = true
issues.each do |issue|
# Add a Deploy tag to the issue
req = Net::HTTP::Post.new("/repos/[organization]/[project]/issues/#{issue}/labels")
req.basic_auth 'username', 'password'
req.body = ["Deployed"].to_json
response = http.request(req)
# Add a deploy comment to the issue
req = Net::HTTP::Post.new("/repos/[organization]/[project]/issues/#{issue}/comments")
req.basic_auth 'username', 'password'
req.body = {:body => message}.to_json
response = http.request(req)
results = JSON.parse(response.body)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment