lib/reviewer/plugin.rb in danger-reviewer-0.0.4 vs lib/reviewer/plugin.rb in danger-reviewer-0.0.5
- old
+ new
@@ -7,11 +7,11 @@
class DangerReviewer < Plugin
def assign(team, max_reviewers = 2, user_blacklist = [])
current_count = current_reviewers_count
# Check if we already have enough reviewers
- return if current_count >= max_reviewers
+ return if current_count >= max_reviewers || current_count == -1
authors = find_authors
members = team_members(team)
reviewers = find_reviewers((authors & members), members, user_blacklist, (max_reviewers - current_count))
@@ -40,11 +40,11 @@
users = Hash.new(0)
git.modified_files.each do |file|
result = GitHub::Client.query(GitHub::BlameQuery, variables: { repository: repo, owner: owner, ref: branch, file: file })
- next if result.data.repository.ref.nil?
+ next if result.data.nil? || result.data.repository.ref.nil?
result.data.repository.ref.target.blame.ranges.each do |range|
lines = (range.ending_line - range.starting_line) + 1
users[range.commit.author.user.login] += lines unless range.commit.author.user.nil?
end
end
@@ -71,15 +71,19 @@
def current_reviewers_count
owner, repo = env.ci_source.repo_slug.split('/')
result = GitHub::Client.query(GitHub::ReviewerQuery, variables: { repo: repo, owner: owner, number: github.pr_json[:number] })
+ return -1 if result.data.nil?
+
result.data.repository.pull_request.review_requests.edges.count + result.data.repository.pull_request.reviews.edges.count
end
def team_members(team)
owner, repo = env.ci_source.repo_slug.split('/')
result = GitHub::Client.query(GitHub::MemberQuery, variables: { organization: owner, team: team})
+ return [] if result.data.nil?
+
result.data.organization.team.members.edges.map { |edge| edge.node.login }
end
end
end