Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter to listContributors for anonymous contributors #1907

Merged
merged 11 commits into from
Jan 6, 2025
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);
augustd marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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();
augustd marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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
Loading