mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
IDEA-109652 Github: set checkbox "private" unavailable basing on number of used private repositories
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user