Skip to content

Commit

Permalink
Added two getUserPublicOrganizations(...) methods to get public Org m…
Browse files Browse the repository at this point in the history
…emberships of any user, not just the currently-authenticated one.
  • Loading branch information
awittha committed May 23, 2019
1 parent 0848556 commit 3745067
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ public List<GHInvitation> getMyInvitations() throws IOException {
* This method returns a shallowly populated organizations.
*
* To retrieve full organization details, you need to call {@link #getOrganization(String)}
* TODO: make this automatic.
*/
public Map<String, GHOrganization> getMyOrganizations() throws IOException {
GHOrganization[] orgs = retrieve().to("/user/orgs", GHOrganization[].class);
Expand All @@ -560,6 +559,32 @@ public Map<String, GHOrganization> getMyOrganizations() throws IOException {
}
return r;
}

/**
* Alias for {@link #getUserPublicOrganizations(String)}.
*/
public Map<String, GHOrganization> getUserPublicOrganizations(GHUser user) throws IOException {
return getUserPublicOrganizations( user.getLogin() );
}

/**
* This method returns a shallowly populated organizations.
*
* To retrieve full organization details, you need to call {@link #getOrganization(String)}
*
* @param user the user to retrieve public Organization membership information for
*
* @return the public Organization memberships for the user
*/
public Map<String, GHOrganization> getUserPublicOrganizations(String login) throws IOException {
GHOrganization[] orgs = retrieve().to("/users/" + login + "/orgs", GHOrganization[].class);
Map<String, GHOrganization> r = new HashMap<String, GHOrganization>();
for (GHOrganization o : orgs) {
// don't put 'o' into orgs because they are shallow
r.put(o.getLogin(),o.wrapUp(this));
}
return r;
}

/**
* Gets complete map of organizations/teams that current user belongs to.
Expand Down

0 comments on commit 3745067

Please sign in to comment.