Highlight matching atoms of copy conditions in change messages

When a new patch set is created and approvals are copied to the new
patch set or if approvals are dropped (because they cannot be copied to
the new patch set) Gerrit posts a change message to inform about the
copied and outdated votes. For each copied/outdated vote the change
message includes the corresponding copy condition, so that users can
check why a vote matched or didn't match the copy condition.

Understanding why a vote matched or didn't match the copy condition
could be easier though if the passing and failing atoms in the copy
condition would be highlighted. E.g. for expressions of submit
requirements we already have such highlighting (passing atoms are
underlined in green, failing atoms are underlined in red).

It would be nice to have the same highlighting for copy conditions, but
it's not easily doable. For the expressions of the submit requirements
the highlighting is done in the web frontend. This requires the web
frontend to know about the expression and the passing and failing atoms,
which means that the backend must have an API to return this data.
Adding such an API for copy conditions is not easy, since they are
embedded in change messages which are plain strings. In addition the
backend has only the current copy condition available and in restrospect
it can't tell how the copy condition looked like at the moment when the
copy evaluation for a certain approval was done.

That's why for highlighting atoms in copy conditions we take a different
approach. The change message with the copy conditions is generated at
the moment when the copy evaluation is done. At this moment we can check
which atoms of the copy conditions are passing/failing. We can then use
this information to highlight the passing atoms in the change message.
The change message is a plain string, but Markdown formatting is
supported. We make use of this and use Markdown syntax to print passing
atoms in bold. This is not the same formatting as for expressions of
submit requirements, but it's the best we can do with Markdown. Markdown
does neither support underlining text nor colored text (this is only
possible with HTML snippets but those are not supported in change
messages). This approach can be implemented with little effort and still
allows us to highlight which atoms of a copy condition are passing.

To implement this we compute the passing/failing atoms of the copy
condition at the moment when the copy evaluation in ApprovalCopier is
done. To pass this information to the caller we change the type for the
copied/outdated approvals in ApprovalCopier.Result from PatchSetApproval
to a new ApprovalData type that contains the PatchSetApproval and the
passing and failing atoms (for consistency the method names for getting
the passing/failing atoms are kept the same as for
SubmitRequirementExpressionResult).

ApprovalsUtil gets the copied/outdated approvals as input to format the
change message with copied/dropped votes. In addition to the
copied/outdated approvals it now has the passing and failing atoms
available for each approval, so that it can format the passing atoms in
bold (using Markdown syntax).

So far approvals with the same label had been grouped as one line in the
change message (since they have the same copy condition), e.g.:

  Copied Votes:
  * Code-Review-2, Code-Review+2 (copy condition: "is:MIN OR is:MAX")

Now we need to split those into multiple lines if the passing atoms
differ, so that in every line we can higlight different atoms:

 Copied Votes:
  * Code-Review-2 (copy condition: "**is:MIN** OR is:MAX")
  * Code-Review+2 (copy condition: "is:MIN OR **is:MAX**")

If approvals for the same label have the same passing atoms they are
still grouped together as one line, e.g.:

  Copied Votes:
  * Code-Review-1, Code-Review+1 (copy condition: "is:MIN OR **changekind:TRIVIAL_REBASE**")

Bug: Google b/240377462
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I7b42f350f9d79b1dc3cac62aeac7d7c7f8699456
Release-Notes: Matching atoms in copy conditions that are posted as change messages are highlighted in bold now
7 files changed
tree: f2814066fea9760b34c6fd307119a8a7d6f15ba8
  1. .settings/
  2. .ts-out/
  3. antlr3/
  4. contrib/
  5. Documentation/
  6. e2e-tests/
  7. java/
  8. javatests/
  9. lib/
  10. modules/
  11. plugins/
  12. polygerrit-ui/
  13. prolog/
  14. prologtests/
  15. proto/
  16. resources/
  17. tools/
  18. webapp/
  19. .bazelignore
  20. .bazelproject
  21. .bazelrc
  22. .bazelversion
  23. .editorconfig
  24. .git-blame-ignore-revs
  25. .gitignore
  26. .gitmodules
  27. .gitreview
  28. .mailmap
  29. .pydevproject
  30. .zuul.yaml
  31. BUILD
  32. COPYING
  33. INSTALL
  34. Jenkinsfile
  35. package.json
  36. README.md
  37. SUBMITTING_PATCHES
  38. version.bzl
  39. web-dev-server.config.mjs
  40. WORKSPACE
  41. yarn.lock
README.md

Gerrit Code Review

Gerrit is a code review and project management tool for Git based projects.

Build Status Maven Central

Objective

Gerrit makes reviews easier by showing changes in a side-by-side display, and allowing inline comments to be added by any reviewer.

Gerrit simplifies Git based project maintainership by permitting any authorized user to submit changes to the master Git repository, rather than requiring all approved changes to be merged in by hand by the project maintainer.

Documentation

For information about how to install and use Gerrit, refer to the documentation.

Source

Our canonical Git repository is located on googlesource.com. There is a mirror of the repository on Github.

Reporting bugs

Please report bugs on the issue tracker.

Contribute

Gerrit is the work of hundreds of contributors. We appreciate your help!

Please read the contribution guidelines.

Note that we do not accept Pull Requests via the Github mirror.

Getting in contact

The Developer Mailing list is repo-discuss on Google Groups.

License

Gerrit is provided under the Apache License 2.0.

Build

Install Bazel and run the following:

    git clone --recurse-submodules https://gerrit.googlesource.com/gerrit
    cd gerrit && bazel build release

Install binary packages (Deb/Rpm)

The instruction how to configure GerritForge/BinTray repositories is here

On Debian/Ubuntu run:

    apt-get update && apt-get install gerrit=<version>-<release>

NOTE: release is a counter that starts with 1 and indicates the number of packages that have been released with the same version of the software.

On CentOS/RedHat run:

    yum clean all && yum install gerrit-<version>[-<release>]

On Fedora run:

    dnf clean all && dnf install gerrit-<version>[-<release>]

Use pre-built Gerrit images on Docker

Docker images of Gerrit are available on DockerHub

To run a CentOS 8 based Gerrit image:

    docker run -p 8080:8080 gerritcodereview/gerrit[:version]-centos8

To run a Ubuntu 20.04 based Gerrit image:

    docker run -p 8080:8080 gerritcodereview/gerrit[:version]-ubuntu20

NOTE: release is optional. Last released package of the version is installed if the release number is omitted.