Github: codereview
authorAleksey Pivovarov <Aleksey.Pivovarov@jetbrains.com>
Wed, 5 Feb 2014 18:22:25 +0000 (22:22 +0400)
committerAleksey Pivovarov <Aleksey.Pivovarov@jetbrains.com>
Thu, 27 Feb 2014 11:18:16 +0000 (15:18 +0400)
plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java
plugins/github/src/org/jetbrains/plugins/github/ui/GithubTwoFactorDialog.java [deleted file]
plugins/github/src/org/jetbrains/plugins/github/ui/GithubTwoFactorPanel.form [deleted file]
plugins/github/src/org/jetbrains/plugins/github/ui/GithubTwoFactorPanel.java [deleted file]
plugins/github/src/org/jetbrains/plugins/github/util/GithubUtil.java
plugins/github/test/org/jetbrains/plugins/github/GithubCreateGistTest.java
plugins/github/test/org/jetbrains/plugins/github/GithubCreateGistTestBase.java

index b29770961932ada2bea6894b547e83312a4139bd..a9f65a26a60d94f08b9d0570dd6ebe5ff8c5d799 100644 (file)
@@ -39,6 +39,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.lang.reflect.Array;
 import java.net.URLEncoder;
 import java.util.*;
 import java.util.List;
@@ -460,10 +461,9 @@ public class GithubApiUtil {
 
   @NotNull
   public static String getMasterToken(@NotNull GithubAuthData auth, @Nullable String note) throws IOException {
-    List<String> scopes = new ArrayList<String>();
-
-    scopes.add("repo"); // read/write access to public/private repositories
-    scopes.add("gist"); // create/delete gists
+    // "repo" - read/write access to public/private repositories
+    // "gist" - create/delete gists
+    List<String> scopes = Arrays.asList("repo", "gist");
 
     return getScopedToken(auth, scopes, note);
   }
diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubTwoFactorDialog.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubTwoFactorDialog.java
deleted file mode 100644 (file)
index c3bbd02..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2000-2013 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.github.ui;
-
-import com.intellij.openapi.diagnostic.Logger;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogWrapper;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.plugins.github.util.GithubSettings;
-import org.jetbrains.plugins.github.util.GithubUtil;
-
-import javax.swing.*;
-
-/**
- * @author oleg
- * @date 10/20/10
- */
-public class GithubTwoFactorDialog extends DialogWrapper {
-
-  protected static final Logger LOG = GithubUtil.LOG;
-
-  protected final GithubTwoFactorPanel myGithubTwoFactorPanel;
-  protected final GithubSettings mySettings;
-
-  public GithubTwoFactorDialog(@NotNull final Project project) {
-    super(project, false);
-
-    myGithubTwoFactorPanel = new GithubTwoFactorPanel();
-
-    mySettings = GithubSettings.getInstance();
-
-    setTitle("Github Two-Factor Authentication");
-    setOKButtonText("Verify");
-    init();
-  }
-
-  @NotNull
-  protected Action[] createActions() {
-    return new Action[]{getOKAction(), getCancelAction(), getHelpAction()};
-  }
-
-  @Override
-  protected JComponent createCenterPanel() {
-    return myGithubTwoFactorPanel.getPanel();
-  }
-
-  @Override
-  protected String getHelpId() {
-    return "github.two.factor.dialog";
-  }
-
-  @Override
-  protected String getDimensionServiceKey() {
-    return "Github.TwoFactorDialog";
-  }
-
-  @Override
-  public JComponent getPreferredFocusedComponent() {
-    return myGithubTwoFactorPanel.getPreferableFocusComponent();
-  }
-
-  @Override
-  protected void doOKAction() {
-    super.doOKAction();
-  }
-
-  @NotNull
-  public String getCode() {
-    return myGithubTwoFactorPanel.getCode();
-  }
-}
\ No newline at end of file
diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubTwoFactorPanel.form b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubTwoFactorPanel.form
deleted file mode 100644 (file)
index 49398cd..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="org.jetbrains.plugins.github.ui.GithubTwoFactorPanel">
-  <grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
-    <margin top="0" left="0" bottom="0" right="0"/>
-    <constraints>
-      <xy x="20" y="20" width="500" height="174"/>
-    </constraints>
-    <properties>
-      <focusable value="false"/>
-    </properties>
-    <border type="none"/>
-    <children>
-      <vspacer id="9b306">
-        <constraints>
-          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
-        </constraints>
-      </vspacer>
-      <component id="dbea1" class="javax.swing.JLabel">
-        <constraints>
-          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <text value="Authentication Code:"/>
-        </properties>
-      </component>
-      <component id="f5630" class="javax.swing.JTextField" binding="myCodeTextField">
-        <constraints>
-          <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
-            <preferred-size width="150" height="-1"/>
-          </grid>
-        </constraints>
-        <properties/>
-      </component>
-    </children>
-  </grid>
-</form>
diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubTwoFactorPanel.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubTwoFactorPanel.java
deleted file mode 100644 (file)
index 1fc9422..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2000-2013 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jetbrains.plugins.github.ui;
-
-import org.jetbrains.annotations.NotNull;
-
-import javax.swing.*;
-
-/**
- * @author oleg
- * @date 10/20/10
- */
-public class GithubTwoFactorPanel {
-  private JPanel myPane;
-  private JTextField myCodeTextField;
-
-  public GithubTwoFactorPanel() {
-  }
-
-  public JComponent getPanel() {
-    return myPane;
-  }
-
-  @NotNull
-  public String getCode() {
-    return myCodeTextField.getText().trim();
-  }
-
-  public JComponent getPreferableFocusComponent() {
-    return myCodeTextField;
-  }
-}
-
index ef02186bf728a2cd2be2b2620103e20413372012..0048061018e79b596aaecd9a81e797d59222c008 100644 (file)
@@ -22,6 +22,7 @@ import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.progress.Task;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.ThrowableComputable;
 import com.intellij.openapi.util.text.StringUtil;
@@ -50,7 +51,6 @@ import org.jetbrains.plugins.github.exceptions.GithubOperationCanceledException;
 import org.jetbrains.plugins.github.exceptions.GithubTwoFactorAuthenticationException;
 import org.jetbrains.plugins.github.ui.GithubBasicLoginDialog;
 import org.jetbrains.plugins.github.ui.GithubLoginDialog;
-import org.jetbrains.plugins.github.ui.GithubTwoFactorDialog;
 
 import java.io.IOException;
 import java.net.UnknownHostException;
@@ -213,18 +213,18 @@ public class GithubUtil {
 
         GithubApiUtil.askForTwoFactorCodeSMS(oldAuth);
 
-        final GithubTwoFactorDialog dialog = new GithubTwoFactorDialog(project);
+        final AtomicReference<String> codeRef = new AtomicReference<String>();
         ApplicationManager.getApplication().invokeAndWait(new Runnable() {
           @Override
           public void run() {
-            DialogManager.show(dialog);
+            codeRef.set(Messages.showInputDialog(project, "Authentication Code", "Github Two-Factor Authentication", null));
           }
         }, indicator.getModalityState());
-        if (!dialog.isOK()) {
+        if (codeRef.get() == null) {
           throw new GithubOperationCanceledException("Can't get two factor authentication code");
         }
 
-        return oldAuth.copyWithTwoFactorCode(dialog.getCode());
+        return oldAuth.copyWithTwoFactorCode(codeRef.get());
       }
     });
   }
