Last active
November 30, 2022 10:44
-
-
Save fredplante/93c647e89618b4bc0c0c63d2bd7e0967 to your computer and use it in GitHub Desktop.
Checks if entries can be removed from CODEOWNERS file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# This script assumes CODEOWNERS files can be found in "../.github/ | |
lines = File.readlines(File.join(__dir__, "..", ".github", "CODEOWNERS")) | |
stale_entries = [] | |
lines.each_with_index do |line, index| | |
original_line = line | |
# Normalize the beginning of each entries | |
line = line.gsub(/[[:space:]]+/, " ").strip.delete_prefix(".").delete_prefix("/") | |
# Skip if blank line or comment line | |
next if line.empty? || line.start_with?("#") | |
# Skip if entry has a wildcard character | |
next if line.include?("*") | |
# Extract the path from the entry | |
path = line.match(/^(\S+)\s+.*$/).captures.first rescue line | |
# Skip if it's a file | |
next if FileTest.file?(path) | |
# Skip if it's a non empty directory | |
next if (FileTest.directory?(path) && !Dir.empty?(path)) | |
padding = lines.size.to_s.size | |
stale_entries << "#{(index+1).to_s.rjust(padding, " ")}: #{original_line}" | |
end | |
puts "Following lines can be removed from CODEOWNERS:" | |
puts stale_entries |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment