Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 3bb7eb2

Browse files
committed
Added API to list contributors
1 parent 11fcb9d commit 3bb7eb2

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,27 @@ public GHSubscription getSubscription() throws IOException {
10931093
}
10941094
}
10951095

1096+
public PagedIterable<Contributor> listContributors() throws IOException {
1097+
return new PagedIterable<Contributor>() {
1098+
public PagedIterator<Contributor> iterator() {
1099+
return new PagedIterator<Contributor>(root.retrieve().asIterator(getApiTailUrl("contributors"), Contributor[].class)) {
1100+
@Override
1101+
protected void wrapUp(Contributor[] page) {
1102+
for (Contributor c : page)
1103+
c.wrapUp(root);
1104+
}
1105+
};
1106+
}
1107+
};
1108+
}
1109+
1110+
public static class Contributor extends GHUser {
1111+
private int contributions;
1112+
1113+
public int getContributions() {
1114+
return contributions;
1115+
}
1116+
}
10961117

10971118

10981119

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.kohsuke.github;
22

33
import org.junit.Test;
4+
import org.kohsuke.github.GHRepository.Contributor;
45

56
import java.io.IOException;
67

@@ -21,6 +22,24 @@ public void subscription() throws Exception {
2122
assertNull(r.getSubscription());
2223
}
2324

25+
@Test
26+
public void listContributors() throws IOException {
27+
GHRepository r = gitHub.getOrganization("stapler").getRepository("stapler");
28+
int i=0;
29+
boolean kohsuke = false;
30+
31+
for (Contributor c : r.listContributors()) {
32+
System.out.println(c.getName());
33+
assertTrue(c.getContributions()>0);
34+
if (c.getLogin().equals("kohsuke"))
35+
kohsuke = true;
36+
if (i++ > 5)
37+
break;
38+
}
39+
40+
assertTrue(kohsuke);
41+
}
42+
2443
private GHRepository getRepository() throws IOException {
2544
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
2645
}

0 commit comments

Comments
 (0)