Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da46b7f

Browse filesBrowse files
committed
GHMyself should allow accessing the private repos and orgs too
1 parent c96e6c7 commit da46b7f
Copy full SHA for da46b7f

File tree

Expand file treeCollapse file tree

1 file changed

+49
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+49
-1
lines changed

‎src/main/java/org/kohsuke/github/GHMyself.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHMyself.java
+49-1Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import java.io.IOException;
44
import java.util.Arrays;
55
import java.util.Collections;
6+
import java.util.HashSet;
7+
import java.util.Iterator;
68
import java.util.List;
9+
import java.util.Map;
10+
import java.util.Set;
11+
import java.util.TreeMap;
712

813
/**
914
* Represents the account that's logging into GitHub.
@@ -35,7 +40,50 @@ public List<String> getEmails() throws IOException {
3540
public List<GHKey> getPublicKeys() throws IOException {
3641
return Collections.unmodifiableList(Arrays.asList(root.retrieve().to("/user/keys", GHKey[].class)));
3742
}
38-
43+
44+
/**
45+
* Gets the organization that this user belongs to.
46+
*/
47+
public GHPersonSet<GHOrganization> getAllOrganizations() throws IOException {
48+
GHPersonSet<GHOrganization> orgs = new GHPersonSet<GHOrganization>();
49+
Set<String> names = new HashSet<String>();
50+
for (GHOrganization o : root.retrieve().to("/user/orgs", GHOrganization[].class)) {
51+
if (names.add(o.getLogin())) // in case of rumoured duplicates in the data
52+
orgs.add(root.getOrganization(o.getLogin()));
53+
}
54+
return orgs;
55+
}
56+
57+
/**
58+
* Gets the all repositories this user owns (public and private).
59+
*/
60+
public synchronized Map<String,GHRepository> getAllRepositories() throws IOException {
61+
Map<String,GHRepository> repositories = new TreeMap<String, GHRepository>();
62+
for (GHRepository r : listAllRepositories()) {
63+
repositories.put(r.getName(),r);
64+
}
65+
return Collections.unmodifiableMap(repositories);
66+
}
67+
68+
/**
69+
* Lists up all repositories this user owns (public and private).
70+
*
71+
* Unlike {@link #getAllRepositories()}, this does not wait until all the repositories are returned.
72+
*/
73+
public PagedIterable<GHRepository> listAllRepositories() {
74+
return new PagedIterable<GHRepository>() {
75+
public PagedIterator<GHRepository> iterator() {
76+
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/user/repos", GHRepository[].class)) {
77+
@Override
78+
protected void wrapUp(GHRepository[] page) {
79+
for (GHRepository c : page)
80+
c.wrap(root);
81+
}
82+
};
83+
}
84+
};
85+
}
86+
3987
// public void addEmails(Collection<String> emails) throws IOException {
4088
//// new Requester(root,ApiVersion.V3).withCredential().to("/user/emails");
4189
// root.retrieveWithAuth3()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.