From: James Moger Date: Sun, 23 Mar 2014 00:52:54 +0000 (-0400) Subject: Support regex filtering the projects, repositories, and users list X-Git-Tag: v1.5.0~68^2~40 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5cc48016caf4de3ecce6fbf2f2a34d3bde99edb6;p=gitblit.git Support regex filtering the projects, repositories, and users list --- diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java index 177102e4..212e7292 100644 --- a/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java +++ b/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java @@ -16,12 +16,16 @@ 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 projects = gitblit.getProjectModels(user, false); + List filtered; + if (StringUtils.isEmpty(regexFilter)) { + // no regex filter + filtered = projects; + } else { + // regex filter the list + filtered = new ArrayList(); + for (ProjectModel p : projects) { + if (p.name.matches(regexFilter)) { + filtered.add(p); + } + } + } if (tabbed) { - asTabbed(projects); + asTabbed(filtered); } else { - asTable(projects); + asTable(filtered); } } diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java index 329e95e2..ab974dc0 100644 --- a/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java +++ b/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java @@ -16,9 +16,12 @@ 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 repositories = gitblit.getRepositoryModels(user); + List filtered; + if (StringUtils.isEmpty(regexFilter)) { + // no regex filter + filtered = repositories; + } else { + // regex filter the list + filtered = new ArrayList(); + for (RepositoryModel r : repositories) { + if (r.name.matches(regexFilter)) { + filtered.add(r); + } + } + } + if (tabbed) { - asTabbed(repositories); + asTabbed(filtered); } else { - asTable(repositories); + asTable(filtered); } } diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java index 1682ab48..ebe0a0a2 100644 --- a/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java +++ b/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java @@ -15,13 +15,16 @@ */ 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 users = gitblit.getAllUsers(); + List filtered; + if (StringUtils.isEmpty(regexFilter)) { + // no regex filter + filtered = users; + } else { + // regex filter the list + filtered = new ArrayList(); + for (UserModel u : users) { + if (u.username.matches(regexFilter)) { + filtered.add(u); + } + } + } + if (tabbed) { - asTabbed(users); + asTabbed(filtered); } else { - asTable(users); + asTable(filtered); } }