]> source.dussan.org Git - gitblit.git/commitdiff
Support regex filtering the projects, repositories, and users list
authorJames Moger <james.moger@gitblit.com>
Sun, 23 Mar 2014 00:52:54 +0000 (20:52 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 10 Apr 2014 22:58:10 +0000 (18:58 -0400)
src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java
src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java
src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java

index 177102e45ca034d23da638f247edf00e5b978d8c..212e729285cdc56b6ca07b4d206a945ea96e3879 100644 (file)
 package com.gitblit.transport.ssh.gitblit;
 
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.List;
 
+import org.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.Option;
+import org.parboiled.common.StringUtils;
 
 import com.gitblit.manager.IGitblit;
 import com.gitblit.models.ProjectModel;
+import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.UserModel;
 import com.gitblit.transport.ssh.commands.CommandMetaData;
 import com.gitblit.transport.ssh.commands.DispatchCommand;
@@ -47,17 +51,33 @@ public class ProjectsDispatcher extends DispatchCommand {
                @Option(name = "--tabbed", aliases = { "-t" }, usage = "as tabbed output")
                private boolean tabbed;
 
+               @Argument(index = 0, metaVar = "REGEX", usage = "regex filter expression")
+               protected String regexFilter;
+
                @Override
                public void run() {
                        IGitblit gitblit = getContext().getGitblit();
                        UserModel user = getContext().getClient().getUser();
 
                        List<ProjectModel> projects = gitblit.getProjectModels(user, false);
+                       List<ProjectModel> filtered;
+                       if (StringUtils.isEmpty(regexFilter)) {
+                               // no regex filter 
+                               filtered = projects;
+                       } else {
+                               // regex filter the list
+                               filtered = new ArrayList<ProjectModel>();
+                               for (ProjectModel p : projects) {
+                                       if (p.name.matches(regexFilter)) {
+                                               filtered.add(p);
+                                       }
+                               }
+                       }
 
                        if (tabbed) {
-                               asTabbed(projects);
+                               asTabbed(filtered);
                        } else {
-                               asTable(projects);
+                               asTable(filtered);
                        }
                }
 
index 329e95e2a4bd009ba6f8cf0744018036799819bf..ab974dc076c03ba4172ebbb8cd551f5c7f627041 100644 (file)
 package com.gitblit.transport.ssh.gitblit;
 
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.List;
 
+import org.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.Option;
+import org.parboiled.common.StringUtils;
 
 import com.gitblit.manager.IGitblit;
 import com.gitblit.models.RepositoryModel;
@@ -49,16 +52,33 @@ public class RepositoriesDispatcher extends DispatchCommand {
                @Option(name = "--tabbed", aliases = { "-t" }, usage = "as tabbed output")
                private boolean tabbed;
 
+               @Argument(index = 0, metaVar = "REGEX", usage = "regex filter expression")
+               protected String regexFilter;
+
                @Override
                public void run() {
                        IGitblit gitblit = getContext().getGitblit();
                        UserModel user = getContext().getClient().getUser();
 
                        List<RepositoryModel> repositories = gitblit.getRepositoryModels(user);
+                       List<RepositoryModel> filtered;
+                       if (StringUtils.isEmpty(regexFilter)) {
+                               // no regex filter 
+                               filtered = repositories;
+                       } else {
+                               // regex filter the list
+                               filtered = new ArrayList<RepositoryModel>();
+                               for (RepositoryModel r : repositories) {
+                                       if (r.name.matches(regexFilter)) {
+                                               filtered.add(r);
+                                       }
+                               }
+                       }
+                       
                        if (tabbed) {
-                               asTabbed(repositories);
+                               asTabbed(filtered);
                        } else {
-                               asTable(repositories);
+                               asTable(filtered);
                        }
                }
 
index 1682ab48267499c6ed946af0eadd59c11252e738..ebe0a0a231796dc22597f8a4389bfb56128c1a02 100644 (file)
  */
 package com.gitblit.transport.ssh.gitblit;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.kohsuke.args4j.Argument;
 import org.kohsuke.args4j.Option;
+import org.parboiled.common.StringUtils;
 
 import com.gitblit.manager.IGitblit;
 import com.gitblit.models.RegistrantAccessPermission;
+import com.gitblit.models.RepositoryModel;
 import com.gitblit.models.TeamModel;
 import com.gitblit.models.UserModel;
 import com.gitblit.transport.ssh.commands.CommandMetaData;
@@ -108,15 +111,32 @@ public class UsersDispatcher extends DispatchCommand {
                @Option(name = "--tabbed", aliases = { "-t" }, usage = "as tabbed output")
                private boolean tabbed;
 
+               @Argument(index = 0, metaVar = "REGEX", usage = "regex filter expression")
+               protected String regexFilter;
+
                @Override
                public void run() {
                        IGitblit gitblit = getContext().getGitblit();
                        List<UserModel> users = gitblit.getAllUsers();
 
+                       List<UserModel> filtered;
+                       if (StringUtils.isEmpty(regexFilter)) {
+                               // no regex filter 
+                               filtered = users;
+                       } else {
+                               // regex filter the list
+                               filtered = new ArrayList<UserModel>();
+                               for (UserModel u : users) {
+                                       if (u.username.matches(regexFilter)) {
+                                               filtered.add(u);
+                                       }
+                               }
+                       }
+
                        if (tabbed) {
-                               asTabbed(users);
+                               asTabbed(filtered);
                        } else {
-                               asTable(users);
+                               asTable(filtered);
                        }
                }