Skip to content

Commit 6f90650

Browse files
committed
Fix bug in ContributionChecker::Checker#user_is_repo_org_member? and add test coverage
1 parent da18654 commit 6f90650

File tree

3 files changed

+136
-1
lines changed

3 files changed

+136
-1
lines changed

lib/contribution-checker/checker.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def user_has_starred_repo?
171171
#
172172
# @return [Boolean]
173173
def user_is_repo_org_member?
174-
return false if @repo[:owner] != "Organization"
174+
return false if @repo[:owner][:type] != "Organization"
175175
@client.organization_member? @repo[:owner][:login], @user[:login]
176176
end
177177

spec/contribution-checker/checker_spec.rb

+42
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,48 @@
209209
end
210210
end
211211

212+
213+
context "when a commit is in the default branch and the user is a member of the org owning the repository" do
214+
let(:checker) { checker = ContributionChecker::Checker.new \
215+
:access_token => "token",
216+
:commit_url => "https://github.com/jdennes/contribution-checker/commit/731e83d4abf1bd67ac6ab68d18387693482e47cf"
217+
}
218+
219+
before do
220+
stub_get("/repos/jdennes/contribution-checker/commits/731e83d4abf1bd67ac6ab68d18387693482e47cf").
221+
to_return(json_response("commit.json"))
222+
stub_get("/repos/jdennes/contribution-checker").
223+
to_return(json_response("org_owned_repo.json"))
224+
stub_get("/user").
225+
to_return(json_response("user.json"))
226+
stub_get("/repos/jdennes/contribution-checker/compare/master...731e83d4abf1bd67ac6ab68d18387693482e47cf").
227+
to_return(json_response("default_compare.json"))
228+
stub_get("/user/emails").
229+
to_return(json_response("emails.json"))
230+
stub_get("/user/starred/jdennes/contribution-checker").
231+
to_return(:status => 404)
232+
stub_get("/orgs/github/members/jdennes").
233+
to_return(:status => 204)
234+
end
235+
236+
it "returns the check result" do
237+
result = checker.check
238+
expect(result).to be_a(Hash)
239+
240+
expect(result[:contribution]).to eq(true)
241+
242+
expect(result[:and_criteria][:commit_in_valid_branch]).to eq(true)
243+
expect(result[:and_criteria][:commit_in_last_year]).to eq(true)
244+
expect(result[:and_criteria][:repo_not_a_fork]).to eq(true)
245+
expect(result[:and_criteria][:commit_email_linked_to_user]).to eq(true)
246+
247+
expect(result[:or_criteria][:user_has_starred_repo]).to eq(false)
248+
expect(result[:or_criteria][:user_can_push_to_repo]).to eq(true)
249+
expect(result[:or_criteria][:user_is_repo_org_member]).to eq(true)
250+
expect(result[:or_criteria][:user_has_fork_of_repo]).to eq(false)
251+
end
252+
end
253+
212254
end
213255

214256
end

