Skip to content

Commit

Permalink
Issue #309: Added user listing
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Nov 17, 2016
1 parent 1c162c6 commit 818f6dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,23 @@ protected void wrapUp(GHLicense[] page) {
};
}

/**
* 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
*
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/kohsuke/github/GitHubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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;
Expand Down Expand Up @@ -145,4 +147,13 @@ public void testGitHubIsApiUrlValid() throws IOException {
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());
}
}
}

0 comments on commit 818f6dc

Please sign in to comment.