mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
Merge pull request #272 from noctarius/master
Added support for the extended stargazers API in Github V3 API
This commit is contained in:
@@ -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<GHUser> 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<GHStargazer> listExtendedStargazers() {
|
||||
return new PagedIterable<GHStargazer>() {
|
||||
@Override
|
||||
public PagedIterator<GHStargazer> _iterator(int pageSize) {
|
||||
Requester requester = root.retrieve();
|
||||
requester.setHeader("Accept", "application/vnd.github.v3.star+json");
|
||||
return new PagedIterator<GHStargazer>(requester.asIterator(getApiTailUrl("stargazers"), GHStargazer[].class, pageSize)) {
|
||||
@Override
|
||||
protected void wrapUp(GHStargazer[] page) {
|
||||
for (GHStargazer c : page) {
|
||||
c.wrapUp(GHRepository.this);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private PagedIterable<GHUser> listUsers(final String suffix) {
|
||||
return new PagedIterable<GHUser>() {
|
||||
public PagedIterator<GHUser> _iterator(int pageSize) {
|
||||
|
||||
48
src/main/java/org/kohsuke/github/GHStargazer.java
Normal file
48
src/main/java/org/kohsuke/github/GHStargazer.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user