diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubShareAction.java b/plugins/github/src/org/jetbrains/plugins/github/GithubShareAction.java index 62ec72b79b66..7bdf3199d38a 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubShareAction.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubShareAction.java @@ -160,7 +160,7 @@ public class GithubShareAction extends DumbAwareAction { // Show dialog (window) final GithubShareDialog shareDialog = - new GithubShareDialog(project, repoNamesRef.get(), userInfoRef.get().getPlan().isPrivateRepoAllowed()); + new GithubShareDialog(project, repoNamesRef.get(), userInfoRef.get().getMaxPrivateRepos() > userInfoRef.get().getPrivateRepos()); shareDialog.show(); if (!shareDialog.isOK()) { return; diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubUser.java b/plugins/github/src/org/jetbrains/plugins/github/GithubUser.java index ab46fcc39787..6695dfa0f95a 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubUser.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubUser.java @@ -24,47 +24,14 @@ import org.jetbrains.annotations.NotNull; */ class GithubUser { - enum Plan { - FREE, - MICRO, - SMALL, - MEDIUM, - BRONZE, - SILVER, - GOLD, - PLATINUM, - ENTERPRISE; - - public boolean isPrivateRepoAllowed() { - return this != FREE; - } - - public static Plan fromString(String name) { - for (Plan plan : values()) { - - if (plan.name().equalsIgnoreCase(name)) { - return plan; - } - } - return defaultPlan(); - } - - private static Plan defaultPlan() { - return FREE; - } - } - - @NotNull private final Plan myPlan; @NotNull private final String myLogin; + private int myPrivateRepos; + private int myMaxPrivateRepos; - GithubUser(@NotNull String login, @NotNull Plan plan) { + GithubUser(@NotNull String login, int privateRepos, int maxPrivateRepos) { myLogin = login; - myPlan = plan; - } - - @NotNull - Plan getPlan() { - return myPlan; + myPrivateRepos = privateRepos; + myMaxPrivateRepos = maxPrivateRepos; } @NotNull @@ -72,4 +39,12 @@ class GithubUser { return myLogin; } + int getMaxPrivateRepos() { + return myMaxPrivateRepos; + } + + int getPrivateRepos() { + return myPrivateRepos; + } + } diff --git a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java index df1a095457ce..0089b8c5b1c0 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java +++ b/plugins/github/src/org/jetbrains/plugins/github/GithubUtil.java @@ -167,20 +167,10 @@ public class GithubUtil { } JsonObject obj = (JsonObject)result; - if (!obj.has("plan")) { - return null; - } - GithubUser.Plan plan = parsePlan(obj.get("plan")); String login = obj.get("login").getAsString(); - return new GithubUser(login, plan); - } - - @NotNull - private static GithubUser.Plan parsePlan(JsonElement plan) { - if (!plan.isJsonObject()) { - return GithubUser.Plan.FREE; - } - return GithubUser.Plan.fromString(plan.getAsJsonObject().get("name").getAsString()); + int privateRepos = obj.get("owned_private_repos").getAsInt(); + int maxPrivateRepos = obj.get("plan").getAsJsonObject().get("private_repos").getAsInt(); + return new GithubUser(login, privateRepos, maxPrivateRepos); } @NotNull