openproject
openproject copied to clipboard
Rubocop corrections
Continue #15055
Excluding Rails/WhereRange, as it may in the end not be safe when used with merge method.
#!/usr/bin/env ruby
require 'json'
require 'set'
require 'time'
# there are less than 100, no need to go through pages
data = `curl --silent -H "Accept: application/vnd.github.v3+json" 'https://api.github.com/repos/opf/openproject/pulls?state=open&per_page=100'`
threshold = Date.today - 100 # only updated during last 100 days
pr_ids = JSON.parse(data)
.filter{ Time.iso8601(_1['updated_at']).to_date >= threshold }
.map{ _1['number'] }
system *%W[git fetch origin dev], *pr_ids.map{ "+refs/pull/#{_1}/head:refs/remotes/origin/pr/#{_1}" }
refs = pr_ids.map{ |pr_id| "origin/pr/#{pr_id}" }
refs += `git for-each-ref --format='%(refname:short)' 'refs/remotes/origin/release/*'`.split("\n")
pr_touched_paths = Set.new
refs.each do |ref|
pr_touched_paths.merge IO.popen(%W[git diff --name-only ...#{ref}], &:read).split("\n")
end
rubocop_target_paths = IO.popen(%W[rubocop --list-target-files], &:read).split("\n")
paths = rubocop_target_paths - pr_touched_paths.to_a
system *%w[rubocop --format offenses] + paths
system *%w[rubocop --autocorrect --except Rails/WhereRange -o /dev/null] + paths