You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
5.0 KiB

  1. # frozen_string_literal: true
  2. REPOSITORY_NAME = 'tootsuite/mastodon'
  3. namespace :repo do
  4. desc 'Generate the AUTHORS.md file'
  5. task :authors do
  6. file = File.open(Rails.root.join('AUTHORS.md'), 'w')
  7. file << <<~HEADER
  8. Authors
  9. =======
  10. Mastodon is available on [GitHub](https://github.com/#{REPOSITORY_NAME})
  11. and provided thanks to the work of the following contributors:
  12. HEADER
  13. url = "https://api.github.com/repos/#{REPOSITORY_NAME}/contributors?anon=1"
  14. HttpLog.config.compact_log = true
  15. while url.present?
  16. response = HTTP.get(url)
  17. contributors = Oj.load(response.body)
  18. contributors.each do |c|
  19. file << "* [#{c['login']}](#{c['html_url']})\n" if c['login']
  20. file << "* [#{c['name']}](mailto:#{c['email']})\n" if c['name']
  21. end
  22. url = LinkHeader.parse(response.headers['Link']).find_link(%w(rel next))&.href
  23. end
  24. file << <<~FOOTER
  25. 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/tootsuite/mastodon/graphs/contributors) instead.
  26. FOOTER
  27. end
  28. desc 'Replace pull requests with authors in the CHANGELOG.md file'
  29. task :changelog do
  30. path = Rails.root.join('CHANGELOG.md')
  31. tmp = Tempfile.new
  32. HttpLog.config.compact_log = true
  33. begin
  34. File.open(path, 'r') do |file|
  35. file.each_line do |line|
  36. if line.start_with?('-')
  37. new_line = line.gsub(/#([[:digit:]]+)*/) do |pull_request_reference|
  38. pull_request_number = pull_request_reference[1..-1]
  39. response = nil
  40. loop do
  41. response = HTTP.headers('Authorization' => "token #{ENV['GITHUB_API_TOKEN']}").get("https://api.github.com/repos/#{REPOSITORY_NAME}/pulls/#{pull_request_number}")
  42. if response.code == 403
  43. sleep_for = (response.headers['X-RateLimit-Reset'].to_i - Time.now.to_i).abs
  44. puts "Sleeping for #{sleep_for} seconds to get over rate limit"
  45. sleep sleep_for
  46. else
  47. break
  48. end
  49. end
  50. pull_request = Oj.load(response.to_s)
  51. "[#{pull_request['user']['login']}](#{pull_request['html_url']})"
  52. end
  53. tmp.puts new_line
  54. else
  55. tmp.puts line
  56. end
  57. end
  58. end
  59. tmp.close
  60. FileUtils.mv(tmp.path, path)
  61. ensure
  62. tmp.close
  63. tmp.unlink
  64. end
  65. end
  66. task check_locales_files: :environment do
  67. pastel = Pastel.new
  68. missing_yaml_files = I18n.available_locales.reject { |locale| File.exist?(Rails.root.join('config', 'locales', "#{locale}.yml")) }
  69. missing_json_files = I18n.available_locales.reject { |locale| File.exist?(Rails.root.join('app', 'javascript', 'mastodon', 'locales', "#{locale}.json")) }
  70. locales_in_files = Dir[Rails.root.join('config', 'locales', '*.yml')].map do |path|
  71. file_name = File.basename(path)
  72. file_name.gsub(/\A(doorkeeper|devise|activerecord|simple_form)\./, '').gsub(/\.yml\z/, '').to_sym
  73. end.uniq.compact
  74. missing_available_locales = locales_in_files - I18n.available_locales
  75. missing_locale_names = I18n.available_locales.reject { |locale| SettingsHelper::HUMAN_LOCALES.key?(locale) }
  76. critical = false
  77. unless missing_json_files.empty?
  78. critical = true
  79. puts pastel.red("You are missing JSON files for these locales: #{pastel.bold(missing_json_files.join(', '))}")
  80. puts pastel.red('This will lead to runtime errors for users who have selected those locales')
  81. puts pastel.red("Add the missing files or remove the locales from #{pastel.bold('I18n.available_locales')} in config/application.rb")
  82. end
  83. unless missing_yaml_files.empty?
  84. critical = true
  85. puts pastel.red("You are missing YAML files for these locales: #{pastel.bold(missing_yaml_files.join(', '))}")
  86. puts pastel.red('This will lead to runtime errors for users who have selected those locales')
  87. puts pastel.red("Add the missing files or remove the locales from #{pastel.bold('I18n.available_locales')} in config/application.rb")
  88. end
  89. unless missing_available_locales.empty?
  90. puts pastel.yellow("You have locale files that are not enabled: #{pastel.bold(missing_available_locales.join(', '))}")
  91. puts pastel.yellow("Add them to #{pastel.bold('I18n.available_locales')} in config/application.rb or remove them")
  92. end
  93. unless missing_locale_names.empty?
  94. puts pastel.yellow("You are missing human-readable names for these locales: #{pastel.bold(missing_locale_names.join(', '))}")
  95. puts pastel.yellow("Add them to #{pastel.bold('HUMAN_LOCALES')} in app/helpers/settings_helper.rb or remove the locales from #{pastel.bold('I18n.available_locales')} in config/application.rb")
  96. end
  97. if critical
  98. exit(1)
  99. else
  100. puts pastel.green('OK')
  101. end
  102. end
  103. end