3060 Commits

Author SHA1 Message Date
David Pursehouse
7f5d6edab2 Merge branch 'stable-2.16'
* stable-2.16:
  Move *Op classes from c.g.g.s.restapi.change to c.g.g.s.change

Change-Id: Iae38283f95d4d7696236f184411005fb0878cd65
2019-02-16 15:24:14 +09:00
Changcheng Xiao
3b817164e3 PatchSetInserter: allow to set "sendEmail" bit
With this new "sendEmail" bit, we will have more control
for whether emails are going to be sent out after a new
patch set is added. This is useful for avoiding duplicate
emails, e.g merge (already have an email to notify a change
is merged, no need to have another email to say a new patch
set is uploaded).

Change-Id: I43c5d7c6560316d5a6034dc8e711f7e87b7af932
2019-02-15 17:43:57 +01:00
David Pursehouse
9b728841fa Move *Op classes from c.g.g.s.restapi.change to c.g.g.s.change
The majority of these classes are already in the c.g.g.s.change package.

Change-Id: Ic62b9f05443e2cd5167bab28eed789ad9669618f
2019-02-15 09:47:07 +09:00
David Pursehouse
bd00083e48 Merge branch 'stable-2.16'
* stable-2.16:
  PrologEnvironment: Add logging of reduction limits

Change-Id: I196585f29742b8b26f29187a76f00e2d98ca9f85
2019-02-14 22:10:17 +09:00
David Pursehouse
ccf646765e Merge branch 'stable-2.15' into stable-2.16
* stable-2.15:
  PrologEnvironment: Add logging of reduction limits

Change-Id: Ic2b91320fadc837c91b578db27d7d46b15eb0f9d
2019-02-14 19:49:53 +09:00
David Pursehouse
4c58e1031f Change: Add helper methods to check change state
To check a change's state the caller currently has to call getState()
and then do a comparison on the enum value.

To make this easier, introduce new methods on Change:

- isNew
- isMerged
- isAbandoned
- isClosed

Note that we don't add "isOpen" since there are no longer multiple
states that could be considered "open". Previously there were "new"
and "draft", but the draft workflow was removed.

Update callers to use the new methods.

Change-Id: Ic047f74b114e2277e66c878dace73ea8e0babab6
2019-02-14 13:48:51 +09:00
Dave Borowitz
14f1295319 FieldDef: Mark Getter#get as nullable
Change-Id: I6bb474883e2657aaa8effcc5600681426a484dcf
2019-02-13 08:07:28 -08:00
David Pursehouse
401e0b7eb1 Merge "Introduce sequential success commit messages" 2019-02-13 01:46:12 +00:00
David Pursehouse
b50973cc5c BatchUpdate: Fix 'invalid member type qualification' Javadoc warning
Change-Id: I2a4581ea2d817a273777f87ca7c5e4b4eeed1e43
2019-02-12 15:21:10 +09:00
David Pursehouse
f71771f40c DeleteReviewerByEmailOp: Remove unused input member
The input is unused since change If6f8a44f3.

Change-Id: I221e65eeabaa959b048a0517dfe7a8f253e21ba6
2019-02-12 15:21:00 +09:00
David Pursehouse
19a2fc7e5c Merge changes from topic "notify-resolver"
* changes:
  NotifyResolver: Use SetMultimap for accounts to notify
  Pass notification settings through BatchUpdate's Context
  Consistently pass NotifyResolver.Result instead of separate args
  Refactor NotifyUtil analogously to AccountResolver
  PostReview: Fix default notification settings, kind of
  Rename FakeEmailSenderSubject#notSent to didNotSend
  ChangeNotificationsIT: Consistently check sender queue is empty
  ChangeNotificationsIT: Don't trigger review after setting ready
2019-02-11 23:36:24 +00:00
Edwin Kempin
255d6a1709 Merge branch stable-2.16
* stable-2.16:
  ListProjects: Fix log statements

