Merge branch 'stable-3.2'

* stable-3.2:
  Fix broken CheckerRefMigrationTest
  Docs: Add missing comma to example responses
  Docs: remove trailing comma from example requests/responses
  Doc: Change CheckInput example to valid JSON

Change-Id: Ia4448b1ecb7a3313981d96a626ecaa99879245a3
diff --git a/BUILD b/BUILD
index 79ebe56..e1a244a 100644
--- a/BUILD
+++ b/BUILD
@@ -1,3 +1,8 @@
+load(
+    "//tools/bzl:plugin.bzl",
+    "gerrit_plugin",
+)
+
 package_group(
     name = "visibility",
     packages = ["//plugins/checks/..."],
@@ -5,11 +10,6 @@
 
 package(default_visibility = [":visibility"])
 
-load(
-    "//tools/bzl:plugin.bzl",
-    "gerrit_plugin",
-)
-
 gerrit_plugin(
     name = "checks",
     srcs = glob(["java/com/google/gerrit/plugins/checks/**/*.java"]),
diff --git a/gr-checks/BUILD b/gr-checks/BUILD
index 3889aae..0f931db 100644
--- a/gr-checks/BUILD
+++ b/gr-checks/BUILD
@@ -1,3 +1,7 @@
+load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
+load("//tools/bzl:js.bzl", "polygerrit_plugin")
+load("//tools/bzl:genrule2.bzl", "genrule2")
+
 package_group(
     name = "visibility",
     packages = ["//plugins/checks/..."],
@@ -5,10 +9,6 @@
 
 package(default_visibility = [":visibility"])
 
-load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
-load("//tools/bzl:js.bzl", "polygerrit_plugin")
-load("//tools/bzl:genrule2.bzl", "genrule2")
-
 polygerrit_plugin(
     name = "gr-checks",
     app = "checks-bundle.js",
@@ -19,9 +19,9 @@
     name = "checks-bundle",
     srcs = glob(["*.js"]),
     entry_point = "gr-checks.js",
+    format = "iife",
     rollup_bin = "//tools/node_tools:rollup-bin",
     sourcemap = "hidden",
-    format = 'iife',
     deps = [
         "@tools_npm//rollup-plugin-node-resolve",
     ],
diff --git a/gr-checks/gr-checkers-list.js b/gr-checks/gr-checkers-list.js
index b7441e9..da61b22 100644
--- a/gr-checks/gr-checkers-list.js
+++ b/gr-checks/gr-checkers-list.js
@@ -200,7 +200,7 @@
   }
 
   _handleEditCancel(e) {
-    if (e.detail.reload) {
+    if (e.detail && e.detail.reload) {
       this._getCheckers();
     }
     this.$.editOverlay.close();
diff --git a/java/com/google/gerrit/plugins/checks/ChecksUpdate.java b/java/com/google/gerrit/plugins/checks/ChecksUpdate.java
index 63df867..b017b68 100644
--- a/java/com/google/gerrit/plugins/checks/ChecksUpdate.java
+++ b/java/com/google/gerrit/plugins/checks/ChecksUpdate.java
@@ -31,6 +31,7 @@
 import com.google.gerrit.server.ServerInitiated;
 import com.google.gerrit.server.UserInitiated;
 import com.google.gerrit.server.change.NotifyResolver;
+import com.google.gerrit.server.mail.send.MessageIdGenerator;
 import com.google.gerrit.server.notedb.ChangeNotes;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
@@ -64,6 +65,7 @@
   private final Checks checks;
   private final Checkers checkers;
   private final NotifyResolver notifyResolver;
+  private final MessageIdGenerator messageIdGenerator;
   private final Optional<IdentifiedUser> currentUser;
 
   @AssistedInject
@@ -76,6 +78,7 @@
       Checks checks,
       Checkers checkers,
       NotifyResolver notifyResolver,
+      MessageIdGenerator messageIdGenerator,
       @Assisted IdentifiedUser currentUser) {
     this.checksStorageUpdate = checksStorageUpdate;
     this.combinedCheckStateCache = combinedCheckStateCache;
@@ -85,6 +88,7 @@
     this.checks = checks;
     this.checkers = checkers;
     this.notifyResolver = notifyResolver;
+    this.messageIdGenerator = messageIdGenerator;
     this.currentUser = Optional.of(currentUser);
   }
 
@@ -97,7 +101,8 @@
       PatchSetUtil psUtil,
       Checks checks,
       Checkers checkers,
-      NotifyResolver notifyResolver) {
+      NotifyResolver notifyResolver,
+      MessageIdGenerator messageIdGenerator) {
     this.checksStorageUpdate = checksStorageUpdate;
     this.combinedCheckStateCache = combinedCheckStateCache;
     this.combinedCheckStateUpdatedSenderFactory = combinedCheckStateUpdatedSenderFactory;
@@ -106,6 +111,7 @@
     this.checks = checks;
     this.checkers = checkers;
     this.notifyResolver = notifyResolver;
+    this.messageIdGenerator = messageIdGenerator;
     this.currentUser = Optional.empty();
   }
 
@@ -200,6 +206,8 @@
           updatedCheck);
       sender.setNotify(notify);
       sender.setChecksByChecker(getAllChecksByChecker(checkKey));
+      sender.setMessageId(
+          messageIdGenerator.fromChangeUpdate(checkKey.repository(), checkKey.patchSet()));
       sender.send();
     } catch (Exception e) {
       logger.atSevere().withCause(e).log(
diff --git a/javatests/com/google/gerrit/plugins/checks/BUILD b/javatests/com/google/gerrit/plugins/checks/BUILD
index aeded72..e76fbfa 100644
--- a/javatests/com/google/gerrit/plugins/checks/BUILD
+++ b/javatests/com/google/gerrit/plugins/checks/BUILD
@@ -1,7 +1,7 @@
-package(default_visibility = ["//plugins/checks:visibility"])
-
 load("//tools/bzl:junit.bzl", "junit_tests")
 
+package(default_visibility = ["//plugins/checks:visibility"])
+
 junit_tests(
     name = "checks_tests",
     srcs = glob(["*.java"]),
diff --git a/javatests/com/google/gerrit/plugins/checks/acceptance/BUILD b/javatests/com/google/gerrit/plugins/checks/acceptance/BUILD
index e279935..78075c6 100644
--- a/javatests/com/google/gerrit/plugins/checks/acceptance/BUILD
+++ b/javatests/com/google/gerrit/plugins/checks/acceptance/BUILD
@@ -1,7 +1,7 @@
-package(default_visibility = ["//plugins/checks:visibility"])
-
 load("//javatests/com/google/gerrit/acceptance:tests.bzl", "acceptance_tests")
 
+package(default_visibility = ["//plugins/checks:visibility"])
+
 acceptance_tests(
     srcs = glob(["*IT.java"]),
     group = "checks",
diff --git a/javatests/com/google/gerrit/plugins/checks/acceptance/db/BUILD b/javatests/com/google/gerrit/plugins/checks/acceptance/db/BUILD
index 03caa7d..af19b27 100644
--- a/javatests/com/google/gerrit/plugins/checks/acceptance/db/BUILD
+++ b/javatests/com/google/gerrit/plugins/checks/acceptance/db/BUILD
@@ -1,7 +1,7 @@
-package(default_visibility = ["//plugins/checks:visibility"])
-
 load("//javatests/com/google/gerrit/acceptance:tests.bzl", "acceptance_tests")
 
+package(default_visibility = ["//plugins/checks:visibility"])
+
 acceptance_tests(
     srcs = glob(["*IT.java"]),
     group = "get_combined_check_state",
diff --git a/javatests/com/google/gerrit/plugins/checks/acceptance/testsuite/BUILD b/javatests/com/google/gerrit/plugins/checks/acceptance/testsuite/BUILD
index 692ac74..535f220 100644
--- a/javatests/com/google/gerrit/plugins/checks/acceptance/testsuite/BUILD
+++ b/javatests/com/google/gerrit/plugins/checks/acceptance/testsuite/BUILD
@@ -1,7 +1,7 @@
-package(default_visibility = ["//plugins/checks:visibility"])
-
 load("//javatests/com/google/gerrit/acceptance:tests.bzl", "acceptance_tests")
 
+package(default_visibility = ["//plugins/checks:visibility"])
+
 acceptance_tests(
     srcs = glob(["*Test.java"]),
     group = "checks",