| 
									
										
										
										
											2020-11-25 17:03:23 +01:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2021-01-21 17:43:52 -05:00
										 |  |  | require "release_notes" | 
					
						
							| 
									
										
										
										
											2018-03-24 19:21:10 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-22 12:10:48 +01:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-22 12:10:48 +01:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def release_notes_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       usage_banner "`release-notes` [<options>] [<previous_tag>] [<end_ref>]" | 
					
						
							|  |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2018-10-08 22:49:03 -04:00
										 |  |  |         Print the merged pull requests on Homebrew/brew between two Git refs. | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |         If no <previous_tag> is provided it defaults to the latest tag. | 
					
						
							|  |  |  |         If no <end_ref> is provided it defaults to `origin/master`. | 
					
						
							| 
									
										
										
										
											2020-12-28 10:37:09 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-28 11:34:29 -05:00
										 |  |  |         If `--markdown` and a <previous_tag> are passed, an extra line containing | 
					
						
							| 
									
										
										
										
											2020-12-28 10:37:09 -05:00
										 |  |  |         a link to the Homebrew blog will be adding to the output. Additionally, | 
					
						
							|  |  |  |         a warning will be shown if the latest minor release was less than one month ago. | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |       EOS | 
					
						
							|  |  |  |       switch "--markdown", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Print as a Markdown list." | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  |       named_args max: 2
 | 
					
						
							| 
									
										
										
										
											2021-01-25 09:18:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       hide_from_man_page! | 
					
						
							| 
									
										
										
										
											2018-03-25 17:48:22 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-09-08 22:21:04 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def release_notes | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     args = release_notes_args.parse | 
					
						
							| 
									
										
										
										
											2018-03-24 19:21:10 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-25 09:18:10 +00:00
										 |  |  |     odeprecated "`brew release-notes`", "`brew release`" | 
					
						
							| 
									
										
										
										
											2021-01-23 02:06:12 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |     previous_tag = args.named.first | 
					
						
							| 
									
										
										
										
											2020-12-28 10:37:09 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if previous_tag.present? | 
					
						
							| 
									
										
										
										
											2020-12-28 11:34:29 -05:00
										 |  |  |       most_recent_major_minor_tag = previous_tag.sub(/\d+$/, "0") | 
					
						
							|  |  |  |       one_month_ago = Date.today << 1
 | 
					
						
							| 
									
										
										
										
											2020-12-28 10:37:09 -05:00
										 |  |  |       previous_tag_date = Date.parse Utils.popen_read( | 
					
						
							| 
									
										
										
										
											2020-12-28 11:34:29 -05:00
										 |  |  |         "git", "-C", HOMEBREW_REPOSITORY, "log", "-1", "--format=%aI", most_recent_major_minor_tag | 
					
						
							| 
									
										
										
										
											2020-12-28 10:37:09 -05:00
										 |  |  |       ) | 
					
						
							| 
									
										
										
										
											2020-12-28 11:34:29 -05:00
										 |  |  |       opoo "The latest major/minor release was less than one month ago." if previous_tag_date > one_month_ago | 
					
						
							| 
									
										
										
										
											2020-12-28 10:37:09 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 10:23:40 -05:00
										 |  |  |     previous_tag ||= Utils.popen_read( | 
					
						
							|  |  |  |       "git", "-C", HOMEBREW_REPOSITORY, "tag", "--list", "--sort=-version:refname" | 
					
						
							|  |  |  |     ).lines.first.chomp | 
					
						
							| 
									
										
										
										
											2016-10-22 12:10:48 +01:00
										 |  |  |     odie "Could not find any previous tags!" unless previous_tag | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:28:24 +00:00
										 |  |  |     end_ref = args.named.second || "origin/master" | 
					
						
							| 
									
										
										
										
											2016-10-22 12:10:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     [previous_tag, end_ref].each do |ref| | 
					
						
							| 
									
										
										
										
											2018-04-10 10:23:40 -05:00
										 |  |  |       next if quiet_system "git", "-C", HOMEBREW_REPOSITORY, "rev-parse", "--verify", "--quiet", ref | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-22 12:10:48 +01:00
										 |  |  |       odie "Ref #{ref} does not exist!" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-23 02:06:12 -05:00
										 |  |  |     release_notes = ReleaseNotes.generate_release_notes previous_tag, end_ref, markdown: args.markdown? | 
					
						
							| 
									
										
										
										
											2016-10-22 12:10:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 17:00:24 +09:00
										 |  |  |     $stderr.puts "Release notes between #{previous_tag} and #{end_ref}:" | 
					
						
							| 
									
										
										
										
											2021-01-21 17:43:52 -05:00
										 |  |  |     puts release_notes | 
					
						
							| 
									
										
										
										
											2016-10-22 12:10:48 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |