mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
improving the usability by introducing a set with lookup-by-ID
This commit is contained in:
23
pom.xml
23
pom.xml
@@ -25,6 +25,23 @@
|
||||
</site>
|
||||
</distributionManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.infradna.tool</groupId>
|
||||
<artifactId>bridge-method-injector</artifactId>
|
||||
<version>1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>process</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jvnet.hudson</groupId>
|
||||
@@ -54,6 +71,12 @@
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.infradna.tool</groupId>
|
||||
<artifactId>bridge-method-annotation</artifactId>
|
||||
<version>1.4</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<reporting>
|
||||
|
||||
36
src/main/java/org/kohsuke/github/GHPersonSet.java
Normal file
36
src/main/java/org/kohsuke/github/GHPersonSet.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* Set of {@link GHPerson} with helper lookup methods.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class GHPersonSet<T extends GHPerson> extends HashSet<T> {
|
||||
public GHPersonSet() {
|
||||
}
|
||||
|
||||
public GHPersonSet(Collection<? extends T> c) {
|
||||
super(c);
|
||||
}
|
||||
|
||||
public GHPersonSet(int initialCapacity, float loadFactor) {
|
||||
super(initialCapacity, loadFactor);
|
||||
}
|
||||
|
||||
public GHPersonSet(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the item by its login.
|
||||
*/
|
||||
public T byLogin(String login) {
|
||||
for (T t : this)
|
||||
if (t.getLogin().equals(login))
|
||||
return t;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlForm;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlInput;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -143,11 +144,12 @@ public class GHRepository {
|
||||
* Gets the collaborators on this repository.
|
||||
* This set always appear to include the owner.
|
||||
*/
|
||||
public Set<GHUser> getCollaborators() throws IOException {
|
||||
Set<GHUser> r = new HashSet<GHUser>();
|
||||
@WithBridgeMethods(Set.class)
|
||||
public GHPersonSet<GHUser> getCollaborators() throws IOException {
|
||||
GHPersonSet<GHUser> r = new GHPersonSet<GHUser>();
|
||||
for (String u : root.retrieve("/repos/show/"+owner.login+"/"+name+"/collaborators",JsonCollaborators.class).collaborators)
|
||||
r.add(root.getUser(u));
|
||||
return Collections.unmodifiableSet(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
*/
|
||||
package org.kohsuke.github;
|
||||
|
||||
import com.infradna.tool.bridge_method_injector.BridgeMethodsAdded;
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -123,22 +126,25 @@ public class GHUser extends GHPerson {
|
||||
/**
|
||||
* Lists the users that this user is following
|
||||
*/
|
||||
public Set<GHUser> getFollows() throws IOException {
|
||||
@WithBridgeMethods(Set.class)
|
||||
public GHPersonSet<GHUser> getFollows() throws IOException {
|
||||
return root.retrieve("/user/show/"+login+"/following",JsonUsers.class).toSet(root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists the users who are following this user.
|
||||
*/
|
||||
public Set<GHUser> getFollowers() throws IOException {
|
||||
@WithBridgeMethods(Set.class)
|
||||
public GHPersonSet<GHUser> getFollowers() throws IOException {
|
||||
return root.retrieve("/user/show/"+login+"/followers",JsonUsers.class).toSet(root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the organization that this user belongs to publicly.
|
||||
*/
|
||||
public Set<GHOrganization> getOrganizations() throws IOException {
|
||||
Set<GHOrganization> orgs = new HashSet<GHOrganization>();
|
||||
@WithBridgeMethods(Set.class)
|
||||
public GHPersonSet<GHOrganization> getOrganizations() throws IOException {
|
||||
GHPersonSet<GHOrganization> orgs = new GHPersonSet<GHOrganization>();
|
||||
Set<String> names = new HashSet<String>();
|
||||
for (GHOrganization o : root.retrieve3("/users/"+login+"/orgs",GHOrganization[].class)) {
|
||||
if (names.add(o.getLogin())) // I've seen some duplicates in the data
|
||||
|
||||
@@ -34,8 +34,8 @@ import java.util.Set;
|
||||
class JsonUsers {
|
||||
public List<String> users;
|
||||
|
||||
public Set<GHUser> toSet(GitHub root) throws IOException {
|
||||
Set<GHUser> r = new HashSet<GHUser>();
|
||||
public GHPersonSet<GHUser> toSet(GitHub root) throws IOException {
|
||||
GHPersonSet<GHUser> r = new GHPersonSet<GHUser>();
|
||||
for (String u : users)
|
||||
r.add(root.getUser(u));
|
||||
return r;
|
||||
|
||||
Reference in New Issue
Block a user