Change-Id: I5db5390e305e7b73bf9593999b8eaf8aa779bfa7
2019-02-11 17:30:43 +01:00
Edwin Kempin
d647534fe9 ListProjects: Fix log statements
With Flogger we must use '%s' as placeholder for parameters.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I834c84516b86b7bdcf800ab06748da30babd9a4f
2019-02-11 16:31:07 +01:00
Dave Borowitz
9f46d2e248 Resolve "self" even if inactive
Different systems may implement reactivation of accounts in different
ways. On googlesource.com, for example, accounts are automatically
reactivated on login through the web UI, but there are other codepaths
where reactivation may not happen automatically. Filtering out inactive
users when resolving "self" is therefore a regression: it would return
no results where prior to the AccountResolver rewrite it would have
returned results.

Fix the regression by resolving "self" even when inactive. I'm not
arguing that not auto-reactivating is the best behavior for
googlesource.com, just switching back to the old behavior of
AccountResolver.

The regressed behavior was especially confusing to debug because it
resulted in an exception message saying "Resolving account 'self'
requires login", even though the user was technically logged in.

Change-Id: I5aaf20eeb94ea6de268a96230d14ac85c4eb1863
2019-02-11 15:11:42 +01:00
Dave Borowitz
c3c55cfb4a Fix visibleto:self for anonymous users
This special case was erroneously removed in I7113aa7a. Add a regression
test that would have caught it.

I had thought it was safe to remove because AccountResolver now supports
"self. However, I didn't realize that the isSelf case worked for
anonymous users, while AccountResolver intentionally does not.

Change-Id: I393f74b37215b9a6296eedf1da6a935f1c9518a9
2019-02-08 15:13:33 -08:00
Dave Borowitz
eecebc44d6 NotifyResolver: Use SetMultimap for accounts to notify
An account ID should only appear once per RecipientType; allowing
duplicates of the same account ID with the same RecipientType doesn't
make sense. This shouldn't have any effect in practice, since these
accounts are converted to Sets within OutgoingEmail, but the code is
cleaner this way.

Change-Id: I677def1384151bfe52fa20e291864b260a9df3fb
2019-02-08 08:57:38 -08:00
Dave Borowitz
0312eb2315 Pass notification settings through BatchUpdate's Context
Previously, any notification settings that a BatchUpdateOp wanted to
respect in its postUpdate method needed to be resolved from the
corresponding REST API input and plumbed through the Op constructor so
they could be looked up as needed. Explicit can be good, but this verged
into the territory of _too_ explicit.

Instead, treat the notification settings as a property of the
BatchUpdate. This is somewhat magical, but in this case the magic is
justified. Conceptually, associating notification settings with the
BatchUpdate makes sense: there is a single set of notification settings
that is parsed at the top level from the input, and those settings
should apply to *all* emails sent as a result of that BatchUpdate,
regardless of the particulars of where they're sent from. Putting them
in the Context allows us to treat them as a per-BatchUpdate singleton.

We retain the ability to override the NotifyHandling enum on a
per-*change* basis, rather than a per-*op* basis, to account for the
reduced notifications from WIP changes.

Without this change, there's always the possibility of having multiple
Ops in the same BatchUpdate that send different emails with different
notification settings. For example, we had special code in PostReview
to ignore the notification settings embedded in the constituent
AddReviewerInputs of a ReviewInput. After this change, we still ignore
those settings (as the REST API docs specify), but we don't have to do
anything special to do so: we just set the NotifyResolver.Result on the
BatchUpdate to the one from the ReviewInput, completely ignoring the
AddReviewerInputs.

This change also has the effect of removing any logic around
notification settings from ReviewerAdder; all the notification logic is
in the caller. We still retain a separate mechanism for suppressing all
emails from ReviewerAdder, so that PostReview can send only a single
email. However, this is stored as a simple boolean, rather than passing
around a whole NotifyResolver.Result. It's still not completely ideal,
but considering everything else ReviewerAdder has to deal with, it's a
small win. Plus, simplifying ReviewerAdder will pave the way for
rewriting it in the near future.

