diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 326564e52..26cba1308 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -935,12 +935,36 @@ public class GHRepository extends GHObject { } /** - * Lists all the users who have starred this repo. + * Lists all the users who have starred this repo based on the old version of the API. For + * additional information, like date when the repository was starred, see {@link #listExtendedStargazers()} */ public PagedIterable listStargazers() { return listUsers("stargazers"); } + /** + * Lists all the users who have starred this repo based on new version of the API, having extended + * information like the time when the repository was starred. For compatibility with the old API + * see {@link #listStargazers()} + */ + public PagedIterable listExtendedStargazers() { + return new PagedIterable() { + @Override + public PagedIterator _iterator(int pageSize) { + Requester requester = root.retrieve(); + requester.setHeader("Accept", "application/vnd.github.v3.star+json"); + return new PagedIterator(requester.asIterator(getApiTailUrl("stargazers"), GHStargazer[].class, pageSize)) { + @Override + protected void wrapUp(GHStargazer[] page) { + for (GHStargazer c : page) { + c.wrapUp(GHRepository.this); + } + } + }; + } + }; + } + private PagedIterable listUsers(final String suffix) { return new PagedIterable() { public PagedIterator _iterator(int pageSize) { diff --git a/src/main/java/org/kohsuke/github/GHStargazer.java b/src/main/java/org/kohsuke/github/GHStargazer.java new file mode 100644 index 000000000..20b3ef8a7 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHStargazer.java @@ -0,0 +1,48 @@ +package org.kohsuke.github; + +import java.util.Date; + +/** + * A stargazer at a repository on GitHub. + * + * @author noctarius + */ +public class GHStargazer { + + private GHRepository repository; + private String starred_at; + private GHUser user; + + /** + * Gets the repository that is stargazed + * + * @return the starred repository + */ + public GHRepository getRepository() { + return repository; + } + + /** + * Gets the date when the repository was starred, however old stars before + * August 2012, will all show the date the API was changed to support starred_at. + * + * @return the date the stargazer was added + */ + public Date getStarredAt() { + return GitHub.parseDate(starred_at); + } + + /** + * Gets the user that starred the repository + * + * @return the stargazer user + */ + public GHUser getUser() { + return user; + } + + void wrapUp(GHRepository repository) { + this.repository = repository; + user.wrapUp(repository.root); + } +}