-
-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: utility script for indexing PRs by file
[skip ci]
- Loading branch information
1 parent
ebe91aa
commit d7c37b0
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#! /usr/bin/env ruby | ||
# | ||
# script to see what PRs, if any, are operating on a file that I care about. | ||
# yes, this is a smell. we shouldn't have long-lived PRs, but alas here we are. | ||
# | ||
require "bundler/inline" | ||
|
||
gemfile do | ||
source "https://rubygems.org/" | ||
gem "git_diff" | ||
end | ||
|
||
require "git_diff" | ||
require "set" | ||
|
||
gh = `which gh 2> /dev/null`.strip | ||
if gh.empty? | ||
puts "Please install the github CLI at https://cli.github.com/" | ||
exit 1 | ||
end | ||
|
||
def get command | ||
puts "> #{command}" | ||
output = `#{command}` | ||
output | ||
end | ||
|
||
def get_paths_from_a_diff(diff) | ||
re = /^(?:---|\+\+\+) [ab]\/(.*)$/ | ||
diff.split("\n").grep(re).map {|line| line.sub(re, '\1') }.uniq | ||
end | ||
|
||
prs = get("gh pr list").split("\n") | ||
|
||
paths_to_prs = Hash.new { |h,k| h[k] = Set.new } | ||
|
||
prs.each do |pr| | ||
pr_number = pr.split(/\s+/).first | ||
|
||
diff = get("gh pr diff #{pr_number}") | ||
diff_data = GitDiff::from_string(diff) | ||
|
||
relevant_files = diff_data.files.map(&:b_path) | ||
|
||
if relevant_files.length > 0 | ||
puts "PR #{pr_number}:" | ||
relevant_files.sort.each do |file| | ||
puts "- #{file}" | ||
end | ||
end | ||
|
||
relevant_files.each do |file| | ||
paths_to_prs[file].add(pr_number) | ||
end | ||
end | ||
|
||
puts "\n---" | ||
|
||
paths_to_prs.keys.sort.each do |key| | ||
puts "#{key}:" | ||
paths_to_prs[key].entries.sort.each do |value| | ||
puts "- #{value}" | ||
end | ||
end |