One downside here is that any check to set NotifyHandling based on
properties of the change (e.g. the WIP bit) is racy, since the change
was read outside of the BatchUpdate. The risk and consequences of such a
race are low enough that the benefits described above still outweigh it.
(And it's not like it's the only such race, even though we do try to
keep them to a minimum.)

This change should have minimal behavior changes. One exception is that
moving around calls to NotifyResolver#resolve from the body of a try
block to the top level of a REST API handler might result in a 400/422
for invalid input in notify_details rather than logging and silently not
sending an email. Some endpoints already had this behavior, so making
the failure explicit and consistent is considered a feature.

Change-Id: If6f8a44f382f57b9cb10490f74c2b144e904ece8
2019-02-08 08:57:28 -08:00
Dave Borowitz
8e24b76649 Consistently pass NotifyResolver.Result instead of separate args
Change-Id: I457fa6cc45002a88440e33adf609b52f8610b9eb
2019-02-08 08:55:33 -08:00
Dave Borowitz
3949eea76e Refactor NotifyUtil analogously to AccountResolver
NotifyUtil#resolveAccounts was basically a wrapper around
AccountResolver. Give the class a new name, NotifyResolver, and have it
resolve inputs to a Result type. This Result type encapsulates both the
NotifyHandling enum and the ListMultimap that got passed around
everywhere. This has several significant advantages.

First, this pair of objects is used in many places, so cutting down two
arguments (including the unwieldy ListMultimap type) to one is a win on
its own. This change fixes some such methods, and the rest will be fixed
in future cleanups.

Second and more subtly, this change results in more explicit and less
error-prone behavior when a null notify field is passed in a REST API
object. Callers have to explicitly specify a non-null NotifyHandling
input to NotifyResolver#resolve, which typically means they have to do a
firstNonNull(input.notify, <some default>). It turns out that in the
REST API docs, there are several different defaults for the different
*Input types, including some that have different behavior for WIP/ready
changes. The documentation is structured per Input type, which means
it's always clear from the documentation what the default should be if
you have in front of you a FooInput. In other words, this pattern makes
it easier to inspect the code for correctness.

Change-Id: I609674d22b6a16b8fac32aeea1a57d293ee601d5
2019-02-08 08:55:27 -08:00
Dave Borowitz
a9fc40ccdc PostReview: Fix default notification settings, kind of
The code was confused between the input.notify field and the local
reviewerNotify variable; this was clearly a bug. Unfortunately,
attempting to fix it breaks a surprising number of things.

Opt to keep the assignment to input.notify, since later accesses to this
field depend on that side effect.

This bug was causing no emails to be sent in the case where review has
started. The intent of I93395e36 was clearly to send emails to everyone
on a WIP change that has previously started review.

The other set of tests that would fail after properly overwriting the
input.notify field is checking that emails are sent to the owner when
the change is WIP and review hasn't started. In this case, it wasn't
clear to me what the actual intent was. Err on the conservative side,
and change the logic to explicitly email nobody in this case instead of
emailing the owner, under the assumption that users aren't currently
upset by the lack of emails.

Change-Id: Ie0fb1237d5d1aac6e7fda5e4a6ccdc6b5688a89a
2019-02-08 08:49:10 -08:00
Dave Borowitz
b030dfb994 Rename FakeEmailSenderSubject#notSent to didNotSend
"Assert that sender did not send" is slightly more grammatical than "not
sent", and is barely longer.

Change-Id: I16f5b4decee0357e9862b6bedc7b04a9589ab17e
2019-02-08 08:48:14 -08:00
Dave Borowitz
0d085bef87 ChangeNotificationsIT: Consistently check sender queue is empty
In addition to testing the contents of the next email in the queue,
tests should also be asserting that there are no bogus emails being
sent. This can prevent bugs: for example, in PostReview, there is code
to suppress emails from the AddReviewersOp so that a single email can be
sent at the end. Now the tests will actually catch it if that
suppression breaks.

