Created
December 8, 2011 17:17
-
-
Save tomkersten/1447681 to your computer and use it in GitHub Desktop.
[Hacky script that] Pulls tickets from a chiliproject/redmine installation & dumps them to STDOUT. Works fine/well with @teddziuba's fork of hubot (https://github.com/teddziuba/hubot)
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'httparty' | |
class Issue | |
BASE_URI = "http://your-chiliproject-uri-here/issues" | |
CHILI_API_KEY = ENV["HUBOT_CHILIPROJECT_API_KEY"] || raise("You must set the 'HUBOT_CHILIPROJECT_API_KEY' environment variable!") | |
include HTTParty | |
base_uri BASE_URI | |
format :json | |
def initialize(options = {}) | |
@number = options['id'] | |
@subject = options['subject'] | |
@project_name = options['project'] && options['project']['name'] | |
end | |
def self.find(number) | |
begin | |
result = get("/#{number}.json", {:query => {:key => CHILI_API_KEY}}) | |
result.success? ? new(result.parsed_response['issue']) : nil | |
rescue MultiJson::DecodeError | |
return nil | |
end | |
end | |
def summary | |
"##{@number}: #{@subject} [#{@project_name}] -- #{url}" | |
end | |
def url | |
"#{BASE_URI}/#{@number}" | |
end | |
private :url | |
end | |
ticket_numbers = ARGV[0].scan(/#(\d+)/).flatten | |
exit(0) if ticket_numbers.empty? | |
# pull the info from chili | |
ticket_numbers.each do |ticket_number| | |
issue = Issue.find(ticket_number) | |
if issue.nil? | |
puts "##{ticket_number}: Unable to find information on ticket ##{ticket_number}" | |
else | |
puts issue.summary | |
end | |
end | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the string has #70 it will dump a summary of the issue into campfire with a direct link to it...