/bin/issue_search
Ruby | 59 lines | 39 code | 6 blank | 14 comment | 3 complexity | 5170b25239eb058466529e316ac6a6c5 MD5 | raw file
- #!/usr/bin/env ruby
- # based on http://www.alphadevx.com/a/88-Writing-a-REST-Client-in-Ruby
- require 'rubygems'
- require 'rest_client'
- require 'json'
- require 'uri'
- class BitbucketIssueSearch
- # constructor
- def initialize
- @url_prefix = 'https://bitbucket.org/api/1.0/repositories/'
- @url_action= '/issues?search='
- @url_suffix= '&limit=50'
- end
- # return raw JSON from bitbucket
- def getJSON(owner, repository, search)
- url = @url_prefix + owner + "/" + repository + @url_action +
- search + @url_suffix
- response = RestClient.get(URI.escape(url))
- return response.body
- end
- # human friendly list of matching issues
- def getText(owner, repository, search)
- jsonHash = JSON.parse(getJSON(owner, repository, search))
- output = ""
- #output += jsonHash["size"].to_s + " open pull requests: "+"\n"
- #fields = ["id", "branch\t", "commit"]
- #fields.each { |field|
- # output += field + "\t"
- #}
- #output += "\n"
- jsonHash["issues"].each { |i|
- output += i["local_id"].to_s
- if i["metadata"]["component"].nil?
- output += "\tnull"
- else
- output += "\t"+i["metadata"]["component"]
- end
- output += "\t"
- output += "\t"+i["title"]
- #i.keys.each { |key|
- # output += " "+key+"\n"
- #}
- output += "\n"
- }
- return output
- end
- end
- client = BitbucketIssueSearch.new
- if ARGV.length == 3
- puts client.getText(ARGV[0], ARGV[1], ARGV[2])
- else
- puts "usage: "+__FILE__+" owner repository issue_search_string"
- end