2018-09-10 08:31:42 +09:00
# frozen_string_literal: true
2021-07-13 22:46:20 +09:00
REPOSITORY_NAME = 'mastodon/mastodon'
2021-05-17 06:54:46 +09:00
2018-09-10 08:31:42 +09:00
namespace :repo do
2019-01-20 00:25:20 +09:00
desc 'Generate the AUTHORS.md file'
2018-09-10 08:31:42 +09:00
task :authors do
2023-02-22 09:57:15 +09:00
file = Rails . root . join ( 'AUTHORS.md' ) . open ( 'w' )
2021-05-17 06:54:46 +09:00
2018-09-10 08:31:42 +09:00
file << << ~ HEADER
2019-01-20 06:01:12 +09:00
Authors
=== === =
2021-05-17 06:54:46 +09:00
Mastodon is available on [ GitHub ] ( https : / / github . com / #{REPOSITORY_NAME})
2018-09-10 08:31:42 +09:00
and provided thanks to the work of the following contributors :
HEADER
2021-05-17 06:54:46 +09:00
url = " https://api.github.com/repos/ #{ REPOSITORY_NAME } /contributors?anon=1 "
2024-11-07 18:57:42 +09:00
HttpLog . config . compact_log = true if defined? ( HttpLog )
2021-05-17 06:54:46 +09:00
2018-09-10 08:31:42 +09:00
while url . present?
2021-05-17 06:54:46 +09:00
response = HTTP . get ( url )
2024-10-31 04:41:12 +09:00
contributors = JSON . parse ( response . body )
2021-05-17 06:54:46 +09:00
2018-09-10 08:31:42 +09:00
contributors . each do | c |
file << " * [ #{ c [ 'login' ] } ]( #{ c [ 'html_url' ] } ) \n " if c [ 'login' ]
2018-09-10 09:01:03 +09:00
file << " * [ #{ c [ 'name' ] } ](mailto: #{ c [ 'email' ] } ) \n " if c [ 'name' ]
2018-09-10 08:31:42 +09:00
end
2021-05-17 06:54:46 +09:00
2018-09-10 08:31:42 +09:00
url = LinkHeader . parse ( response . headers [ 'Link' ] ) . find_link ( %w( rel next ) ) & . href
end
file << << ~ FOOTER
2021-07-13 22:46:20 +09:00
This document is provided for informational purposes only . Since it is only updated once per release , the version you are looking at may be currently out of date . To see the full list of contributors , consider looking at the [ git history ] ( https : / / github . com / mastodon / mastodon / graphs / contributors ) instead .
2018-09-10 08:31:42 +09:00
FOOTER
end
2019-01-20 00:25:20 +09:00
desc 'Replace pull requests with authors in the CHANGELOG.md file'
task :changelog do
path = Rails . root . join ( 'CHANGELOG.md' )
tmp = Tempfile . new
2024-11-07 18:57:42 +09:00
HttpLog . config . compact_log = true if defined? ( HttpLog )
2019-01-20 00:25:20 +09:00
begin
File . open ( path , 'r' ) do | file |
file . each_line do | line |
if line . start_with? ( '-' )
2024-08-23 21:55:54 +09:00
new_line = line . gsub ( / \ ( # ([[:digit:]]+)(, # ([[:digit:]]+))* \ ) \ Z / ) do | pull_requests_string |
pull_requests = pull_requests_string [ 1 ... - 1 ] . split ( ',' ) . map { | pr_id | pr_id . strip [ 1 ... ] }
2019-01-20 00:25:20 +09:00
response = nil
2024-08-23 21:55:54 +09:00
authors = pull_requests . map do | pull_request_number |
response = nil
2019-01-20 00:25:20 +09:00
2024-08-23 21:55:54 +09:00
loop do
response = HTTP . headers ( 'Authorization' = > " token #{ ENV [ 'GITHUB_API_TOKEN' ] } " ) . get ( " https://api.github.com/repos/ #{ REPOSITORY_NAME } /pulls/ #{ pull_request_number } " )
if response . code == 403
sleep_for = ( response . headers [ 'X-RateLimit-Reset' ] . to_i - Time . now . to_i ) . abs
puts " Sleeping for #{ sleep_for } seconds to get over rate limit "
sleep sleep_for
else
break
end
2019-01-20 00:25:20 +09:00
end
2024-08-23 21:55:54 +09:00
2024-10-31 04:41:12 +09:00
pull_request = JSON . parse ( response . to_s )
2024-08-23 21:55:54 +09:00
pull_request [ 'user' ] [ 'login' ]
2019-01-20 00:25:20 +09:00
end
2024-08-23 21:55:54 +09:00
authors . sort! . uniq!
" ( #{ pull_requests . map { | pr | " # #{ pr } " } . to_sentence } by #{ authors . map { | author | " @ #{ author } " } . to_sentence } ) "
2019-01-20 00:25:20 +09:00
end
tmp . puts new_line
else
tmp . puts line
end
end
end
tmp . close
FileUtils . mv ( tmp . path , path )
ensure
tmp . close
tmp . unlink
end
end
2019-09-12 11:58:33 +09:00
task check_locales_files : :environment do
pastel = Pastel . new
2023-02-22 09:57:15 +09:00
missing_yaml_files = I18n . available_locales . reject { | locale | Rails . root . join ( 'config' , 'locales' , " #{ locale } .yml " ) . exist? }
missing_json_files = I18n . available_locales . reject { | locale | Rails . root . join ( 'app' , 'javascript' , 'mastodon' , 'locales' , " #{ locale } .json " ) . exist? }
2019-09-12 11:58:33 +09:00
2024-08-26 16:35:07 +09:00
locales_in_files = Rails . root . glob ( 'config/locales/*.yml' ) . map do | path |
2023-03-13 08:03:07 +09:00
file_name = File . basename ( path , '.yml' )
file_name . gsub ( / \ A(doorkeeper|devise|activerecord|simple_form) \ . / , '' ) . to_sym
2021-05-17 06:54:46 +09:00
end . uniq . compact
missing_available_locales = locales_in_files - I18n . available_locales
2022-02-08 10:41:17 +09:00
supported_locale_codes = Set . new ( LanguagesHelper :: SUPPORTED_LOCALES . keys + LanguagesHelper :: REGIONAL_LOCALE_NAMES . keys )
missing_locale_names = I18n . available_locales . reject { | locale | supported_locale_codes . include? ( locale ) }
2021-05-17 06:54:46 +09:00
critical = false
unless missing_json_files . empty?
critical = true
puts pastel . red ( " You are missing JSON files for these locales: #{ pastel . bold ( missing_json_files . join ( ', ' ) ) } " )
puts pastel . red ( 'This will lead to runtime errors for users who have selected those locales' )
puts pastel . red ( " Add the missing files or remove the locales from #{ pastel . bold ( 'I18n.available_locales' ) } in config/application.rb " )
end
unless missing_yaml_files . empty?
critical = true
puts pastel . red ( " You are missing YAML files for these locales: #{ pastel . bold ( missing_yaml_files . join ( ', ' ) ) } " )
puts pastel . red ( 'This will lead to runtime errors for users who have selected those locales' )
puts pastel . red ( " Add the missing files or remove the locales from #{ pastel . bold ( 'I18n.available_locales' ) } in config/application.rb " )
end
unless missing_available_locales . empty?
puts pastel . yellow ( " You have locale files that are not enabled: #{ pastel . bold ( missing_available_locales . join ( ', ' ) ) } " )
puts pastel . yellow ( " Add them to #{ pastel . bold ( 'I18n.available_locales' ) } in config/application.rb or remove them " )
end
unless missing_locale_names . empty?
puts pastel . yellow ( " You are missing human-readable names for these locales: #{ pastel . bold ( missing_locale_names . join ( ', ' ) ) } " )
2022-02-08 10:41:17 +09:00
puts pastel . yellow ( " Add them to app/helpers/languages_helper.rb or remove the locales from #{ pastel . bold ( 'I18n.available_locales' ) } in config/application.rb " )
2021-05-17 06:54:46 +09:00
end
if critical
2019-09-12 11:58:33 +09:00
exit ( 1 )
2021-05-17 06:54:46 +09:00
else
puts pastel . green ( 'OK' )
2019-09-12 11:58:33 +09:00
end
end
2018-09-10 08:31:42 +09:00
end