index d7483b7c9a5e4e22703f1c975c7dc780c849fc8a..f7ae343204f2b46217b594c040a5e30c6fddf25a 100644 (file)
@@ -121,7 +121,7 @@ public class GithubCreateGistTest extends GithubCreateGistTestBase {
   }
 
   public void testWrongLogin() throws Throwable {
-    registerDefaultLoginDialogHandler();
+    registerCancelingLoginDialogHandler();
 
     List<FileContent> expected = createContent();
 
@@ -135,7 +135,7 @@ public class GithubCreateGistTest extends GithubCreateGistTestBase {
   }
 
   public void testWrongPassword() throws Throwable {
-    registerDefaultLoginDialogHandler();
+    registerCancelingLoginDialogHandler();
 
     List<FileContent> expected = createContent();
 
index 196d880f3386a2745eccf2acf38d0c026cdb7d19..17a0c68781e4b614a54aadb8778f1186614f4bd6 100644 (file)
@@ -139,7 +139,7 @@ public abstract class GithubCreateGistTestBase extends GithubTest {
     assertTrue("Gist content differs from sample", Comparing.haveEqualElements(expected, actual));
   }
 
-  protected void registerDefaultLoginDialogHandler() {
+  protected void registerCancelingLoginDialogHandler() {
     myDialogManager.registerDialogHandler(GithubLoginDialog.class, new TestDialogHandler<GithubLoginDialog>() {
       @Override
       public int handleDialog(GithubLoginDialog dialog) {