Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2018-05-08 15:30:37 -0400
committerThomas Wolf2018-05-08 15:30:37 -0400
commita039ba440106f7fcc4e6fa718771ce3a8d822377 (patch)
treec0dd453cd7f348e9ae31a397c1409dee9bf66b7c /org.eclipse.egit.github.core
parent5fad06251c0b68aa4743fbfde25ad474d73f1a46 (diff)
downloadegit-github-a039ba440106f7fcc4e6fa718771ce3a8d822377.tar.gz
egit-github-a039ba440106f7fcc4e6fa718771ce3a8d822377.tar.xz
egit-github-a039ba440106f7fcc4e6fa718771ce3a8d822377.zip
Fix Repository.getWatchers(); add Repository.getStars()
Per [1] it appears that the JSON returned by Github changed, apparently already in 2012. What Github shows today as the number of "watchers" is stored in field "subscribers_count". Field "watchers" actually is a copy of "stargazers_count" (as is "watchers_count"). So add fields "stargazersCount" and "subscribersCount", but keep the legacy "watchers" field to be able to deal with old serialized (via Gson or via Java serialization) objects. Add tests, including a new test for Gson de-serialization. The test data in test_repo.json is anonymized actual output for an existing repository obtained from the Github API as of 2018-05-08. [1] https://developer.github.com/changes/2012-09-05-watcher-api/ Bug: 534440 Change-Id: I1faba649986ab6ed9e367bfefdb0bbe2fbaf7071 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.github.core')
-rw-r--r--org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java29
1 files changed, 27 insertions, 2 deletions
diff --git a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java
index 132838ce..0f075682 100644
--- a/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java
+++ b/org.eclipse.egit.github.core/src/org/eclipse/egit/github/core/Repository.java
@@ -50,8 +50,14 @@ public class Repository implements IRepositoryIdProvider, Serializable {
private int size;
+ /** Legacy field, kept for backwards compatibility. It's actually the stargazersCount. */
private int watchers;
+ private int stargazersCount;
+
+ /** This is what Github shows as "watchers". */
+ private int subscribersCount = -1;
+
private Repository parent;
private Repository source;
@@ -243,10 +249,29 @@ public class Repository implements IRepositoryIdProvider, Serializable {
}
/**
+ * @return stars
+ * @since 5.0
+ */
+ public int getStars() {
+ return stargazersCount;
+ }
+
+ /**
+ * @param stars
+ * @return this repository
+ * @since 5.0
+ */
+ public Repository setStars(int stars) {
+ this.stargazersCount = stars;
+ return this;
+ }
+
+ /**
* @return watchers
*/
public int getWatchers() {
- return watchers;
+ // Account for legacy serializations that had only the watchers field
+ return subscribersCount < 0 ? watchers : subscribersCount;
}
/**
@@ -254,7 +279,7 @@ public class Repository implements IRepositoryIdProvider, Serializable {
* @return this repository
*/
public Repository setWatchers(int watchers) {
- this.watchers = watchers;
+ this.subscribersCount = watchers;
return this;
}

Back to the top