Skip to content
20 changes: 20 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3080,6 +3080,26 @@ public PagedIterable<Contributor> listContributors() throws IOException {
return root().createRequest().withUrlPath(getApiTailUrl("contributors")).toIterable(Contributor[].class, null);
}

/**
* List contributors paged iterable.
*
* @param includeAnonymous
* whether to include anonymous contributors
* @return the paged iterable
* @throws IOException
* the io exception
* @link https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-contributors
*/
public PagedIterable<Contributor> listContributors(boolean includeAnonymous) throws IOException {
if (includeAnonymous) {
return root().createRequest()
.withUrlPath(getApiTailUrl("contributors"))
.with("anon", "true")
.toIterable(Contributor[].class, null);
}
return listContributors();
}

/**
* The type Contributor.
*/
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,30 @@ public void listContributors() throws IOException {
assertThat(kohsuke, is(true));
}

/**
* List contributors.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void listContributorsAnon() throws IOException {
GHRepository r = gitHub.getOrganization("hub4j").getRepository("github-api");
int i = 0;
boolean kohsuke = false;

for (GHRepository.Contributor c : r.listContributors(true)) {
if (c.getLogin().equals("kohsuke")) {
assertThat(c.getContributions(), greaterThan(0));
kohsuke = true;
}
if (i++ > 5) {
break;
}
}

assertThat(kohsuke, is(true));
}
/**
* Gets the permission.
*
Expand Down