lib/gitlab_reviewbot/gitlab.rb in danger-gitlab_reviewbot-1.0.0 vs lib/gitlab_reviewbot/gitlab.rb in danger-gitlab_reviewbot-1.0.1

- old
+ new

@@ -9,10 +9,14 @@ def initialize(id, username, review_count = 0) @id = id @username = username @review_count = review_count end + + def ==(other) + id == other.id + end end class Client < API def fetch_users_for_group(group_name) group_id = search_group(group_name) @@ -38,11 +42,23 @@ merge_requests(project_id, :state => 'opened', :per_page => '100').select { |mr| mr.merge_status != 'can_be_merged' } end def users_with_pending_mr_review(project_id) outstanding_mrs = fetch_mrs_requiring_review(project_id) - outstanding_mrs.reduce([]) { |acc, mr| acc + mr.assignees} - .map { |a| User.new(a['id'], a['username']) } + all_assignees = outstanding_mrs.reduce([]) { |acc, mr| acc + mr.assignees } + assignees_id_map = all_assignees.reduce({}) { |acc, a| + aid = a['id'] + ausername = a['username'] + assignee = acc[aid] || User.new(aid, ausername) + assignee.review_count += 1 + acc[aid] = assignee + acc + } + assignees_id_map.values + end + + def fetch_mr_reviewers(project_id, mr_iid) + merge_request(project_id, mr_iid).assignees.map { |u| User.new(u['id'], u['username']) } end private def search_group(group_name) short_name = group_name.split('/').last