Change all the stage* methods to clear the sender before returning, so
that test methods are just inspecting the messages they intend to send.
Tests for emails generated by API calls that happen to be in the
implementation of stage* methods should be tested directly in dedicated
methods instead.

While we're in there, expand the failure messages to make such failures
easier to debug.

Change-Id: I49329a1ca82b4a060541dd3ebf32a0bb5214c994
2019-02-08 08:47:36 -08:00
Paladox
520d92157a Merge branch 'stable-2.16'
* stable-2.16:
  Support for setting max/min value for "Query Limit" and "Batch Changes"
  Mark DeletePrivate input as @Nullable
  ListProjects: print projects list using secondary index
  ListProjects: re-implement using secondary index
  Fix replacing ${project-base-name} in gr-repo

Change-Id: Id9123dcfbd123a529612fccaecd64ee0c196b216
2019-02-08 14:42:30 +00:00
David Pursehouse
9ae15a31d0 Merge "Don't return single change ref if skipMetadata is set" 2019-02-08 08:54:59 +00:00
Patrick Hiesel
f843d8674e Mark DeletePrivate input as @Nullable
The documentation says that an input is not required. The code checks
for null values correctly, but the injection methods lack @Nullable
which makes Guice fail to create the object when null is passed to
the factory method.

Annotate the input object as @Nullable to fix this.

Change-Id: I0d424e45d6039fd4ad8386b6811b9134cd600dfd
2019-02-08 17:38:01 +09:00
David Pursehouse
7f442e5d95 Merge "Mark DeletePrivate input as @Nullable" 2019-02-08 08:23:25 +00:00
Luca Milanesio
e3efc1f715 ListProjects: print projects list using secondary index
Render the list of projects to OutputStream leveraging the
projects secondary index instead of relying on the in-memory cache.

Change-Id: I864e1c3cd63b206c0f9dc76bbaa6de99ddfdc0d4
2019-02-08 17:22:20 +09:00
Patrick Hiesel
661d2a8b65 Mark DeletePrivate input as @Nullable
The documentation says that an input is not required. The code checks
for null values correctly, but the injection methods lack @Nullable
which makes Guice fail to create the object when null is passed to
the factory method.

Annotate the input object as @Nullable to fix this.

Change-Id: I0d424e45d6039fd4ad8386b6811b9134cd600dfd
2019-02-08 09:13:58 +01:00
Luca Milanesio
5017ba50ce ListProjects: re-implement using secondary index
The GWT UI and other parts of Gerrit still rely on the in-memory
cache for rendering the project list.
This is the first step that moves some use-cases to the QueryProjects
engine: full list without filters and showing only the active and readonly
projects.

All other existing use-cases are still based on the in-memory
cache and are going to be addressed in the follow-up of this change.

With regards to filtering by project name substring, it is not
implemented on top of the secondary index because of Issue 10446.

Bug: Issue 10380
Change-Id: I8effed5f75bdf353d9b23a3d349009e5f0535186
2019-02-08 07:35:11 +00:00
David Pursehouse
6ee8bb3ba4 Merge branch 'stable-2.16'
* stable-2.16:
  Use QueryProjects#apply without parameters
  Set version to 2.15.11-SNAPSHOT

Change-Id: I20ce9764e28f02cd6ba222beb21f4cf0f4bb6b2c
2019-02-08 15:45:33 +09:00
David Pursehouse
3c52bf9f63 Use QueryProjects#apply without parameters
The apply(TopLevelResource) method doesn't actually use the given
resource parameter, and only exists to satisfy the interface of its
parent RestReadView.

A variant of the method without the TopLevelResource parameter was
added in change Ia8ded07a5. Modify callers to use that.

