-
Notifications
You must be signed in to change notification settings - Fork 2
/
team_prs.rb
executable file
·78 lines (64 loc) · 1.74 KB
/
team_prs.rb
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
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env ruby
require_relative "lib/github"
if $PROGRAM_NAME == __FILE__
if !ENV["GITHUB_ACCESS_TOKEN"]
puts "GITHUB_ACCESS_TOKEN environment var needs to be set to a personal access token"
exit(1)
end
if ARGV.length < 1 && !ENV["GITHUB_TEAM"]
puts "Usage: #{__FILE__} <team name as org/team> <optional extra filters>"
exit(2)
end
if ARGV.length > 0
team_names = ARGV[0]
else
team_names = ENV["GITHUB_TEAM"]
end
if ARGV.length > 1
extra_filters = ARGV[1]
else
extra_filters = ""
end
team_members = []
orgs = []
team_names.split(",").each do |team_name|
parsed_team = Github.parse_org_and_team(team_name)
team = Github.team_members(parsed_team["org"], parsed_team["team_name"])
if team.nil?
$stderr.puts "Team [#{team_name}] could not be found"
exit(3)
end
team_members |= team
orgs << parsed_team["org"].downcase
end
puts "┌" + ("─" * 79)
puts "│ "
no_prs = []
team_members.each_with_index do |member, i|
prs = Github.open_pull_requests_for_author(member["login"], extra_filters).select { |pr| orgs.include?(pr["owner"].downcase) }
if !prs.empty?
Github.puts_multiple_pull_requests(prs, { prefix: "│ " })
else
no_prs << member
end
if !prs.empty? && i < team_members.size - 1
puts "│ "
puts "├" + ("─" * 79)
puts "│ "
end
end
no_prs.each_with_index do |member, i|
if i == 0
puts "│ "
puts "├" + ("─" * 79)
puts "│ "
end
puts "│ " + Github.name_and_login(member)
puts "│ " + "No open PRs"
if i < no_prs.size - 1
puts "│ "
end
end
puts "│ "
puts "└" + ("─" * 79)
end