Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit beae9fd

Browse filesBrowse files
committed
Added support for the extended stargazers API in Github V3 API
1 parent d30b040 commit beae9fd
Copy full SHA for beae9fd

File tree

Expand file treeCollapse file tree

2 files changed

+73
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+73
-1
lines changed

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,12 +935,36 @@ public PagedIterable<GHUser> listSubscribers() {
935935
}
936936

937937
/**
938-
* Lists all the users who have starred this repo.
938+
* Lists all the users who have starred this repo based on the old version of the API. For
939+
* additional information, like date when the repository was starred, see {@link #listExtendedStargazers()}
939940
*/
940941
public PagedIterable<GHUser> listStargazers() {
941942
return listUsers("stargazers");
942943
}
943944

945+
/**
946+
* Lists all the users who have starred this repo based on new version of the API, having extended
947+
* information like the time when the repository was starred. For compatibility with the old API
948+
* see {@link #listStargazers()}
949+
*/
950+
public PagedIterable<GHStargazer> listExtendedStargazers() {
951+
return new PagedIterable<GHStargazer>() {
952+
@Override
953+
public PagedIterator<GHStargazer> _iterator(int pageSize) {
954+
Requester requester = root.retrieve();
955+
requester.setHeader("Accept", "application/vnd.github.v3.star+json");
956+
return new PagedIterator<GHStargazer>(requester.asIterator(getApiTailUrl("stargazers"), GHStargazer[].class, pageSize)) {
957+
@Override
958+
protected void wrapUp(GHStargazer[] page) {
959+
for (GHStargazer c : page) {
960+
c.wrapUp(GHRepository.this);
961+
}
962+
}
963+
};
964+
}
965+
};
966+
}
967+
944968
private PagedIterable<GHUser> listUsers(final String suffix) {
945969
return new PagedIterable<GHUser>() {
946970
public PagedIterator<GHUser> _iterator(int pageSize) {
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.kohsuke.github;
2+
3+
import java.util.Date;
4+
5+
/**
6+
* A stargazer at a repository on GitHub.
7+
*
8+
* @author noctarius
9+
*/
10+
public class GHStargazer {
11+
12+
private GHRepository repository;
13+
private String starred_at;
14+
private GHUser user;
15+
16+
/**
17+
* Gets the repository that is stargazed
18+
*
19+
* @return the starred repository
20+
*/
21+
public GHRepository getRepository() {
22+
return repository;
23+
}
24+
25+
/**
26+
* Gets the date when the repository was starred, however old stars before
27+
* August 2012, will all show the date the API was changed to support starred_at.
28+
*
29+
* @return the date the stargazer was added
30+
*/
31+
public Date getStarredAt() {
32+
return GitHub.parseDate(starred_at);
33+
}
34+
35+
/**
36+
* Gets the user that starred the repository
37+
*
38+
* @return the stargazer user
39+
*/
40+
public GHUser getUser() {
41+
return user;
42+
}
43+
44+
void wrapUp(GHRepository repository) {
45+
this.repository = repository;
46+
user.wrapUp(repository.root);
47+
}
48+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.