Change-Id: I15af0d1cb35750c8aec4b2f42339901c48332889
2019-02-08 13:30:42 +09:00
David Pursehouse
f682838e82 Merge branch 'stable-2.16'
* stable-2.16:
  queryLimit: specify that limit applies only to PolyGerrit UI
  Disable "prefer-promise-reject-errors" in eslint
  Set version to 2.15.10
  Daemon: Show status of slave and headless mode in 'ready' log
  QueryProjects: introduce apply() without parameters
  Daemon: Don't install online reindexer in slave mode
  ListProjectsIT: test for display to output stream
  RevisionApi: Add method to list votes per revision
  ChangeJson#getApprovalInfo: Add @Nullable annotations
  cmd-review: Add another example to clarify review using change number and PS
  Update .mailmap
  Update cmd-review documentation
  Daemon: use regular binding for auditModule
  CommitValidators: trim "ERROR" shouting from "forge committer" check
  ReceiveCommits: uniformize commit validation error messages.
  Inline "Change-Id" string into error messages
  Always end the "Change-Id missing" error message with \n.
  Print only one hint about Change-Ids at a time
  Clean up Change-Id hint text
  CommitValidators: Replace indexOf calls with String#contains
  CommitValidators: Prefer using Splitter to String.split

Change-Id: I9fad1352d3332f5caff8e317eeba7b3bc0760008
2019-02-08 13:17:34 +09:00
Luca Milanesio
1ff28f3138 Merge branch 'stable-2.15' into stable-2.16
* stable-2.15:
  Disable "prefer-promise-reject-errors" in eslint
  Set version to 2.15.10
  Daemon: Show status of slave and headless mode in 'ready' log
  Daemon: Don't install online reindexer in slave mode
  RevisionApi: Add method to list votes per revision
  ChangeJson#getApprovalInfo: Add @Nullable annotations
  cmd-review: Add another example to clarify review using change number and PS
  Update .mailmap
  Update cmd-review documentation
  Daemon: use regular binding for auditModule
  CommitValidators: trim "ERROR" shouting from "forge committer" check
  ReceiveCommits: uniformize commit validation error messages.
  Inline "Change-Id" string into error messages
  Always end the "Change-Id missing" error message with \n.
  Print only one hint about Change-Ids at a time
  Clean up Change-Id hint text
  CommitValidators: Replace indexOf calls with String#contains
  CommitValidators: Prefer using Splitter to String.split

Changes I0bfe06bd and I58f8a0e5 are intentionally omitted because
they do not apply to the structure of the stable-2.16 branch.

Change-Id: I711837f062aeefeafa3631601b0150448e879575
2019-02-08 00:59:03 +00:00
David Pursehouse
6b585ff6c3 Merge "Mark #hasLegacyPermissions with @UsedAt google" 2019-02-07 10:31:44 +00:00
Luca Milanesio
e83dee7079 QueryProjects: introduce apply() without parameters
QueryProjects REST API does not depend on the resource passed
as input but purely on its query parameters.

Introduce an apply() method without parameters so that the
absence of dependency with the resource becomes more explicit.

Change-Id: Ia8ded07a56a00af15f1fa44679886f24d8eabdd9
2019-02-07 07:48:57 +00:00
Dave Borowitz
d665794c93 Merge changes I8359a0fe,Id4dbe193
* changes:
  MailUtil: Suppress deprecation warning for usage of AccountResolver#resolveByNameOrEmail
  ReviewerAdder: Remove redundant null checks
2019-02-06 16:24:54 +00:00
Edwin Kempin
0ae48b352d Support searching changes that touch directories by regular expressions
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I8865dbf9b6dd7bd3b83f2227206f00c8690ddefb
2019-02-06 15:34:10 +01:00
Edwin Kempin
e8079ce597 Allow matching changes with files that have no extension by 'ext' operator
Files that have no extension can now be matched with the 'ext' search
operator by an empty string: ext:""

