Skip to content

Commit c8f4815

Browse files
augustdbitwiseman
andauthored
Add parameter to listContributors for anonymous contributors (hub4j#1907)
* Add listContributors method parameter to determine whether to include anonymous contributors. Fixes hub4j#1905 * Add Javadoc link annotation * Add test * Update src/main/java/org/kohsuke/github/GHRepository.java Committing @bitwiseman suggestion Co-authored-by: Liam Newman <bitwiseman@gmail.com> * Update src/main/java/org/kohsuke/github/GHRepository.java Committing @bitwiseman suggestion Co-authored-by: Liam Newman <bitwiseman@gmail.com> * Fix javadoc * Update tests * Change assertion style --------- Co-authored-by: Liam Newman <bitwiseman@gmail.com>
1 parent 4732768 commit c8f4815

File tree

12 files changed

+1172
-1
lines changed

12 files changed

+1172
-1
lines changed

src/main/java/org/kohsuke/github/GHRepository.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2723,7 +2723,25 @@ public List<GHCodeownersError> listCodeownersErrors() throws IOException {
27232723
* the io exception
27242724
*/
27252725
public PagedIterable<Contributor> listContributors() throws IOException {
2726-
return root().createRequest().withUrlPath(getApiTailUrl("contributors")).toIterable(Contributor[].class, null);
2726+
return listContributors(null);
2727+
}
2728+
2729+
/**
2730+
* List contributors paged iterable.
2731+
*
2732+
* @param includeAnonymous
2733+
* whether to include anonymous contributors
2734+
* @return the paged iterable
2735+
* @throws IOException
2736+
* the io exception
2737+
* @see <a href="https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-contributors">
2738+
* GitHub API - List Repository Contributors</a>
2739+
*/
2740+
public PagedIterable<Contributor> listContributors(Boolean includeAnonymous) throws IOException {
2741+
return root().createRequest()
2742+
.withUrlPath(getApiTailUrl("contributors"))
2743+
.with("anon", includeAnonymous)
2744+
.toIterable(Contributor[].class, null);
27272745
}
27282746

27292747
/**

src/test/java/org/kohsuke/github/GHRepositoryTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,31 @@ public void listContributors() throws IOException {
507507
assertThat(kohsuke, is(true));
508508
}
509509

510+
/**
511+
* List contributors.
512+
*
513+
* @throws IOException
514+
* Signals that an I/O exception has occurred.
515+
*/
516+
@Test
517+
public void listContributorsAnon() throws IOException {
518+
GHRepository r = gitHub.getOrganization("hub4j").getRepository("github-api");
519+
int i = 0;
520+
boolean kohsuke = false;
521+
522+
for (GHRepository.Contributor c : r.listContributors(true)) {
523+
if (c.getType().equals("Anonymous")) {
524+
assertThat(c.getContributions(), is(3));
525+
kohsuke = true;
526+
}
527+
if (++i > 1) {
528+
break;
529+
}
530+
}
531+
532+
assertThat(kohsuke, is(true));
533+
}
534+
510535
/**
511536
* Gets the permission.
512537
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"login": "bitwiseman",
3+
"id": 1958953,
4+
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
5+
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/bitwiseman",
8+
"html_url": "https://github.com/bitwiseman",
9+
"followers_url": "https://api.github.com/users/bitwiseman/followers",
10+
"following_url": "https://api.github.com/users/bitwiseman/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/bitwiseman/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/bitwiseman/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/bitwiseman/subscriptions",
14+
"organizations_url": "https://api.github.com/users/bitwiseman/orgs",
15+
"repos_url": "https://api.github.com/users/bitwiseman/repos",
16+
"events_url": "https://api.github.com/users/bitwiseman/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/bitwiseman/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Liam Newman",
21+
"company": "Cloudbees, Inc.",
22+
"blog": "",
23+
"location": "Seattle, WA, USA",
24+
"email": "bitwiseman@gmail.com",
25+
"hireable": null,
26+
"bio": "https://twitter.com/bitwiseman",
27+
"public_repos": 167,
28+
"public_gists": 4,
29+
"followers": 136,
30+
"following": 9,
31+
"created_at": "2012-07-11T20:38:33Z",
32+
"updated_at": "2019-09-24T19:32:29Z",
33+
"private_gists": 7,
34+
"total_private_repos": 9,
35+
"owned_private_repos": 0,
36+
"disk_usage": 33697,
37+
"collaborators": 0,
38+
"two_factor_authentication": true,
39+
"plan": {
40+
"name": "free",
41+
"space": 976562499,
42+
"collaborators": 0,
43+
"private_repos": 10000
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"login": "kohsuke",
3+
"id": 50003,
4+
"node_id": "MDQ6VXNlcjUwMDAz",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/50003?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/kohsuke",
8+
"html_url": "https://github.com/kohsuke",
9+
"followers_url": "https://api.github.com/users/kohsuke/followers",
10+
"following_url": "https://api.github.com/users/kohsuke/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions",
14+
"organizations_url": "https://api.github.com/users/kohsuke/orgs",
15+
"repos_url": "https://api.github.com/users/kohsuke/repos",
16+
"events_url": "https://api.github.com/users/kohsuke/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/kohsuke/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Kohsuke Kawaguchi",
21+
"company": "@launchableinc ",
22+
"blog": "https://www.kohsuke.org/",
23+
"location": "San Jose, California",
24+
"email": "kk@kohsuke.org",
25+
"hireable": null,
26+
"bio": null,
27+
"twitter_username": null,
28+
"public_repos": 265,
29+
"public_gists": 113,
30+
"followers": 1999,
31+
"following": 3,
32+
"created_at": "2009-01-28T18:53:21Z",
33+
"updated_at": "2022-04-10T22:58:15Z"
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"login": "hub4j",
3+
"id": 54909825,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
5+
"url": "https://api.github.com/orgs/hub4j",
6+
"repos_url": "https://api.github.com/orgs/hub4j/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 1,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/hub4j",
22+
"created_at": "2019-09-04T18:12:34Z",
23+
"updated_at": "2019-09-04T18:12:34Z",
24+
"type": "Organization",
25+
"total_private_repos": 0,
26+
"owned_private_repos": 0,
27+
"private_gists": 0,
28+
"disk_usage": 11899,
29+
"collaborators": 0,
30+
"billing_email": "bitwiseman@gmail.com",
31+
"default_repository_permission": "read",
32+
"members_can_create_repositories": true,
33+
"two_factor_requirement_enabled": false,
34+
"plan": {
35+
"name": "free",
36+
"space": 976562499,
37+
"private_repos": 0,
38+
"filled_seats": 2,
39+
"seats": 0
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"id": 617210,
3+
"node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=",
4+
"name": "github-api",
5+
"full_name": "hub4j/github-api",
6+
"private": false,
7+
"owner": {
8+
"login": "hub4j",
9+
"id": 54909825,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
11+
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/hub4j",
14+
"html_url": "https://github.com/hub4j",
15+
"followers_url": "https://api.github.com/users/hub4j/followers",
16+
"following_url": "https://api.github.com/users/hub4j/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/hub4j/subscriptions",
20+
"organizations_url": "https://api.github.com/users/hub4j/orgs",
21+
"repos_url": "https://api.github.com/users/hub4j/repos",
22+
"events_url": "https://api.github.com/users/hub4j/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/hub4j/received_events",
24+
"type": "Organization",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/hub4j/github-api",
28+
"description": "Java API for GitHub",
29+
"fork": false,
30+
"url": "https://api.github.com/repos/hub4j/github-api",
31+
"forks_url": "https://api.github.com/repos/hub4j/github-api/forks",
32+
"keys_url": "https://api.github.com/repos/hub4j/github-api/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/hub4j/github-api/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/hub4j/github-api/teams",
35+
"hooks_url": "https://api.github.com/repos/hub4j/github-api/hooks",
36+
"issue_events_url": "https://api.github.com/repos/hub4j/github-api/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/hub4j/github-api/events",
38+
"assignees_url": "https://api.github.com/repos/hub4j/github-api/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/hub4j/github-api/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/hub4j/github-api/tags",
41+
"blobs_url": "https://api.github.com/repos/hub4j/github-api/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/hub4j/github-api/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/hub4j/github-api/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/hub4j/github-api/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/hub4j/github-api/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/hub4j/github-api/languages",
47+
"stargazers_url": "https://api.github.com/repos/hub4j/github-api/stargazers",
48+
"contributors_url": "https://api.github.com/repos/hub4j/github-api/contributors?anon=true",
49+
"subscribers_url": "https://api.github.com/repos/hub4j/github-api/subscribers",
50+
"subscription_url": "https://api.github.com/repos/hub4j/github-api/subscription",
51+
"commits_url": "https://api.github.com/repos/hub4j/github-api/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/hub4j/github-api/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/hub4j/github-api/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/hub4j/github-api/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/hub4j/github-api/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/hub4j/github-api/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/hub4j/github-api/merges",
58+
"archive_url": "https://api.github.com/repos/hub4j/github-api/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/hub4j/github-api/downloads",
60+
"issues_url": "https://api.github.com/repos/hub4j/github-api/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/hub4j/github-api/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/hub4j/github-api/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/hub4j/github-api/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/hub4j/github-api/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments",
67+
"created_at": "2010-04-19T04:13:03Z",
68+
"updated_at": "2019-10-03T09:41:10Z",
69+
"pushed_at": "2019-10-02T22:27:45Z",
70+
"git_url": "git://github.com/hub4j/github-api.git",
71+
"ssh_url": "git@github.com:hub4j/github-api.git",
72+
"clone_url": "https://github.com/hub4j/github-api.git",
73+
"svn_url": "https://github.com/hub4j/github-api",
74+
"homepage": "http://github-api.kohsuke.org/",
75+
"size": 11899,
76+
"stargazers_count": 557,
77+
"watchers_count": 557,
78+
"language": "Java",
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": true,
83+
"has_pages": true,
84+
"forks_count": 428,
85+
"mirror_url": null,
86+
"archived": false,
87+
"disabled": false,
88+
"open_issues_count": 90,
89+
"license": {
90+
"key": "mit",
91+
"name": "MIT License",
92+
"spdx_id": "MIT",
93+
"url": "https://api.github.com/licenses/mit",
94+
"node_id": "MDc6TGljZW5zZTEz"
95+
},
96+
"forks": 428,
97+
"open_issues": 90,
98+
"watchers": 557,
99+
"default_branch": "main",
100+
"permissions": {
101+
"admin": true,
102+
"push": true,
103+
"pull": true
104+
},
105+
"allow_squash_merge": true,
106+
"allow_merge_commit": true,
107+
"allow_rebase_merge": true,
108+
"organization": {
109+
"login": "hub4j",
110+
"id": 54909825,
111+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
112+
"avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4",
113+
"gravatar_id": "",
114+
"url": "https://api.github.com/users/hub4j",
115+
"html_url": "https://github.com/hub4j",
116+
"followers_url": "https://api.github.com/users/hub4j/followers",
117+
"following_url": "https://api.github.com/users/hub4j/following{/other_user}",
118+
"gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}",
119+
"starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}",
120+
"subscriptions_url": "https://api.github.com/users/hub4j/subscriptions",
121+
"organizations_url": "https://api.github.com/users/hub4j/orgs",
122+
"repos_url": "https://api.github.com/users/hub4j/repos",
123+
"events_url": "https://api.github.com/users/hub4j/events{/privacy}",
124+
"received_events_url": "https://api.github.com/users/hub4j/received_events",
125+
"type": "Organization",
126+
"site_admin": false
127+
},
128+
"network_count": 428,
129+
"subscribers_count": 50
130+
}

0 commit comments

Comments
 (0)