Skip to content

Commit

Permalink
Clean up GHPerson deprecated a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Feb 27, 2020
1 parent 944d92b commit 5e5708d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
<exclude>org.kohsuke.github.extras.OkHttp3Connector</exclude>
<exclude>org.kohsuke.github.EnforcementLevel</exclude>
<exclude>org.kohsuke.github.GHPerson.1</exclude>
<exclude>org.kohsuke.github.GHPerson.1.1</exclude>

<!-- These fail coverage on windows because tests are disabled -->
<exclude>org.kohsuke.github.GHAsset</exclude>
Expand Down
57 changes: 24 additions & 33 deletions src/main/java/org/kohsuke/github/GHPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
Expand All @@ -20,7 +19,7 @@ public abstract class GHPerson extends GHObject {
/* package almost final */ GitHub root;

// core data fields that exist even for "small" user data (such as the user info in pull request)
protected String login, avatar_url, gravatar_id;
protected String login, avatar_url;

// other fields (that only show up in full data)
protected String location, blog, email, name, company, type;
Expand Down Expand Up @@ -115,31 +114,27 @@ public PagedIterable<GHRepository> listRepositories(final int pageSize) {
*/
@Deprecated
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
return new Iterable<List<GHRepository>>() {
public Iterator<List<GHRepository>> iterator() {
final Iterator<GHRepository[]> pager;
try {
pager = GitHubPageIterator.create(root.getClient(),
GHRepository[].class,
root.createRequest().withUrlPath("users", login, "repos").build(),
pageSize);
} catch (MalformedURLException e) {
throw new GHException("Unable to build GitHub API URL", e);
return () -> {
final PagedIterator<GHRepository> pager;
try {
GitHubPageIterator<GHRepository[]> iterator = GitHubPageIterator.create(root.getClient(),
GHRepository[].class,
root.createRequest().withUrlPath("users", login, "repos").build(),
pageSize);
pager = new PagedIterator<>(iterator, item -> item.wrap(root));
} catch (MalformedURLException e) {
throw new GHException("Unable to build GitHub API URL", e);
}

return new Iterator<List<GHRepository>>() {
public boolean hasNext() {
return pager.hasNext();
}

return new Iterator<List<GHRepository>>() {
public boolean hasNext() {
return pager.hasNext();
}

public List<GHRepository> next() {
GHRepository[] batch = pager.next();
for (GHRepository r : batch)
r.root = root;
return Arrays.asList(batch);
}
};
}
public List<GHRepository> next() {
return pager.nextPage();
}
};
};
}

Expand Down Expand Up @@ -178,22 +173,18 @@ public GHRepository getRepository(String name) throws IOException {
* @return the gravatar id
* @deprecated No longer available in the v3 API.
*/
@Deprecated
public String getGravatarId() {
return gravatar_id;
return "";
}

/**
* Returns a string like 'https://secure.gravatar.com/avatar/0cb9832a01c22c083390f3c5dcb64105' that indicates the
* avatar image URL.
* Returns a string of the avatar image URL.
*
* @return the avatar url
*/
public String getAvatarUrl() {
if (avatar_url != null)
return avatar_url;
if (gravatar_id != null)
return "https://secure.gravatar.com/avatar/" + gravatar_id;
return null;
return avatar_url;
}

/**
Expand Down

0 comments on commit 5e5708d

Please sign in to comment.