mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
Added API to list contributors
This commit is contained in:
@@ -1093,6 +1093,27 @@ public class GHRepository extends GHObject {
|
||||
}
|
||||
}
|
||||
|
||||
public PagedIterable<Contributor> listContributors() throws IOException {
|
||||
return new PagedIterable<Contributor>() {
|
||||
public PagedIterator<Contributor> iterator() {
|
||||
return new PagedIterator<Contributor>(root.retrieve().asIterator(getApiTailUrl("contributors"), Contributor[].class)) {
|
||||
@Override
|
||||
protected void wrapUp(Contributor[] page) {
|
||||
for (Contributor c : page)
|
||||
c.wrapUp(root);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class Contributor extends GHUser {
|
||||
private int contributions;
|
||||
|
||||
public int getContributions() {
|
||||
return contributions;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.kohsuke.github.GHRepository.Contributor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -21,6 +22,24 @@ public class RepositoryTest extends AbstractGitHubApiTestBase {
|
||||
assertNull(r.getSubscription());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listContributors() throws IOException {
|
||||
GHRepository r = gitHub.getOrganization("stapler").getRepository("stapler");
|
||||
int i=0;
|
||||
boolean kohsuke = false;
|
||||
|
||||
for (Contributor c : r.listContributors()) {
|
||||
System.out.println(c.getName());
|
||||
assertTrue(c.getContributions()>0);
|
||||
if (c.getLogin().equals("kohsuke"))
|
||||
kohsuke = true;
|
||||
if (i++ > 5)
|
||||
break;
|
||||
}
|
||||
|
||||
assertTrue(kohsuke);
|
||||
}
|
||||
|
||||
private GHRepository getRepository() throws IOException {
|
||||
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user