This makes the handling of files with no extension consistent between
the 'ext' and 'onlyexts' search operators.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I42774ce8641c429e6fc7aa55948769cc0a1fa48e
2019-02-06 15:29:30 +01:00
Edwin Kempin
0e88d5d69a Support searching changes by directories
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I4192646dc50ace09e1f7b697f5b352b6ceca12fa
2019-02-06 15:19:15 +01:00
Edwin Kempin
f148c79933 Support searching changes by commit message footer
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Id7e08e57bc0cf23e707a84174abe8178c04d4acf
2019-02-06 15:17:44 +01:00
Edwin Kempin
5a058526eb Merge "Support searching changes which only touch certain file extensions" 2019-02-06 13:37:49 +00:00
David Pursehouse
8895c7dc90 MailUtil: Suppress deprecation warning for usage of AccountResolver#resolveByNameOrEmail
Change-Id: I8359a0fe89e2450eab1c499d3712457b34b7289b
2019-02-06 21:05:02 +09:00
David Pursehouse
a3aaf671a6 ReviewerAdder: Remove redundant null checks
Change-Id: Id4dbe19330b1d7a7bd000d86ea6f66039b5f2c4c
2019-02-06 21:02:17 +09:00
Patrick Hiesel
a55bfeedba Don't return single change ref if skipMetadata is set
skipMetadata indicates that all meta refs should be omitted. This is
more of a performance option than a security option, but for the sake of
completeness, this commit also omits single change ref evaluation in
case the option is provided.

Change-Id: I8bfb80fc727b8abf928d1c6ac1fd715149bfbe3a
2019-02-06 10:26:55 +01:00
Edwin Kempin
cfd05fac3d Merge changes from topic "account-resolver-2"
* changes:
  Rename AccountResolver#byId to accountCache
  Update {account-id} documentation
  Rename AccountResolver2 to AccountResolver
  Remove now-unused old AccountResolver implementation
  Remove unnecessary explicit binding of AccountResolver
  Use AccountResolver2 to resolve strings to IdentifiedUsers
  AccountResolver2: Allow resolving "self" and "me"
  AccountResolver2: Expose more useful exception information
  AccountResolver: Mark more methods as private
  Implement new AccountResolver2#resolveByNameOrEmail
  Rewrite AccountResolver with consistent interface and semantics
2019-02-06 07:39:51 +00:00
David Pursehouse
cf66772c31 Merge branch 'stable-2.16'
* stable-2.16:
  Update codemirror-editor submodule
  LuceneProjectIndex: fix NPE when project disappeared on disk

Change-Id: I0048f6245f81c58dbe8bd2ed43ffa48e6846d23c
2019-02-06 10:37:52 +09:00
David Pursehouse
0a2bd82e13 Merge branch 'stable-2.16'
* stable-2.16:
  Rely on GroupAuditService rather than its implementation

Change-Id: I54c285adec60c1e8af2ed03aacd01fa667f0ca58
2019-02-06 10:00:51 +09:00
Luca Milanesio
57bfaba1d0 LuceneProjectIndex: fix NPE when project disappeared on disk
Fix a NPE in the decoding of ProjectState to ProjectData when a project
is removed from disk while Gerrit is still running.

Change-Id: I9bbf4e88a3b41d677e17121d10f38d8f901b2e99
2019-02-05 22:59:16 +00:00
Marco Miller
577ffab5de Merge "Merge branch 'stable-2.16'" 2019-02-05 22:03:17 +00:00
Luca Milanesio
6a130c17a2 Rely on GroupAuditService rather than its implementation
GroupAuditService is the interface to the underlying audit
system, while AuditService is the actual implementation.

Instead of directly injecting the implementation class, rely on
the interface and leave the association to AuditService to the
Guice binding.

This is useful because tests may want to replace, at times, the
actual implementation of the audit-trail with a fake in-memory
store.

Change-Id: I31bbb522fb974c2504635ccf1251287d4890af89
2019-02-05 20:34:22 +00:00