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.

94 lines
3.3 KiB

  1. # frozen_string_literal: true
  2. namespace :repo do
  3. desc 'Generate the AUTHORS.md file'
  4. task :authors do
  5. file = File.open(Rails.root.join('AUTHORS.md'), 'w')
  6. file << <<~HEADER
  7. Authors
  8. =======
  9. Mastodon is available on [GitHub](https://github.com/tootsuite/mastodon)
  10. and provided thanks to the work of the following contributors:
  11. HEADER
  12. url = 'https://api.github.com/repos/tootsuite/mastodon/contributors?anon=1'
  13. HttpLog.config.compact_log = true
  14. while url.present?
  15. response = HTTP.get(url)
  16. contributors = Oj.load(response.body)
  17. contributors.each do |c|
  18. file << "* [#{c['login']}](#{c['html_url']})\n" if c['login']
  19. file << "* [#{c['name']}](mailto:#{c['email']})\n" if c['name']
  20. end
  21. url = LinkHeader.parse(response.headers['Link']).find_link(%w(rel next))&.href
  22. end
  23. file << <<~FOOTER
  24. 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.
  25. FOOTER
  26. end
  27. desc 'Replace pull requests with authors in the CHANGELOG.md file'
  28. task :changelog do
  29. path = Rails.root.join('CHANGELOG.md')
  30. tmp = Tempfile.new
  31. HttpLog.config.compact_log = true
  32. begin
  33. File.open(path, 'r') do |file|
  34. file.each_line do |line|
  35. if line.start_with?('-')
  36. new_line = line.gsub(/#([[:digit:]]+)*/) do |pull_request_reference|
  37. pull_request_number = pull_request_reference[1..-1]
  38. response = nil
  39. loop do
  40. response = HTTP.headers('Authorization' => "token #{ENV['GITHUB_API_TOKEN']}").get("https://api.github.com/repos/tootsuite/mastodon/pulls/#{pull_request_number}")
  41. if response.code == 403
  42. sleep_for = (response.headers['X-RateLimit-Reset'].to_i - Time.now.to_i).abs
  43. puts "Sleeping for #{sleep_for} seconds to get over rate limit"
  44. sleep sleep_for
  45. else
  46. break
  47. end
  48. end
  49. pull_request = Oj.load(response.to_s)
  50. "[#{pull_request['user']['login']}](#{pull_request['html_url']})"
  51. end
  52. tmp.puts new_line
  53. else
  54. tmp.puts line
  55. end
  56. end
  57. end
  58. tmp.close
  59. FileUtils.mv(tmp.path, path)
  60. ensure
  61. tmp.close
  62. tmp.unlink
  63. end
  64. end
  65. task check_locales_files: :environment do
  66. pastel = Pastel.new
  67. missing_yaml_files = I18n.available_locales.reject { |locale| File.exist?(Rails.root.join('config', 'locales', "#{locale}.yml")) }
  68. missing_json_files = I18n.available_locales.reject { |locale| File.exist?(Rails.root.join('app', 'javascript', 'mastodon', 'locales', "#{locale}.json")) }
  69. if missing_json_files.empty? && missing_yaml_files.empty?
  70. puts pastel.green('OK')
  71. else
  72. puts pastel.red("Missing YAML files: #{pastel.bold(missing_yaml_files.join(', '))}") unless missing_yaml_files.empty?
  73. puts pastel.red("Missing JSON files: #{pastel.bold(missing_json_files.join(', '))}") unless missing_json_files.empty?
  74. exit(1)
  75. end
  76. end
  77. end