File: files-modified-by-open-prs

package info (click to toggle)
ruby-nokogiri 1.13.10%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,416 kB
  • sloc: ansic: 38,198; xml: 28,086; ruby: 22,271; java: 15,517; cpp: 7,037; yacc: 244; sh: 148; makefile: 136
file content (67 lines) | stat: -rwxr-xr-x 1,376 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/env ruby
# frozen_string_literal: true

#
#  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 = %x(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 = %x(#{command})
  output
end

def get_paths_from_a_diff(diff)
  re = %r{^(?:---|\+\+\+) [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_desc = pr.split(/\s+/)
  pr_desc = pr_desc.join(" ")

  diff = get("gh pr diff #{pr_number}")
  diff_data = GitDiff.from_string(diff)

  relevant_files = diff_data.files.map(&:b_path)

  unless relevant_files.empty?
    puts "PR #{pr_number}: #{pr_desc}"
    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