-
Notifications
You must be signed in to change notification settings - Fork 2
/
team_unified_prs.rb
executable file
·67 lines (53 loc) · 1.81 KB
/
team_unified_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
#!/usr/bin/env ruby
require_relative "lib/github"
def positional_arg_or_env(idx, env_var)
if ARGV.length > idx
return ARGV[idx]
else
return (ENV[env_var] || "")
end
end
def positional_arg_or_env_split(idx, env_var)
return positional_arg_or_env(idx, env_var).split(',')
end
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
team_name = positional_arg_or_env(0, "GITHUB_TEAM")
skip_team_members = positional_arg_or_env_split(1, "GITHUB_SKIP_TEAM_MEMBERS")
skip_pr_ids = positional_arg_or_env_split(2, "GITHUB_SKIP_PR_IDS")
team_repos = positional_arg_or_env_split(3, "GITHUB_TEAM_REPOS")
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
all_prs = {}
add_prs = proc do |prs|
for pr in prs
next if skip_pr_ids.include?(pr["url"]) || pr["repoArchived"]
all_prs[pr["url"]] = pr
end
end
team.each do |member|
next if skip_team_members.include?(member["login"])
add_prs.call(
Github.open_pull_requests_for_involves(member["login"]).reject do |pr|
pr.nil? || pr["owner"].downcase != parsed_team["org"].downcase
end
)
end
add_prs.call(Github.open_pull_requests_for_team(team_name))
team_repos.each do |repo|
add_prs.call(Github.open_pull_requests_for_repo(repo))
end
prs_reverse_date = all_prs.values.sort_by { |pr| pr["createdAt"] }.reverse
Github.puts_multiple_pull_requests(prs_reverse_date, { indexed: true })
end