Issue #309: Added user listing

This commit is contained in:
Kohsuke Kawaguchi
2016-11-16 18:26:43 -08:00
parent 1c162c6390
commit 818f6dc045
2 changed files with 28 additions and 0 deletions

View File

@@ -392,6 +392,23 @@ public class GitHub {
};
}
/**
* Returns a list of all users.
*/
public PagedIterable<GHUser> listUsers() throws IOException {
return new PagedIterable<GHUser>() {
public PagedIterator<GHUser> _iterator(int pageSize) {
return new PagedIterator<GHUser>(retrieve().asIterator("/users", GHUser[].class, pageSize)) {
@Override
protected void wrapUp(GHUser[] page) {
for (GHUser u : page)
u.wrapUp(GitHub.this);
}
};
}
};
}
/**
* Returns the full details for a license
*

View File

@@ -7,6 +7,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.notNullValue;
@@ -145,4 +147,13 @@ public class GitHubTest {
assertTrue(ioe.getMessage().contains("private mode enabled"));
}
}
@Test
public void listUsers() throws IOException {
GitHub hub = GitHub.connect();
for (GHUser u : Iterables.limit(hub.listUsers(),10)) {
assert u.getName()!=null;
System.out.println(u.getName());
}
}
}