spec/fixtures/org_owned_repo.json

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"id": 20517235,
3+
"name": "contribution-checker",
4+
"full_name": "jdennes/contribution-checker",
5+
"owner": {
6+
"login": "github",
7+
"id": 65057,
8+
"avatar_url": "https://avatars.githubusercontent.com/u/65057?",
9+
"gravatar_id": "55fd031da91ef9af6e6ed88b101416a1",
10+
"url": "https://api.github.com/users/jdennes",
11+
"html_url": "https://github.com/jdennes",
12+
"followers_url": "https://api.github.com/users/jdennes/followers",
13+
"following_url": "https://api.github.com/users/jdennes/following{/other_user}",
14+
"gists_url": "https://api.github.com/users/jdennes/gists{/gist_id}",
15+
"starred_url": "https://api.github.com/users/jdennes/starred{/owner}{/repo}",
16+
"subscriptions_url": "https://api.github.com/users/jdennes/subscriptions",
17+
"organizations_url": "https://api.github.com/users/jdennes/orgs",
18+
"repos_url": "https://api.github.com/users/jdennes/repos",
19+
"events_url": "https://api.github.com/users/jdennes/events{/privacy}",
20+
"received_events_url": "https://api.github.com/users/jdennes/received_events",
21+
"type": "Organization",
22+
"site_admin": false
23+
},
24+
"private": false,
25+
"html_url": "https://github.com/jdennes/contribution-checker",
26+
"description": "Check whether one of your GitHub commits qualifies as a contribution.",
27+
"fork": false,
28+
"url": "https://api.github.com/repos/jdennes/contribution-checker",
29+
"forks_url": "https://api.github.com/repos/jdennes/contribution-checker/forks",
30+
"keys_url": "https://api.github.com/repos/jdennes/contribution-checker/keys{/key_id}",
31+
"collaborators_url": "https://api.github.com/repos/jdennes/contribution-checker/collaborators{/collaborator}",
32+
"teams_url": "https://api.github.com/repos/jdennes/contribution-checker/teams",
33+
"hooks_url": "https://api.github.com/repos/jdennes/contribution-checker/hooks",
34+
"issue_events_url": "https://api.github.com/repos/jdennes/contribution-checker/issues/events{/number}",
35+
"events_url": "https://api.github.com/repos/jdennes/contribution-checker/events",
36+
"assignees_url": "https://api.github.com/repos/jdennes/contribution-checker/assignees{/user}",
37+
"branches_url": "https://api.github.com/repos/jdennes/contribution-checker/branches{/branch}",
38+
"tags_url": "https://api.github.com/repos/jdennes/contribution-checker/tags",
39+
"blobs_url": "https://api.github.com/repos/jdennes/contribution-checker/git/blobs{/sha}",
40+
"git_tags_url": "https://api.github.com/repos/jdennes/contribution-checker/git/tags{/sha}",
41+
"git_refs_url": "https://api.github.com/repos/jdennes/contribution-checker/git/refs{/sha}",
42+
"trees_url": "https://api.github.com/repos/jdennes/contribution-checker/git/trees{/sha}",
43+
"statuses_url": "https://api.github.com/repos/jdennes/contribution-checker/statuses/{sha}",
44+
"languages_url": "https://api.github.com/repos/jdennes/contribution-checker/languages",
45+
"stargazers_url": "https://api.github.com/repos/jdennes/contribution-checker/stargazers",
46+
"contributors_url": "https://api.github.com/repos/jdennes/contribution-checker/contributors",
47+
"subscribers_url": "https://api.github.com/repos/jdennes/contribution-checker/subscribers",
48+
"subscription_url": "https://api.github.com/repos/jdennes/contribution-checker/subscription",
49+
"commits_url": "https://api.github.com/repos/jdennes/contribution-checker/commits{/sha}",
50+
"git_commits_url": "https://api.github.com/repos/jdennes/contribution-checker/git/commits{/sha}",
51+
"comments_url": "https://api.github.com/repos/jdennes/contribution-checker/comments{/number}",
52+
"issue_comment_url": "https://api.github.com/repos/jdennes/contribution-checker/issues/comments/{number}",
53+
"contents_url": "https://api.github.com/repos/jdennes/contribution-checker/contents/{+path}",
54+
"compare_url": "https://api.github.com/repos/jdennes/contribution-checker/compare/{base}...{head}",
55+
"merges_url": "https://api.github.com/repos/jdennes/contribution-checker/merges",
56+
"archive_url": "https://api.github.com/repos/jdennes/contribution-checker/{archive_format}{/ref}",
57+
"downloads_url": "https://api.github.com/repos/jdennes/contribution-checker/downloads",
58+
"issues_url": "https://api.github.com/repos/jdennes/contribution-checker/issues{/number}",
59+
"pulls_url": "https://api.github.com/repos/jdennes/contribution-checker/pulls{/number}",
60+
"milestones_url": "https://api.github.com/repos/jdennes/contribution-checker/milestones{/number}",
61+
"notifications_url": "https://api.github.com/repos/jdennes/contribution-checker/notifications{?since,all,participating}",
62+
"labels_url": "https://api.github.com/repos/jdennes/contribution-checker/labels{/name}",
63+
"releases_url": "https://api.github.com/repos/jdennes/contribution-checker/releases{/id}",
64+
"created_at": "2014-06-05T08:16:43Z",
65+
"updated_at": "2014-06-08T22:47:25Z",
66+
"pushed_at": "2014-06-08T22:47:22Z",
67+
"git_url": "git://github.com/jdennes/contribution-checker.git",
68+
"ssh_url": "[email protected]:jdennes/contribution-checker.git",
69+
"clone_url": "https://github.com/jdennes/contribution-checker.git",
70+
"svn_url": "https://github.com/jdennes/contribution-checker",
71+
"homepage": "",
72+
"size": 0,
73+
"stargazers_count": 0,
74+
"watchers_count": 0,
75+
"language": "Ruby",
76+
"has_issues": true,
77+
"has_downloads": true,
78+
"has_wiki": false,
79+
"forks_count": 0,
80+
"mirror_url": null,
81+
"open_issues_count": 0,
82+
"forks": 0,
83+
"open_issues": 0,
84+
"watchers": 0,
85+
"default_branch": "master",
86+
"permissions": {
87+
"admin": true,
88+
"push": true,
89+
"pull": true
90+
},
91+
"network_count": 0,
92+
"subscribers_count": 2
93+
}

0 commit comments

Comments
 (0)