Merge branch 'stable-3.3' into stable-3.4 * stable-3.3: Update git submodules Set version to 3.3.7-SNAPSHOT Set version to 3.3.6 Support author:self and committer:self queries Change-Id: I4ae265c3c1c246d9c1415b3d5fda44c185bf4dfa
diff --git a/Documentation/user-search.txt b/Documentation/user-search.txt index 377012a..7221f98 100644 --- a/Documentation/user-search.txt +++ b/Documentation/user-search.txt
@@ -578,14 +578,17 @@ author:'AUTHOR':: + Changes where 'AUTHOR' is the author of the current patch set. 'AUTHOR' may be -the author's exact email address, or part of the name or email address. +the author's exact email address, or part of the name or email address. The +special case of `author:self` will find changes authored by the caller. [[committer]] committer:'COMMITTER':: + Changes where 'COMMITTER' is the committer of the current patch set. 'COMMITTER' may be the committer's exact email address, or part of the name or -email address. +email address. The special case of `committer:self` will find changes committed +by the caller. + [[submittable]] submittable:'SUBMIT_STATUS'::
diff --git a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java index 4e3edcd..b02b52d 100644 --- a/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java +++ b/java/com/google/gerrit/server/query/change/ChangeQueryBuilder.java
@@ -1513,6 +1513,12 @@ private Predicate<ChangeData> getAuthorOrCommitterFullTextPredicate( String who, Function<String, Predicate<ChangeData>> fullPredicateFunc) throws QueryParseException { + if (isSelf(who)) { + IdentifiedUser me = args.getIdentifiedUser(); + List<Predicate<ChangeData>> predicates = + me.getEmailAddresses().stream().map(fullPredicateFunc).collect(toList()); + return Predicate.or(predicates); + } Set<String> parts = SchemaUtil.getNameParts(who); if (parts.isEmpty()) { throw error("invalid value");
diff --git a/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java b/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java index b97d9f2..6c83d25 100644 --- a/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java +++ b/javatests/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java
@@ -620,9 +620,14 @@ PersonIdent johnDoe = new PersonIdent("John Doe", "john.doe@example.com"); PersonIdent john = new PersonIdent("John", "john@example.com"); PersonIdent doeSmith = new PersonIdent("Doe Smith", "doe_smith@example.com"); + Account ua = user.asIdentifiedUser().getAccount(); + PersonIdent myself = new PersonIdent("I Am", ua.preferredEmail()); + PersonIdent selfName = new PersonIdent("My Self", "my.self@example.com"); + Change change1 = createChange(repo, johnDoe); Change change2 = createChange(repo, john); Change change3 = createChange(repo, doeSmith); + Change change4 = createChange(repo, selfName); // Only email address. assertQuery(searchOperator + "john.doe@example.com", change1); @@ -638,6 +643,18 @@ assertQuery(searchOperator + "\"John <john.doe@example.com>\""); assertQuery(searchOperator + "\"Doe John <john@example.com>\""); assertQuery(searchOperator + "\"Doe John <doe_smith@example.com>\""); + + // Partial name + assertQuery(searchOperator + "ohn"); + assertQuery(searchOperator + "smith", change3); + + // The string 'self' in the name should not be matched + assertQuery(searchOperator + "self"); + + // ':self' matches a change created with the current user's email address + Change change5 = createChange(repo, myself); + assertQuery(searchOperator + "me", change5); + assertQuery(searchOperator + "self", change5); } private void byAuthorOrCommitterFullText(String searchOperator) throws Exception {