From 0d08afcd4a914c2468b4f9d16354586aeea6182b Mon Sep 17 00:00:00 2001 From: Patrick Hiesel Date: Tue, 31 Jul 2018 10:33:13 +0200 Subject: [PATCH] Support 'repository' as query parameter in change queries The UI has migrated to use the term 'repository' instead of 'project'. We are following through by supporting this as an additional query term in change search. This commit adapts the docs and adds tests for the new parameter. Change-Id: Ie167fd4081e2739f96cf6cff95cb4c70c7dcc431 --- Documentation/user-search.txt | 19 ++++++++++ .../query/change/ChangeQueryBuilder.java | 15 ++++++++ .../change/AbstractQueryChangesTest.java | 37 +++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/Documentation/user-search.txt b/Documentation/user-search.txt index bebe81be08..41cb380908 100644 --- a/Documentation/user-search.txt +++ b/Documentation/user-search.txt @@ -165,6 +165,25 @@ parentproject:'PROJECT':: Changes occurring in 'PROJECT' or in one of the child projects of 'PROJECT'. +[[repository]] +repository:'REPOSITORY':: ++ +Changes occurring in 'REPOSITORY'. If 'REPOSITORY' starts with `^` it +matches repository names by regular expression. The +link:http://www.brics.dk/automaton/[dk.brics.automaton +library] is used for evaluation of such patterns. + +[[repositories]] +repositories:'PREFIX':: ++ +Changes occurring in repositories starting with 'PREFIX'. + +[[parentrepository]] +parentrepository:'REPOSITORY':: ++ +Changes occurring in 'REPOSITORY' or in one of the child repositories of +'REPOSITORY'. + [[branch]] branch:'BRANCH':: + diff --git a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java index 5855404145..f8f892b624 100644 --- a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java +++ b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java @@ -657,6 +657,21 @@ public class ChangeQueryBuilder extends QueryBuilder { return new ParentProjectPredicate(args.projectCache, args.childProjects, name); } + @Operator + public Predicate repository(String name) { + return project(name); + } + + @Operator + public Predicate repositories(String name) { + return projects(name); + } + + @Operator + public Predicate parentrepository(String name) { + return parentproject(name); + } + @Operator public Predicate branch(String name) { if (name.startsWith("^")) { diff --git a/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java b/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java index 0ff16bbfd5..d4d4464268 100644 --- a/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java +++ b/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java @@ -798,6 +798,43 @@ public abstract class AbstractQueryChangesTest extends GerritServerTests { assertQuery("projects:repo", change2, change1); } + @Test + public void byRepository() throws Exception { + TestRepository repo1 = createProject("repo1"); + TestRepository repo2 = createProject("repo2"); + Change change1 = insert(repo1, newChange(repo1)); + Change change2 = insert(repo2, newChange(repo2)); + + assertQuery("repository:foo"); + assertQuery("repository:repo"); + assertQuery("repository:repo1", change1); + assertQuery("repository:repo2", change2); + } + + @Test + public void byParentRepository() throws Exception { + TestRepository repo1 = createProject("repo1"); + TestRepository repo2 = createProject("repo2", "repo1"); + Change change1 = insert(repo1, newChange(repo1)); + Change change2 = insert(repo2, newChange(repo2)); + + assertQuery("parentrepository:repo1", change2, change1); + assertQuery("parentrepository:repo2", change2); + } + + @Test + public void byRepositoryPrefix() throws Exception { + TestRepository repo1 = createProject("repo1"); + TestRepository repo2 = createProject("repo2"); + Change change1 = insert(repo1, newChange(repo1)); + Change change2 = insert(repo2, newChange(repo2)); + + assertQuery("repositories:foo"); + assertQuery("repositories:repo1", change1); + assertQuery("repositories:repo2", change2); + assertQuery("repositories:repo", change2, change1); + } + @Test public void byBranchAndRef() throws Exception { TestRepository repo = createProject("repo");