IDEA-131201 github tasks: allow to specify, whether to load all issues or assigned... appcode/142.4719 appcode/142.4887 phpstorm/142.4543 rubymine/142.4542
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Thu, 3 Sep 2015 11:08:29 +0000 (14:08 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Thu, 3 Sep 2015 13:20:19 +0000 (16:20 +0300)
plugins/github/src/org/jetbrains/plugins/github/api/GithubApiUtil.java
plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepository.java
plugins/github/src/org/jetbrains/plugins/github/tasks/GithubRepositoryEditor.java
plugins/github/test/org/jetbrains/plugins/github/GithubIssuesTest.java

index dd51519db9f5ea5fbb1ea4eaaf2a41a5d4f856b0..ccf4f9b3548def03fd4229e12c06bade63cd9b3a 100644 (file)
@@ -493,11 +493,13 @@ public class GithubApiUtil {
   public static List<GithubIssue> getIssuesQueried(@NotNull GithubConnection connection,
                                                    @NotNull String user,
                                                    @NotNull String repo,
+                                                   @Nullable String assignedUser,
                                                    @Nullable String query,
                                                    boolean withClosed) throws IOException {
     try {
       String state = withClosed ? "" : " state:open";
-      query = URLEncoder.encode("repo:" + user + "/" + repo + " " + query + state, CharsetToolkit.UTF8);
+      String assignee = StringUtil.isEmptyOrSpaces(assignedUser) ? "" : " assignee:" + assignedUser;
+      query = URLEncoder.encode("repo:" + user + "/" + repo + state + assignee + " " + query, CharsetToolkit.UTF8);
       String path = "/search/issues?q=" + query;
 
       //TODO: Use bodyHtml for issues - GitHub does not support this feature for SearchApi yet
index 518e918880db1821d966351381d7a86f0f04f11f..7df93faacfc88f650f6bb8660830e56420cc4d0e 100644 (file)
@@ -41,6 +41,7 @@ public class GithubRepository extends BaseRepositoryImpl {
   @NotNull private String myRepoName = "";
   @NotNull private String myUser = "";
   @NotNull private String myToken = "";
+  private boolean myAssignedIssuesOnly = false;
 
   @SuppressWarnings({"UnusedDeclaration"})
   public GithubRepository() {
@@ -51,6 +52,7 @@ public class GithubRepository extends BaseRepositoryImpl {
     setRepoName(other.myRepoName);
     setRepoAuthor(other.myRepoAuthor);
     setToken(other.myToken);
+    setAssignedIssuesOnly(other.myAssignedIssuesOnly);
   }
 
   public GithubRepository(GithubRepositoryType type) {
@@ -67,7 +69,7 @@ public class GithubRepository extends BaseRepositoryImpl {
       @Override
       protected void doTest() throws Exception {
         try {
-          GithubApiUtil.getIssuesQueried(myConnection, getRepoAuthor(), getRepoName(), "", false);
+          GithubApiUtil.getIssuesQueried(myConnection, getRepoAuthor(), getRepoName(), null, null, false);
         }
         catch (GithubOperationCanceledException ignore) {
         }
@@ -126,15 +128,23 @@ public class GithubRepository extends BaseRepositoryImpl {
     GithubConnection connection = getConnection();
 
     try {
-      List<GithubIssue> issues;
-      if (StringUtil.isEmptyOrSpaces(query)) {
+      String assigned = null;
+      if (myAssignedIssuesOnly) {
         if (StringUtil.isEmptyOrSpaces(myUser)) {
           myUser = GithubApiUtil.getCurrentUser(connection).getLogin();
         }
-        issues = GithubApiUtil.getIssuesAssigned(connection, getRepoAuthor(), getRepoName(), myUser, max, withClosed);
+        assigned = myUser;
+      }
+
+      List<GithubIssue> issues;
+      if (StringUtil.isEmptyOrSpaces(query)) {
+        // search queries have way smaller request number limit
+        issues =
+          GithubApiUtil.getIssuesAssigned(connection, getRepoAuthor(), getRepoName(), assigned, max, withClosed);
       }
       else {
-        issues = GithubApiUtil.getIssuesQueried(connection, getRepoAuthor(), getRepoName(), query, withClosed);
+        issues =
+          GithubApiUtil.getIssuesQueried(connection, getRepoAuthor(), getRepoName(), assigned, query, withClosed);
       }
 
       return ContainerUtil.map2Array(issues, Task.class, new Function<GithubIssue, Task>() {
@@ -346,6 +356,14 @@ public class GithubRepository extends BaseRepositoryImpl {
     setUser("");
   }
 
+  public boolean isAssignedIssuesOnly() {
+    return myAssignedIssuesOnly;
+  }
+
+  public void setAssignedIssuesOnly(boolean value) {
+    myAssignedIssuesOnly = value;
+  }
+
   @Tag("token")
   public String getEncodedToken() {
     return PasswordUtil.encodePassword(getToken());
@@ -377,10 +395,17 @@ public class GithubRepository extends BaseRepositoryImpl {
     if (!Comparing.equal(getRepoAuthor(), that.getRepoAuthor())) return false;
     if (!Comparing.equal(getRepoName(), that.getRepoName())) return false;
     if (!Comparing.equal(getToken(), that.getToken())) return false;
+    if (!Comparing.equal(isAssignedIssuesOnly(), that.isAssignedIssuesOnly())) return false;
 
     return true;
   }
 
+  @Override
+  public int hashCode() {
+    return StringUtil.stringHashCode(getRepoName()) +
+           31 * StringUtil.stringHashCode(getRepoAuthor());
+  }
+
   @Override
   protected int getFeatures() {
     return super.getFeatures() | STATE_UPDATING;
index d826763e1667277241fd67869b5f3aa49f8c61ba..e3b9c6c7d40e1242406d9589b649659174643ea6 100644 (file)
@@ -5,6 +5,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.tasks.config.BaseRepositoryEditor;
 import com.intellij.ui.DocumentAdapter;
+import com.intellij.ui.components.JBCheckBox;
 import com.intellij.ui.components.JBLabel;
 import com.intellij.ui.components.JBTextField;
 import com.intellij.util.Consumer;
@@ -34,6 +35,7 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
   private MyTextField myRepoAuthor;
   private MyTextField myRepoName;
   private MyTextField myToken;
+  private JBCheckBox myAssignedIssuesOnly;
   private JButton myTokenButton;
   private JBLabel myHostLabel;
   private JBLabel myRepositoryLabel;
@@ -51,6 +53,8 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
     myRepoAuthor.setText(repository.getRepoAuthor());
     myRepoName.setText(repository.getRepoName());
     myToken.setText(repository.getToken());
+    myToken.setText(repository.getToken());
+    myAssignedIssuesOnly.setSelected(repository.isAssignedIssuesOnly());
 
     DocumentListener buttonUpdater = new DocumentAdapter() {
       @Override
@@ -100,12 +104,20 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
     myTokenPanel.add(myToken, BorderLayout.CENTER);
     myTokenPanel.add(myTokenButton, BorderLayout.EAST);
 
+    myAssignedIssuesOnly = new JBCheckBox("Assigned Issues Only");
+
     installListener(myRepoAuthor);
     installListener(myRepoName);
     installListener(myToken);
-
-    return FormBuilder.createFormBuilder().setAlignLabelOnRight(true).addLabeledComponent(myHostLabel, myHostPanel)
-      .addLabeledComponent(myRepositoryLabel, myRepoPanel).addLabeledComponent(myTokenLabel, myTokenPanel).getPanel();
+    installListener(myAssignedIssuesOnly);
+
+    return FormBuilder.createFormBuilder()
+      .setAlignLabelOnRight(true)
+      .addLabeledComponent(myHostLabel, myHostPanel)
+      .addLabeledComponent(myRepositoryLabel, myRepoPanel)
+      .addLabeledComponent(myTokenLabel, myTokenPanel)
+      .addComponent(myAssignedIssuesOnly)
+      .getPanel();
   }
 
   @Override
@@ -113,6 +125,7 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
     myRepository.setRepoName(getRepoName());
     myRepository.setRepoAuthor(getRepoAuthor());
     myRepository.setToken(getToken());
+    myRepository.setAssignedIssuesOnly(isAssignedIssuesOnly());
     super.apply();
   }
 
@@ -149,6 +162,7 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
     myHostLabel.setAnchor(anchor);
     myRepositoryLabel.setAnchor(anchor);
     myTokenLabel.setAnchor(anchor);
+    myAssignedIssuesOnly.setAnchor(anchor);
   }
 
   private void updateTokenButton() {
@@ -182,6 +196,10 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
     return myToken.getText().trim();
   }
 
+  private boolean isAssignedIssuesOnly() {
+    return myAssignedIssuesOnly.isSelected();
+  }
+
   public static class MyTextField extends JBTextField {
     private int myWidth = -1;
 
index 1cd499f53c89c02a343c4214cbef48996396bdff..e89749dcdf1547b4e80361482b672f4d879b60ea 100644 (file)
@@ -117,7 +117,7 @@ public class GithubIssuesTest extends GithubTest {
   }
 
   public void testQueriedIssues1() throws Exception {
-    List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, "abracadabra", true);
+    List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, null, "abracadabra", true);
     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
       @Override
       public Long fun(GithubIssue githubIssue) {
@@ -131,7 +131,7 @@ public class GithubIssuesTest extends GithubTest {
   }
 
   public void testQueriedIssues2() throws Exception {
-    List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, "commentary", true);
+    List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, null, "commentary", true);
     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
       @Override
       public Long fun(GithubIssue githubIssue) {
@@ -145,7 +145,7 @@ public class GithubIssuesTest extends GithubTest {
   }
 
   public void testQueriedIssues3() throws Exception {
-    List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, "abracadabra", false);
+    List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, null, "abracadabra", false);
     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
       @Override
       public Long fun(GithubIssue githubIssue) {