summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit/transport
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-03-23 11:36:14 -0400
committerJames Moger <james.moger@gitblit.com>2014-04-10 18:58:10 -0400
commitf81ed74578eb1d0fed26c56ddcfbb39f08a4e47c (patch)
treeff704feeb645749bd4d18040efa08b9fa88428ab /src/main/java/com/gitblit/transport
parentd500429a1d7a47da3bcd22880b53dce806ba9300 (diff)
downloadgitblit-f81ed74578eb1d0fed26c56ddcfbb39f08a4e47c.tar.gz
gitblit-f81ed74578eb1d0fed26c56ddcfbb39f08a4e47c.zip
Support querying in tickets ls and accept Object[][] for table data
Diffstat (limited to 'src/main/java/com/gitblit/transport')
-rw-r--r--src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java4
-rw-r--r--src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java8
-rw-r--r--src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java10
-rw-r--r--src/main/java/com/gitblit/transport/ssh/gitblit/TicketsDispatcher.java55
-rw-r--r--src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java34
5 files changed, 66 insertions, 45 deletions
diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java
index 3422f506..8c4aa228 100644
--- a/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/gitblit/KeysDispatcher.java
@@ -163,12 +163,12 @@ public class KeysDispatcher extends DispatchCommand {
protected void asTable(List<SshKey> keys) {
String[] headers = { "#", "Fingerprint", "Comment", "Type" };
int len = keys == null ? 0 : keys.size();
- String[][] data = new String[len][];
+ Object[][] data = new Object[len][];
for (int i = 0; i < len; i++) {
// show 1-based index numbers with the fingerprint
// this is useful for comparing with "ssh-add -l"
SshKey k = keys.get(i);
- data[i] = new String[] { "" + (i + 1), k.getFingerprint(), k.getComment(), k.getAlgorithm() };
+ data[i] = new Object[] { (i + 1), k.getFingerprint(), k.getComment(), k.getAlgorithm() };
}
stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
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 500d6ae0..1984ebcc 100644
--- a/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/gitblit/ProjectsDispatcher.java
@@ -46,7 +46,7 @@ public class ProjectsDispatcher extends DispatchCommand {
List<ProjectModel> projects = gitblit.getProjectModels(user, false);
return projects;
}
-
+
@Override
protected boolean matches(ProjectModel p) {
return p.name.matches(regexFilter);
@@ -63,14 +63,14 @@ public class ProjectsDispatcher extends DispatchCommand {
headers = h;
}
- String[][] data = new String[list.size()][];
+ Object[][] data = new Object[list.size()][];
for (int i = 0; i < list.size(); i++) {
ProjectModel p = list.get(i);
if (verbose) {
- data[i] = new String[] { p.name, p.description, formatDate(p.lastChange), "" + p.repositories.size() };
+ data[i] = new Object[] { p.name, p.description, formatDate(p.lastChange), p.repositories.size() };
} else {
- data[i] = new String[] { p.name, formatDate(p.lastChange), "" + p.repositories.size() };
+ data[i] = new Object[] { p.name, formatDate(p.lastChange), p.repositories.size() };
}
}
stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
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 4e42eef5..4798c6d7 100644
--- a/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/gitblit/RepositoriesDispatcher.java
@@ -47,12 +47,12 @@ public class RepositoriesDispatcher extends DispatchCommand {
List<RepositoryModel> repositories = gitblit.getRepositoryModels(user);
return repositories;
}
-
+
@Override
protected boolean matches(RepositoryModel r) {
return r.name.matches(regexFilter);
}
-
+
@Override
protected void asTable(List<RepositoryModel> list) {
String[] headers;
@@ -64,7 +64,7 @@ public class RepositoriesDispatcher extends DispatchCommand {
headers = h;
}
- String[][] data = new String[list.size()][];
+ Object[][] data = new Object[list.size()][];
for (int i = 0; i < list.size(); i++) {
RepositoryModel r = list.get(i);
@@ -79,9 +79,9 @@ public class RepositoriesDispatcher extends DispatchCommand {
if (!ArrayUtils.isEmpty(r.owners)) {
owners = Joiner.on(",").join(r.owners);
}
- data[i] = new String[] { r.name, r.description, owners, lm, size };
+ data[i] = new Object[] { r.name, r.description, owners, lm, size };
} else {
- data[i] = new String[] { r.name, lm, size };
+ data[i] = new Object[] { r.name, lm, size };
}
}
stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
diff --git a/src/main/java/com/gitblit/transport/ssh/gitblit/TicketsDispatcher.java b/src/main/java/com/gitblit/transport/ssh/gitblit/TicketsDispatcher.java
index 484121b7..dd29b6ac 100644
--- a/src/main/java/com/gitblit/transport/ssh/gitblit/TicketsDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/gitblit/TicketsDispatcher.java
@@ -30,6 +30,7 @@ import com.gitblit.tickets.TicketIndexer.Lucene;
import com.gitblit.transport.ssh.commands.CommandMetaData;
import com.gitblit.transport.ssh.commands.DispatchCommand;
import com.gitblit.transport.ssh.commands.ListCommand;
+import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.FlipTable;
import com.gitblit.utils.FlipTable.Borders;
import com.gitblit.utils.StringUtils;
@@ -42,35 +43,53 @@ public class TicketsDispatcher extends DispatchCommand {
register(user, ReviewCommand.class);
register(user, ListTickets.class);
}
-
+
/* List tickets */
- @CommandMetaData(name = "list", aliases= { "ls" }, description = "List tickets")
+ @CommandMetaData(name = "list", aliases = { "ls" }, description = "List tickets")
public static class ListTickets extends ListCommand<QueryResult> {
- @Argument(index = 0, metaVar = "REPOSITORY", usage = "repository")
+ private final String ALL = "ALL";
+
+ @Argument(index = 0, metaVar = "ALL|REPOSITORY", usage = "the repository or ALL")
protected String repository;
-
+
+ @Argument(index = 1, multiValued = true, metaVar="CONDITION", usage = "query condition")
+ protected List<String> query;
+
+ protected String userQuery;
+
@Override
protected List<QueryResult> getItems() throws UnloggedFailure {
IGitblit gitblit = getContext().getGitblit();
ITicketService tickets = gitblit.getTicketService();
QueryBuilder sb = new QueryBuilder();
- sb.and(Lucene.status.matches(Status.New.toString())).or(Lucene.status.matches(Status.Open.toString()));
+ if (ArrayUtils.isEmpty(query)) {
+ sb.and(Lucene.status.matches(Status.New.toString())).or(Lucene.status.matches(Status.Open.toString()));
+ } else {
+ StringBuilder b = new StringBuilder();
+ for (String q : query) {
+ b.append(q).append(' ');
+ }
+ b.setLength(b.length() - 1);
+ sb.and(b.toString());
+ }
QueryBuilder qb;
- if (StringUtils.isEmpty(repository)) {
+ if (StringUtils.isEmpty(repository) || ALL.equalsIgnoreCase(repository)) {
qb = sb;
+ userQuery = sb.build();
} else {
qb = new QueryBuilder();
RepositoryModel r = gitblit.getRepositoryModel(repository);
if (r == null) {
- throw new UnloggedFailure(1, String.format("%s not found!", repository));
+ throw new UnloggedFailure(1, String.format("%s is not a repository!", repository));
}
qb.and(Lucene.rid.matches(r.getRID()));
qb.and(sb.toSubquery().toString());
+ userQuery = sb.build();
}
-
+
String query = qb.build();
List<QueryResult> list = tickets.queryFor(query, 0, 0, null, true);
return list;
@@ -78,14 +97,14 @@ public class TicketsDispatcher extends DispatchCommand {
@Override
protected void asTable(List<QueryResult> list) {
- boolean forRepo = !StringUtils.isEmpty(repository);
+ boolean forRepo = !StringUtils.isEmpty(repository) && !ALL.equalsIgnoreCase(repository);
String[] headers;
if (verbose) {
if (forRepo) {
- String[] h = { "ID", "Title", "Status", "Last Modified" };
+ String[] h = { "ID", "Title", "Status", "Last Modified", "Votes", "Commits" };
headers = h;
} else {
- String[] h = { "Repository", "ID", "Title", "Status", "Last Modified" };
+ String[] h = { "Repository", "ID", "Title", "Status", "Last Modified", "Votes", "Commits" };
headers = h;
}
} else {
@@ -98,25 +117,27 @@ public class TicketsDispatcher extends DispatchCommand {
}
}
- String[][] data = new String[list.size()][];
+ Object[][] data = new Object[list.size()][];
for (int i = 0; i < list.size(); i++) {
QueryResult q = list.get(i);
if (verbose) {
if (forRepo) {
- data[i] = new String[] { "" + q.number, q.title, q.status.toString(), formatDate(q.getDate()) };
+ data[i] = new Object[] { q.number, q.title, q.status, formatDate(q.getDate()), q.votesCount, q.patchset == null ? "": q.patchset.commits };
} else {
- data[i] = new String[] { q.repository, "" + q.number, q.title, q.status.toString(), formatDate(q.getDate()) };
+ data[i] = new Object[] { q.repository, q.number, q.title, q.status, formatDate(q.getDate()), q.votesCount, q.patchset == null ? "": q.patchset.commits };
}
} else {
if (forRepo) {
- data[i] = new String[] { "" + q.number, q.title, q.status.toString(), formatDate(q.getDate()) };
+ data[i] = new Object[] { q.number, q.title, q.status, formatDate(q.getDate()) };
} else {
- data[i] = new String[] { q.repository, "" + q.number, q.title, q.status.toString(), formatDate(q.getDate()) };
+ data[i] = new Object[] { q.repository, q.number, q.title, q.status, formatDate(q.getDate()) };
}
}
}
- stdout.println(FlipTable.of(headers, data, Borders.BODY_HCOLS));
+ stdout.print(FlipTable.of(headers, data, Borders.BODY_HCOLS));
+ stdout.println(" " + repository + ": " + userQuery);
+ stdout.println();
}
@Override
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 14af7e75..c4fac3ea 100644
--- a/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java
+++ b/src/main/java/com/gitblit/transport/ssh/gitblit/UsersDispatcher.java
@@ -54,34 +54,34 @@ public class UsersDispatcher extends DispatchCommand {
// fields
String [] fheaders = new String [] { "Field", "Value" };
- String [][] fdata = new String[5][];
- fdata[0] = new String [] { "Email", u.emailAddress };
- fdata[1] = new String [] { "Type", u.accountType.toString() };
- fdata[2] = new String [] { "Can Admin", u.canAdmin() ? "Y":"N" };
- fdata[3] = new String [] { "Can Fork", u.canFork() ? "Y":"N" };
- fdata[4] = new String [] { "Can Create", u.canCreate() ? "Y":"N" };
+ Object [][] fdata = new Object[5][];
+ fdata[0] = new Object [] { "Email", u.emailAddress };
+ fdata[1] = new Object [] { "Type", u.accountType };
+ fdata[2] = new Object [] { "Can Admin", u.canAdmin() ? "Y":"N" };
+ fdata[3] = new Object [] { "Can Fork", u.canFork() ? "Y":"N" };
+ fdata[4] = new Object [] { "Can Create", u.canCreate() ? "Y":"N" };
String fields = FlipTable.of(fheaders, fdata, Borders.COLS);
-
+
// teams
String [] theaders = new String [] { "Team", "Type" };
- String [][] tdata = new String[u.teams.size()][];
+ Object [][] tdata = new Object[u.teams.size()][];
int i = 0;
for (TeamModel t : u.teams) {
- tdata[i] = new String [] { t.name, t.accountType.toString() };
+ tdata[i] = new Object [] { t.name, t.accountType };
i++;
}
String teams = FlipTable.of(theaders, tdata, Borders.COLS);
-
+
// permissions
List<RegistrantAccessPermission> perms = u.getRepositoryPermissions();
String[] pheaders = { "Repository", "Permission", "Type", "Source", "Mutable" };
- String [][] pdata = new String[perms.size()][];
+ Object [][] pdata = new Object[perms.size()][];
for (i = 0; i < perms.size(); i++) {
RegistrantAccessPermission ap = perms.get(i);
- pdata[i] = new String[] { ap.registrant, ap.permission.toString(), ap.permissionType.toString(), ap.source, ap.mutable ? "Y":"N" };
+ pdata[i] = new Object[] { ap.registrant, ap.permission, ap.permissionType, ap.source, ap.mutable ? "Y":"N" };
}
String permissions = FlipTable.of(pheaders, pdata, Borders.COLS);
-
+
// assemble user table
String [] headers = new String[] { u.getDisplayName() + (u.username.equals(u.getDisplayName()) ? "" : (" (" + u.username + ")")) };
String[][] data = new String[6][];
@@ -104,7 +104,7 @@ public class UsersDispatcher extends DispatchCommand {
List<UserModel> users = gitblit.getAllUsers();
return users;
}
-
+
@Override
protected boolean matches(UserModel u) {
return u.username.matches(regexFilter);
@@ -121,16 +121,16 @@ public class UsersDispatcher extends DispatchCommand {
headers = h;
}
- String[][] data = new String[list.size()][];
+ Object[][] data = new Object[list.size()][];
for (int i = 0; i < list.size(); i++) {
UserModel u = list.get(i);
String name = u.disabled ? "-" : ((u.canAdmin() ? "*" : " ")) + u.username;
if (verbose) {
- data[i] = new String[] { name, u.displayName, u.accountType.name(),
+ data[i] = new Object[] { name, u.displayName, u.accountType,
u.emailAddress, u.canCreate() ? "Y":"", u.canFork() ? "Y" : ""};
} else {
- data[i] = new String[] { name, u.displayName, u.accountType.name(),
+ data[i] = new Object[] { name, u.displayName, u.accountType,
u.emailAddress };
}
}