| 
									
										
										
										
											2022-10-11 00:52:32 +01:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "cli/parser" | 
					
						
							|  |  |  | require "utils/github" | 
					
						
							| 
									
										
										
										
											2022-11-08 20:36:10 +09:00
										 |  |  | require "manpages" | 
					
						
							| 
									
										
										
										
											2024-01-31 20:00:54 -08:00
										 |  |  | require "system_command" | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2024-01-31 20:00:54 -08:00
										 |  |  |   extend SystemCommand::Mixin | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2024-01-31 20:00:54 -08:00
										 |  |  |   def self.update_maintainers_args | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       description <<~EOS | 
					
						
							|  |  |  |         Update the list of maintainers in the `Homebrew/brew` README. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       named_args :none | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-31 20:00:54 -08:00
										 |  |  |   def self.update_maintainers | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  |     update_maintainers_args.parse | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # We assume that only public members wish to be included in the README | 
					
						
							|  |  |  |     public_members = GitHub.public_member_usernames("Homebrew") | 
					
						
							| 
									
										
										
										
											2023-05-29 12:02:43 +08:00
										 |  |  |     maintainers = GitHub.members_by_team("Homebrew", "maintainers") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     HOMEBREW_MAINTAINER_JSON.write(maintainers.keys.to_json) | 
					
						
							|  |  |  |     maintainer_json_relative_path = HOMEBREW_MAINTAINER_JSON.relative_path_from(HOMEBREW_REPOSITORY).to_s | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 02:58:17 +05:30
										 |  |  |     members = { | 
					
						
							| 
									
										
										
										
											2023-02-02 17:09:25 +00:00
										 |  |  |       plc:         GitHub.members_by_team("Homebrew", "plc"), | 
					
						
							|  |  |  |       tsc:         GitHub.members_by_team("Homebrew", "tsc"), | 
					
						
							| 
									
										
										
										
											2024-03-07 16:20:20 +00:00
										 |  |  |       maintainers:, | 
					
						
							| 
									
										
										
										
											2021-02-06 02:58:17 +05:30
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 02:58:17 +05:30
										 |  |  |     sentences = {} | 
					
						
							|  |  |  |     members.each do |group, hash| | 
					
						
							| 
									
										
										
										
											2023-12-12 10:40:08 -08:00
										 |  |  |       hash.replace(hash.slice(*public_members)) | 
					
						
							| 
									
										
										
										
											2021-02-06 02:58:17 +05:30
										 |  |  |       hash.each { |login, name| hash[login] = "[#{name}](https://github.com/#{login})" } | 
					
						
							|  |  |  |       sentences[group] = hash.values.sort.to_sentence | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     readme = HOMEBREW_REPOSITORY/"README.md" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     content = readme.read | 
					
						
							|  |  |  |     content.gsub!(/(Homebrew's \[Project Leadership Committee.*) is .*\./, | 
					
						
							| 
									
										
										
										
											2021-02-06 02:58:17 +05:30
										 |  |  |                   "\\1 is #{sentences[:plc]}.") | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  |     content.gsub!(/(Homebrew's \[Technical Steering Committee.*) is .*\./, | 
					
						
							| 
									
										
										
										
											2021-02-06 02:58:17 +05:30
										 |  |  |                   "\\1 is #{sentences[:tsc]}.") | 
					
						
							| 
									
										
										
										
											2023-02-02 17:09:25 +00:00
										 |  |  |     content.gsub!(/(Homebrew's maintainers are).*\./, | 
					
						
							|  |  |  |                   "\\1 #{sentences[:maintainers]}.") | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-23 14:49:05 -05:00
										 |  |  |     File.write(readme, content) | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     diff = system_command "git", args: [ | 
					
						
							| 
									
										
										
										
											2023-05-29 12:02:43 +08:00
										 |  |  |       "-C", HOMEBREW_REPOSITORY, "diff", "--exit-code", "README.md", maintainer_json_relative_path | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  |     ] | 
					
						
							|  |  |  |     if diff.status.success? | 
					
						
							| 
									
										
										
										
											2022-09-02 08:24:33 +01:00
										 |  |  |       ofail "No changes to list of maintainers." | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2022-11-08 20:36:10 +09:00
										 |  |  |       Manpages.regenerate_man_pages(quiet: true) | 
					
						
							| 
									
										
										
										
											2021-02-09 21:08:57 +00:00
										 |  |  |       puts "List of maintainers updated in the README and the generated man pages." | 
					
						
							| 
									
										
										
										
											2021-02-04 17:00:50 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |