Created
September 6, 2010 02:10
-
-
Save fujimura/566541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
require 'httparty' | |
class RemoteRedmine | |
include HTTParty | |
def initialize(cap) | |
raise ArgumentError, 'Please set your redmine settings' if !cap[:redmine] | |
self.class.base_uri cap[:redmine][:url] | |
self.class.default_params :key => cap[:redmine][:access_key] | |
end | |
def get_issue_subject(issue_id) | |
res = self.class.get("/issues/#{issue_id}.json").parsed_response | |
res ? res['subject'] : '(no issue found with this id)' | |
end | |
def update_issue(issue_id, issue) | |
self.class.put("/issues/#{issue_id}.json", :query => {:issue => issue}) | |
end | |
end | |
if Object.const_defined?("Capistrano") | |
Capistrano::Configuration.instance(:must_exist).load do | |
namespace :redmine do | |
desc 'update issue status of redmine with your deployment, by #nnn in commit comments.' | |
task :update_issue_status, :roles => :app do | |
unless previous_revision == current_revision | |
rm = RemoteRedmine.new(self) | |
issues = `git log #{previous_revision}..#{current_revision}`.grep(/(fixes|refs) #([0-9]*)/){$2}.flatten | |
puts '' | |
puts ' ------------------------------------------------------------' | |
puts ' ** deployed tickets ** ' | |
puts ' ------------------------------------------------------------' | |
issues.each do |issue_id| | |
rm.update_issue(issue_id, :status_id => self[:redmine][:deployed]) | |
puts " * ##{issue_id.to_s}: #{rm.get_issue_subject(issue_id)}" | |
end | |
puts '' | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment