Created
May 21, 2009 18:44
-
-
Save mhorbul/115626 to your computer and use it in GitHub Desktop.
Clean up the remote branches according to the Unfuddle Reports
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
# Maksim Horbul | |
# | |
# clean up the remote branches according to the Unfuddle Reports | |
# | |
require 'rubygems' | |
require 'feed-normalizer' | |
require 'net/http' | |
require 'net/https' | |
class UnfuddleReport | |
@@url_host = "sonian.unfuddle.com" | |
@@url_path = "/projects/%d/ticket_reports/%d/generate.rss?aak=%s&pak=%s" | |
def self.parse(id, options) | |
xml = self.new(id, options[:project_id], options[:aak], options[:pak]).to_xml | |
FeedNormalizer::FeedNormalizer.parse xml | |
end | |
def initialize(report_id, project_id, aak, pak) | |
@uri = sprintf(@@url_path, project_id, report_id, aak, pak) | |
end | |
def to_xml | |
http = Net::HTTP.new(@@url_host, 443) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
http.get(@uri.strip, nil).body | |
end | |
end | |
aak="-- PUT YOUR AAK HERE --" | |
pak="-- PUT YOUR PAK HERE --" | |
project_id = "-- PUT PROJECT ID HERE --" | |
report_ids = %w(260721 234386 260722) # <<< CHANGE THIS NUMBERS IF NEEDED | |
should_be_deleted = report_ids.map do |report_id| | |
report = UnfuddleReport.parse(report_id, :project_id => project_id, :aak => aak, :pak => pak) | |
report.items.map { |item| item.title.gsub(/#(\d+).*/, "\\1").to_i } unless report.nil? | |
end.flatten | |
`git br -r | grep origin`.to_s.split("\n"). | |
map do |branch| | |
bid=branch.to_s.gsub(/origin\/(\d+)\-.*/, "\\1").to_i | |
bid > 0 ? {:id => bid, :name => branch.gsub(/origin\//, "").strip} : nil | |
end.compact.select do |branch| | |
if should_be_deleted.include?(branch[:id]) | |
puts `git push origin :#{branch[:name]}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment