| 
									
										
										
										
											2020-06-29 10:16:58 -05:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 09:47:19 -05:00
										 |  |  | require "cli/parser" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							|  |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def bump_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2020-08-16 18:45:50 -05:00
										 |  |  |         `bump` [<options>] [<formula>] | 
					
						
							| 
									
										
										
										
											2020-07-02 17:06:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 09:30:19 -05:00
										 |  |  |         Display out-of-date brew formulae and the latest version available. | 
					
						
							|  |  |  |         Also displays whether a pull request has been opened with the URL. | 
					
						
							| 
									
										
										
										
											2020-06-29 09:47:19 -05:00
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2020-07-23 11:21:12 -05:00
										 |  |  |       flag "--limit=", | 
					
						
							|  |  |  |            description: "Limit number of package results returned." | 
					
						
							| 
									
										
										
										
											2020-07-06 03:32:18 +00:00
										 |  |  |       switch :verbose | 
					
						
							|  |  |  |       switch :debug | 
					
						
							| 
									
										
										
										
											2020-06-29 09:47:19 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def bump | 
					
						
							| 
									
										
										
										
											2020-08-05 10:10:05 -05:00
										 |  |  |     args = bump_args.parse | 
					
						
							| 
									
										
										
										
											2020-07-01 10:21:57 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  |     requested_formulae = args.named.to_formulae.map(&:name) if args.named.to_formulae.present? | 
					
						
							| 
									
										
										
										
											2020-08-16 20:38:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-11 15:29:22 +00:00
										 |  |  |     requested_limit = args.limit.to_i if args.limit.present? | 
					
						
							| 
									
										
										
										
											2020-07-28 09:30:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 20:38:03 -05:00
										 |  |  |     repology_data = if requested_formulae | 
					
						
							|  |  |  |       response = {} | 
					
						
							|  |  |  |       requested_formulae.each do |formula| | 
					
						
							|  |  |  |         raise FormulaUnavailableError, formula unless validate_formula(formula) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         package_data = Repology.single_package_query(formula) | 
					
						
							|  |  |  |         response[package_data.keys.first] = package_data.values.first if package_data | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-07-02 17:06:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 20:38:03 -05:00
										 |  |  |       response | 
					
						
							| 
									
										
										
										
											2020-07-28 09:43:20 -05:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2020-08-18 22:18:03 +00:00
										 |  |  |       Repology.parse_api_response(requested_limit) | 
					
						
							| 
									
										
										
										
											2020-07-28 09:43:20 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-07-28 09:30:19 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 20:38:03 -05:00
										 |  |  |     validated_formulae = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     validated_formulae = Repology.validate_and_format_packages(repology_data, requested_limit) if repology_data | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if requested_formulae | 
					
						
							|  |  |  |       repology_excluded_formulae = requested_formulae.reject do |formula| | 
					
						
							|  |  |  |         repology_data[formula] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       formulae = {} | 
					
						
							|  |  |  |       repology_excluded_formulae.each do |formula| | 
					
						
							|  |  |  |         formulae[formula] = Repology.format_package(formula, nil) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       formulae.each { |formula, data| validated_formulae[formula] = data } | 
					
						
							| 
									
										
										
										
											2020-08-05 10:10:05 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-16 19:22:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     display(validated_formulae) | 
					
						
							| 
									
										
										
										
											2020-07-02 17:06:39 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 10:52:37 -05:00
										 |  |  |   def validate_formula(formula_name) | 
					
						
							| 
									
										
										
										
											2020-07-06 03:32:18 +00:00
										 |  |  |     Formula[formula_name] | 
					
						
							|  |  |  |   rescue | 
					
						
							|  |  |  |     nil | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 10:52:37 -05:00
										 |  |  |   def up_to_date?(package) | 
					
						
							| 
									
										
										
										
											2020-08-16 19:22:24 -05:00
										 |  |  |     package && | 
					
						
							|  |  |  |       package[:current_formula_version] == package[:repology_latest_version] && | 
					
						
							| 
									
										
										
										
											2020-07-31 10:52:37 -05:00
										 |  |  |       package[:current_formula_version] == package[:livecheck_latest_version] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def display(formulae) | 
					
						
							|  |  |  |     formulae.each do |formula, package_details| | 
					
						
							| 
									
										
										
										
											2020-08-11 15:29:05 +00:00
										 |  |  |       title = (up_to_date?(package_details) ? "#{formula} is up to date!" : formula).to_s | 
					
						
							| 
									
										
										
										
											2020-07-31 10:52:37 -05:00
										 |  |  |       ohai title | 
					
						
							| 
									
										
										
										
											2020-07-29 13:26:10 +00:00
										 |  |  |       puts "Current formula version:  #{package_details[:current_formula_version]}" | 
					
						
							| 
									
										
										
										
											2020-08-18 13:29:36 +00:00
										 |  |  |       puts "Latest Repology version:  #{package_details[:repology_latest_version]}" | 
					
						
							|  |  |  |       puts "Latest livecheck version: #{package_details[:livecheck_latest_version]}" | 
					
						
							|  |  |  |       puts "Open pull requests:       #{package_details[:open_pull_requests]}" | 
					
						
							| 
									
										
										
										
											2020-07-02 17:06:39 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-06-29 09:47:19 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | end |