about summary refs log tree commit diff
path: root/lib/tasks/repo.rake
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-01-20 13:56:37 +0100
committerGitHub <noreply@github.com>2019-01-20 13:56:37 +0100
commitaa362ab73dc7121104b3c01800152b9fc56ea396 (patch)
treef0f5879a51325856887a2e32a4c3f9654af61aab /lib/tasks/repo.rake
parent530d29148ca0c5bf29f6fa516b1ef4f91d95894b (diff)
parent5145c81620efbd5cf8dc911858d17d1fa888c996 (diff)
Merge pull request #888 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'lib/tasks/repo.rake')
-rw-r--r--lib/tasks/repo.rake50
1 files changed, 48 insertions, 2 deletions
diff --git a/lib/tasks/repo.rake b/lib/tasks/repo.rake
index 367859e94..263cca84c 100644
--- a/lib/tasks/repo.rake
+++ b/lib/tasks/repo.rake
@@ -1,9 +1,9 @@
 # frozen_string_literal: true
 
 namespace :repo do
-  desc 'Generate the authors.md file'
+  desc 'Generate the AUTHORS.md file'
   task :authors do
-    file = File.open('AUTHORS.md', 'w')
+    file = File.open(Rails.root.join('AUTHORS.md'), 'w')
     file << <<~HEADER
       Mastodon is available on [GitHub](https://github.com/tootsuite/mastodon)
       and provided thanks to the work of the following contributors:
@@ -27,4 +27,50 @@ namespace :repo do
       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.
     FOOTER
   end
+
+  desc 'Replace pull requests with authors in the CHANGELOG.md file'
+  task :changelog do
+    path = Rails.root.join('CHANGELOG.md')
+    tmp  = Tempfile.new
+
+    HttpLog.config.compact_log = true
+
+    begin
+      File.open(path, 'r') do |file|
+        file.each_line do |line|
+          if line.start_with?('-')
+            new_line = line.gsub(/#([[:digit:]]+)*/) do |pull_request_reference|
+              pull_request_number = pull_request_reference[1..-1]
+              response = nil
+
+              loop do
+                response = HTTP.headers('Authorization' => "token #{ENV['GITHUB_API_TOKEN']}").get("https://api.github.com/repos/tootsuite/mastodon/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
+              end
+
+              pull_request = Oj.load(response.to_s)
+              "[#{pull_request['user']['login']}](#{pull_request['html_url']})"
+            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
 end