|
| 1 | +require 'xmlrpc/client' |
| 2 | +require 'pp' |
| 3 | +require 'set' |
| 4 | + |
| 5 | +# Simple script to scan all JRuby's rubyspec tags |
| 6 | +# and report invalid ones, i.e. those that have |
| 7 | +# references to already resolved/closed bugs. |
| 8 | + |
| 9 | +if ARGV.size != 2 |
| 10 | + puts "Usage: tags_verify.rb jira-login jira-password" |
| 11 | + exit 1 |
| 12 | +end |
| 13 | + |
| 14 | +class JiraVerifier |
| 15 | + INVALID_STATUSES = {"5"=>"Resolved", "6"=>"Closed"} |
| 16 | + def initialize(login, pass) |
| 17 | + @server = XMLRPC::Client.new('jira.codehaus.org', "/rpc/xmlrpc") |
| 18 | + @auth = @server.call("jira1.login", login, pass) |
| 19 | + @stat_info = {} |
| 20 | + @server.call("jira1.getStatuses", @auth).each { |s| |
| 21 | + @stat_info[s["id"]] = s["name"] |
| 22 | + } |
| 23 | + # pp @stat_info |
| 24 | + end |
| 25 | + def get_issue(id) |
| 26 | + @server.call("jira1.getIssue", @auth, id) |
| 27 | + end |
| 28 | + def get_status(issue) |
| 29 | + issue["status"] |
| 30 | + end |
| 31 | + def is_valid(issue) |
| 32 | + INVALID_STATUSES[get_status(issue)].nil? |
| 33 | + end |
| 34 | + def check_ids(ids) |
| 35 | + ids.each { |id, files| |
| 36 | + issue = get_issue(id) |
| 37 | + unless (is_valid(issue)) |
| 38 | + puts "#{id} -- Wrong State: #{@stat_info[get_status(issue)]}. Used in the following tag files:" |
| 39 | + files.each { |filename| |
| 40 | + puts " - #{filename}" |
| 41 | + } |
| 42 | + end |
| 43 | + } |
| 44 | + end |
| 45 | + def logout |
| 46 | + @server.call("jira1.logout", @auth) |
| 47 | + end |
| 48 | +end |
| 49 | + |
| 50 | +TAGS_DIR = File.expand_path(File.join(File.dirname(__FILE__), 'tags')) |
| 51 | +puts "Verifying tags in '#{TAGS_DIR}'..." |
| 52 | + |
| 53 | +ids = {} |
| 54 | + |
| 55 | +Dir.glob(TAGS_DIR + "/**/*.txt").each { |filename| |
| 56 | + File.open(filename, 'r') { |f| |
| 57 | + while (line = f.gets) |
| 58 | + line.scan(/JRUBY-\d+/) { |id| |
| 59 | + (ids[id] ||= Set.new) << filename |
| 60 | + } |
| 61 | + end |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +puts "#{ids.size} JRuby jira issues used in the tags." |
| 66 | + |
| 67 | +jira = JiraVerifier.new(ARGV[0], ARGV[1]) |
| 68 | +jira.check_ids(ids) |
| 69 | +jira.logout |
0 commit comments