From 150b45e3f1127c7c98b850b847c95a718032549d Mon Sep 17 00:00:00 2001 From: James Dennes Date: Sat, 7 Jun 2014 17:14:19 +0200 Subject: [PATCH] Implement ContributionChecker::Checker#user_has_fork_of_repo? --- lib/contribution-checker/checker.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/contribution-checker/checker.rb b/lib/contribution-checker/checker.rb index 817684e..add9a6c 100644 --- a/lib/contribution-checker/checker.rb +++ b/lib/contribution-checker/checker.rb @@ -72,7 +72,7 @@ def check }, :or_criteria => { :user_has_starred_repo => @user_has_starred_repo, - :user_can_push_to_repo => @user_can_push_to_repo_or_is_org_member, + :user_can_push_to_repo => @user_can_push_to_repo, :user_is_repo_org_member => @user_is_repo_org_member, :user_has_fork_of_repo => @user_has_fork_of_repo, } @@ -168,7 +168,17 @@ def user_can_push_to_repo? # # @return [Boolean] def user_has_fork_of_repo? - true # TODO — Implement this. + # The API doesn't provide a simple means of checking whether a user has + # forked a repository. Here we need to get the user's forks and check the + # `parent` field of each fork to see whether it matches @repo. + @client.auto_paginate = true + @user_repos = @client.repos + @user_forks = @user_repos.select { |r| r[:fork] } + @user_forks.each do |f| + r = @client.repository f[:full_name] + return true if r[:parent][:full_name] == @repo[:full_name] + end + false end # Checks whether the "and" criteria for counting a commit as a contribution