PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/issue_search

https://bitbucket.org/osrf/bitbucket-client-tools
Ruby | 59 lines | 39 code | 6 blank | 14 comment | 3 complexity | 5170b25239eb058466529e316ac6a6c5 MD5 | raw file
  1. #!/usr/bin/env ruby
  2. # based on http://www.alphadevx.com/a/88-Writing-a-REST-Client-in-Ruby
  3. require 'rubygems'
  4. require 'rest_client'
  5. require 'json'
  6. require 'uri'
  7. class BitbucketIssueSearch
  8. # constructor
  9. def initialize
  10. @url_prefix = 'https://bitbucket.org/api/1.0/repositories/'
  11. @url_action= '/issues?search='
  12. @url_suffix= '&limit=50'
  13. end
  14. # return raw JSON from bitbucket
  15. def getJSON(owner, repository, search)
  16. url = @url_prefix + owner + "/" + repository + @url_action +
  17. search + @url_suffix
  18. response = RestClient.get(URI.escape(url))
  19. return response.body
  20. end
  21. # human friendly list of matching issues
  22. def getText(owner, repository, search)
  23. jsonHash = JSON.parse(getJSON(owner, repository, search))
  24. output = ""
  25. #output += jsonHash["size"].to_s + " open pull requests: "+"\n"
  26. #fields = ["id", "branch\t", "commit"]
  27. #fields.each { |field|
  28. # output += field + "\t"
  29. #}
  30. #output += "\n"
  31. jsonHash["issues"].each { |i|
  32. output += i["local_id"].to_s
  33. if i["metadata"]["component"].nil?
  34. output += "\tnull"
  35. else
  36. output += "\t"+i["metadata"]["component"]
  37. end
  38. output += "\t"
  39. output += "\t"+i["title"]
  40. #i.keys.each { |key|
  41. # output += " "+key+"\n"
  42. #}
  43. output += "\n"
  44. }
  45. return output
  46. end
  47. end
  48. client = BitbucketIssueSearch.new
  49. if ARGV.length == 3
  50. puts client.getText(ARGV[0], ARGV[1], ARGV[2])
  51. else
  52. puts "usage: "+__FILE__+" owner repository issue_search_string"
  53. end