Skip to content

Commit

Permalink
Allow GITHUB_TEAM env var instead of positional cli param for request…
Browse files Browse the repository at this point in the history
…_reviews and team_prs
  • Loading branch information
jasonpenny committed Feb 21, 2019
1 parent 8c5f872 commit 7522836
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
10 changes: 9 additions & 1 deletion lib/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def self._pr_data(pr)
## Returns a list of members {id, login, name}
def self.team_members(org, team_name)
team = GithubGraphql.get_team_members(org, team_name)
return nil if team["data"]["organization"]["team"].nil?
return nil if team["data"]["organization"].nil? || team["data"]["organization"]["team"].nil?

return team["data"]["organization"]["team"]["members"]["edges"].map { |edge| edge["node"] }
end
Expand Down Expand Up @@ -119,6 +119,14 @@ def self.parse_pull_request_url(url)
return Hash[keys.zip(vals)]
end

def self.parse_org_and_team(team)
keys = ["org", "team_name"]
m = team.match(/(.+)\/(.+)/)
items = m ? m.captures : ["", team]

return Hash[keys.zip(items)]
end

def self.name_and_login(obj)
if obj["name"] && !obj["name"].empty?
"#{obj["name"]} (@#{obj["login"]})"
Expand Down
8 changes: 6 additions & 2 deletions request_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
exit(1)
end

if ARGV.length < 2
if ARGV.length < 2 && !ENV["GITHUB_TEAM"]
puts "Usage: #{__FILE__} <github pull request url> <team name>"
exit(2)
end

parsed = Github.parse_pull_request_url(ARGV[0])
team_name = ARGV[1]
if ARGV.length > 1
team_name = Github.parse_org_and_team(ARGV[1])["team_name"]
else
team_name = Github.parse_org_and_team(ENV["GITHUB_TEAM"])["team_name"]
end

pr = Github.pull_request_by_number(parsed["org"], parsed["repo"], parsed["pr_number"].to_i)

Expand Down
13 changes: 9 additions & 4 deletions team_prs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
exit(1)
end

if ARGV.length < 1
if ARGV.length < 1 && !ENV["GITHUB_TEAM"]
puts "Usage: #{__FILE__} <team name as org/team>"
exit(2)
end

org, team = ARGV[0].match(/(.+)\/(.+)/).captures
if ARGV.length > 0
team_name = ARGV[0]
else
team_name = ENV["GITHUB_TEAM"]
end
parsed_team = Github.parse_org_and_team(team_name)

team = Github.team_members(org, team)
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)
Expand All @@ -25,7 +30,7 @@
puts "│   "
no_prs = []
team.each_with_index do |member, i|
prs = Github.pull_requests_for_login(member["login"]).reject { |pr| pr["owner"].downcase != org.downcase }
prs = Github.pull_requests_for_login(member["login"]).reject { |pr| pr["owner"].downcase != parsed_team["org"].downcase }

if !prs.empty?
Github.puts_multiple_pull_requests(prs, { prefix: "│   " })
Expand Down

0 comments on commit 7522836

Please sign in to comment.