Skip to content

Commit

Permalink
Unified team prs and involves search
Browse files Browse the repository at this point in the history
  • Loading branch information
rogusdev committed Mar 23, 2020
1 parent d936752 commit f04fa98
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 6 deletions.
21 changes: 19 additions & 2 deletions lib/github-graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def self.get_pull_request_by_number(org, repo, pr_number)
return query(qry, vars)
end

def self.get_pull_requests_for_login(login, extra_filters)
def self.get_open_pull_requests_for_search(search)
qry = <<-'GRAPHQL'
query($queryString: String!) {
search(query:$queryString, type: ISSUE, first: 100) {
Expand Down Expand Up @@ -236,12 +236,29 @@ def self.get_pull_requests_for_login(login, extra_filters)
GRAPHQL

vars = {
queryString: "is:open is:pr author:#{login} #{extra_filters}"
queryString: "is:open is:pr #{search}"
}

return query(qry, vars)
end

def self.get_open_pull_requests_for_author(login, extra_filters="")
return get_open_pull_requests_for_search("author:#{login} #{extra_filters}")
end

def self.get_open_pull_requests_for_involves(login, extra_filters="")
# https://help.github.com/en/github/searching-for-information-on-github/searching-issues-and-pull-requests#search-by-a-user-thats-involved-in-an-issue-or-pull-request
# involves = OR between the author, assignee, mentions, and commenter
# ... not sure if it includes review-requested:#{login} -- seems like maybe yes?
return get_open_pull_requests_for_search("involves:#{login} #{extra_filters}")
end

def self.get_open_pull_requests_for_team(team, extra_filters="")
# team:#{org}/#{team_name}
# not sure if it also includes team-review-requested:#{org}/#{team_name} ?
return get_open_pull_requests_for_search("team:#{team} #{extra_filters}")
end

def self.request_review_on_pull_request(pr_id, user_ids)
qry = <<-'GRAPHQL'
mutation($pullRequestId: ID!, $userIds: [ID!]) {
Expand Down
18 changes: 16 additions & 2 deletions lib/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@ def self.pull_request_by_number(org, repo, pr_number)
return _pr_data(data["data"]["repository"]["pullRequest"])
end

def self.pull_requests_for_login(login, extra_filters)
data = GithubGraphql.get_pull_requests_for_login(login, extra_filters)
def self.open_pull_requests_for_author(login, extra_filters="")
data = GithubGraphql.get_open_pull_requests_for_author(login, extra_filters)
return _map_pr_data_search(data)
end

def self.open_pull_requests_for_involves(login, extra_filters="")
data = GithubGraphql.get_open_pull_requests_for_involves(login, extra_filters)
return _map_pr_data_search(data)
end

def self.open_pull_requests_for_team(team, extra_filters="")
data = GithubGraphql.get_open_pull_requests_for_team(team, extra_filters)
return _map_pr_data_search(data)
end

def self._map_pr_data_search(data)
return data["data"]["search"]["edges"].map do |edge|
_pr_data(edge["node"])
end
Expand Down
2 changes: 1 addition & 1 deletion my_prs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

login = Github.my_user_login()

prs = Github.pull_requests_for_login(login, extra_filters)
prs = Github.open_pull_requests_for_author(login, extra_filters)
Github.puts_multiple_pull_requests(prs)
end
2 changes: 1 addition & 1 deletion team_prs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
puts "│   "
no_prs = []
team.each_with_index do |member, i|
prs = Github.pull_requests_for_login(member["login"], extra_filters).reject { |pr| pr["owner"].downcase != parsed_team["org"].downcase }
prs = Github.open_pull_requests_for_author(member["login"], extra_filters).reject { |pr| pr["owner"].downcase != parsed_team["org"].downcase }

if !prs.empty?
Github.puts_multiple_pull_requests(prs, { prefix: "│   " })
Expand Down
66 changes: 66 additions & 0 deletions team_unified_prs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/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_name = ARGV[0]
else
team_name = ENV["GITHUB_TEAM"]
end

if ARGV.length > 1
skip_team_members = ARGV[1].split(',')
else
skip_team_members = []
end

if ARGV.length > 2
skip_pr_ids = ARGV[2].split(',')
else
skip_pr_ids = []
end

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

puts "┌" + ("─" * 79)
puts "│   "
all_prs = {}

team.each_with_index do |member, i|
next if skip_team_members.include?(member["login"])
prs = Github.open_pull_requests_for_involves(member["login"]).reject { |pr| pr["owner"].downcase != parsed_team["org"].downcase }

for pr in prs
next if skip_pr_ids.include?(pr["url"])
all_prs[pr["url"]] = pr
end
end

prs = Github.open_pull_requests_for_team(team_name)

for pr in prs
next if skip_pr_ids.include?(pr["url"])
all_prs[pr["url"]] = pr
end

Github.puts_multiple_pull_requests(all_prs.values, { prefix: "│   " })
puts "│   "
puts "└" + ("─" * 79)
end

0 comments on commit f04fa98

Please sign in to comment.