Class: KnifeGithubSearch::GithubSearch
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- KnifeGithubSearch::GithubSearch
- Defined in:
- lib/chef/knife/github_search.rb
Instance Method Summary (collapse)
Instance Method Details
- (Object) github_search_repos(query, params = {})
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/chef/knife/github_search.rb', line 74 def github_search_repos(query, params ={}) # once the new search function is available, we can use these params params['q'] = query params['sort'] = 'stars' params['order'] = 'desc' params['response'] = 'json' url = @github_url + "/api/" + @github_api_version + "/legacy/repos/search/" + query Chef::Log.debug("URL: #{url}") send_request(url) end |
- (Object) run
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/chef/knife/github_search.rb', line 41 def run # validate base options from base module. # Display information if debug mode is on. display_debug_info # Get the name_args from the command line query = name_args.join(' ') if query.nil? || query.empty? Chef::Log.error("Please specify a search query") exit 1 end result = github_search_repos(query) if config[:link] columns = [ 'score,Score', 'name,Name', "url,URL" ] else columns = [ 'score,Score', 'name,Name', 'description,Description' ] end if result['repositories'].nil? || result['repositories'].empty? Chef::Log.error("No results when searching for: " + query) else items = [] result['repositories'].each { |n| items << [ "#{n['name']}", n ] } display_info(items, columns ) end end |