Merge "git-repo: change "pytest" to "tests"" into main
diff --git a/generated/commit-queue.cfg b/generated/commit-queue.cfg
index 12c78bf..a018579 100644
--- a/generated/commit-queue.cfg
+++ b/generated/commit-queue.cfg
@@ -22,6 +22,11 @@
     tryjob {
       builders {
         name: "gerrit/try/Verify gerrit CL"
+        location_filters {
+          gerrit_host_regexp: ".*"
+          gerrit_project_regexp: ".*"
+          path_regexp: "polygerrit-ui/.+"
+        }
         mode_allowlist: "DRY_RUN"
         mode_allowlist: "FULL_RUN"
         mode_allowlist: "NEW_PATCHSET_RUN"
@@ -35,6 +40,42 @@
       }
     }
   }
+  post_actions {
+    name: "success"
+    conditions {
+      mode: "DRY_RUN"
+      statuses: SUCCEEDED
+    }
+    conditions {
+      mode: "NEW_PATCHSET_RUN"
+      statuses: SUCCEEDED
+    }
+    vote_gerrit_labels {
+      votes {
+        name: "Frontend-Verified"
+        value: 1
+      }
+    }
+  }
+  post_actions {
+    name: "failure"
+    conditions {
+      mode: "DRY_RUN"
+      statuses: FAILED
+      statuses: CANCELLED
+    }
+    conditions {
+      mode: "NEW_PATCHSET_RUN"
+      statuses: FAILED
+      statuses: CANCELLED
+    }
+    vote_gerrit_labels {
+      votes {
+        name: "Frontend-Verified"
+        value: -1
+      }
+    }
+  }
 }
 config_groups {
   name: "git-repo_repo"
diff --git a/generated/project.cfg b/generated/project.cfg
index f3f86db..5f0f731 100644
--- a/generated/project.cfg
+++ b/generated/project.cfg
@@ -7,7 +7,7 @@
 name: "gerrit"
 access: "group:all"
 lucicfg {
-  version: "1.38.1"
+  version: "1.39.4"
   package_dir: ".."
   config_dir: "generated"
   entry_point: "main.star"
diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md
index ae7ec1f..3c34cdc 100644
--- a/recipes/README.recipes.md
+++ b/recipes/README.recipes.md
@@ -10,11 +10,11 @@
 
 ### *recipes* / [gerrit](/recipes/recipes/gerrit.py)
 
-[DEPS](/recipes/recipes/gerrit.py#11): [depot\_tools/gerrit][depot_tools/recipe_modules/gerrit], [depot\_tools/gsutil][depot_tools/recipe_modules/gsutil], [fuchsia/git][fuchsia/recipe_modules/git], [infra/zip][infra/recipe_modules/zip], [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/file][recipe_engine/recipe_modules/file], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/nodejs][recipe_engine/recipe_modules/nodejs], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step]
+[DEPS](/recipes/recipes/gerrit.py#11): [depot\_tools/gsutil][depot_tools/recipe_modules/gsutil], [fuchsia/git][fuchsia/recipe_modules/git], [infra/zip][infra/recipe_modules/zip], [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/file][recipe_engine/recipe_modules/file], [recipe\_engine/nodejs][recipe_engine/recipe_modules/nodejs], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step]
 
 PYTHON_VERSION_COMPATIBILITY: PY3
 
-— **def [RunSteps](/recipes/recipes/gerrit.py#27)(api):**
+— **def [RunSteps](/recipes/recipes/gerrit.py#25)(api):**
 ### *recipes* / [git-repo](/recipes/recipes/git-repo.py)
 
 [DEPS](/recipes/recipes/git-repo.py#15): [depot\_tools/bot\_update][depot_tools/recipe_modules/bot_update], [depot\_tools/gclient][depot_tools/recipe_modules/gclient], [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/step][recipe_engine/recipe_modules/step]
diff --git a/recipes/recipes/gerrit.expected/no_polygerrit-ui_changes skips tests.json b/recipes/recipes/gerrit.expected/no_polygerrit-ui_changes skips tests.json
deleted file mode 100644
index e230e7e..0000000
--- a/recipes/recipes/gerrit.expected/no_polygerrit-ui_changes skips tests.json
+++ /dev/null
@@ -1,58 +0,0 @@
-[
-  {
-    "cmd": [
-      "vpython3",
-      "RECIPE_REPO[depot_tools]/gerrit_client.py",
-      "changes",
-      "--host",
-      "https://gerrit-review.googlesource.com",
-      "--json_file",
-      "/path/to/tmp/json",
-      "--limit",
-      "1",
-      "-p",
-      "change=123",
-      "-o",
-      "ALL_REVISIONS",
-      "-o",
-      "ALL_FILES"
-    ],
-    "env": {
-      "PATH": "<PATH>:RECIPE_REPO[depot_tools]"
-    },
-    "infra_step": true,
-    "luci_context": {
-      "realm": {
-        "name": "gerrit:try"
-      },
-      "resultdb": {
-        "current_invocation": {
-          "name": "invocations/build:8945511751514863184",
-          "update_token": "token"
-        },
-        "hostname": "rdbhost"
-      }
-    },
-    "name": "gerrit changes",
-    "~followup_annotations": [
-      "@@@STEP_LOG_LINE@json.output@[@@@",
-      "@@@STEP_LOG_LINE@json.output@  {@@@",
-      "@@@STEP_LOG_LINE@json.output@    \"_number\": 123, @@@",
-      "@@@STEP_LOG_LINE@json.output@    \"revisions\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@      \"a1b2c3\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"_number\": 4, @@@",
-      "@@@STEP_LOG_LINE@json.output@        \"files\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@          \"java/com/gerrit/Foo.java\": {}@@@",
-      "@@@STEP_LOG_LINE@json.output@        }@@@",
-      "@@@STEP_LOG_LINE@json.output@      }@@@",
-      "@@@STEP_LOG_LINE@json.output@    }@@@",
-      "@@@STEP_LOG_LINE@json.output@  }@@@",
-      "@@@STEP_LOG_LINE@json.output@]@@@",
-      "@@@STEP_LOG_END@json.output@@@"
-    ]
-  },
-  {
-    "name": "$result",
-    "summaryMarkdown": "No polygerrit-ui/ files found. All checks skipped."
-  }
-]
\ No newline at end of file
diff --git a/recipes/recipes/gerrit.expected/polygerrit-ui_changes with failed step.json b/recipes/recipes/gerrit.expected/polygerrit-ui_changes with failed step.json
index cbca061..426db05 100644
--- a/recipes/recipes/gerrit.expected/polygerrit-ui_changes with failed step.json
+++ b/recipes/recipes/gerrit.expected/polygerrit-ui_changes with failed step.json
@@ -2,58 +2,6 @@
   {
     "cmd": [
       "vpython3",
-      "RECIPE_REPO[depot_tools]/gerrit_client.py",
-      "changes",
-      "--host",
-      "https://gerrit-review.googlesource.com",
-      "--json_file",
-      "/path/to/tmp/json",
-      "--limit",
-      "1",
-      "-p",
-      "change=123",
-      "-o",
-      "ALL_REVISIONS",
-      "-o",
-      "ALL_FILES"
-    ],
-    "env": {
-      "PATH": "<PATH>:RECIPE_REPO[depot_tools]"
-    },
-    "infra_step": true,
-    "luci_context": {
-      "realm": {
-        "name": "gerrit:try"
-      },
-      "resultdb": {
-        "current_invocation": {
-          "name": "invocations/build:8945511751514863184",
-          "update_token": "token"
-        },
-        "hostname": "rdbhost"
-      }
-    },
-    "name": "gerrit changes",
-    "~followup_annotations": [
-      "@@@STEP_LOG_LINE@json.output@[@@@",
-      "@@@STEP_LOG_LINE@json.output@  {@@@",
-      "@@@STEP_LOG_LINE@json.output@    \"_number\": 123, @@@",
-      "@@@STEP_LOG_LINE@json.output@    \"revisions\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@      \"a1b2c3\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"_number\": 4, @@@",
-      "@@@STEP_LOG_LINE@json.output@        \"files\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@          \"polygerrit-ui/app/foo.ts\": {}@@@",
-      "@@@STEP_LOG_LINE@json.output@        }@@@",
-      "@@@STEP_LOG_LINE@json.output@      }@@@",
-      "@@@STEP_LOG_LINE@json.output@    }@@@",
-      "@@@STEP_LOG_LINE@json.output@  }@@@",
-      "@@@STEP_LOG_LINE@json.output@]@@@",
-      "@@@STEP_LOG_END@json.output@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "vpython3",
       "-u",
       "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
       "--json-output",
diff --git a/recipes/recipes/gerrit.expected/polygerrit-ui_changes.json b/recipes/recipes/gerrit.expected/polygerrit-ui_changes.json
index 11e265f..19eb5d1 100644
--- a/recipes/recipes/gerrit.expected/polygerrit-ui_changes.json
+++ b/recipes/recipes/gerrit.expected/polygerrit-ui_changes.json
@@ -2,58 +2,6 @@
   {
     "cmd": [
       "vpython3",
-      "RECIPE_REPO[depot_tools]/gerrit_client.py",
-      "changes",
-      "--host",
-      "https://gerrit-review.googlesource.com",
-      "--json_file",
-      "/path/to/tmp/json",
-      "--limit",
-      "1",
-      "-p",
-      "change=123",
-      "-o",
-      "ALL_REVISIONS",
-      "-o",
-      "ALL_FILES"
-    ],
-    "env": {
-      "PATH": "<PATH>:RECIPE_REPO[depot_tools]"
-    },
-    "infra_step": true,
-    "luci_context": {
-      "realm": {
-        "name": "gerrit:try"
-      },
-      "resultdb": {
-        "current_invocation": {
-          "name": "invocations/build:8945511751514863184",
-          "update_token": "token"
-        },
-        "hostname": "rdbhost"
-      }
-    },
-    "name": "gerrit changes",
-    "~followup_annotations": [
-      "@@@STEP_LOG_LINE@json.output@[@@@",
-      "@@@STEP_LOG_LINE@json.output@  {@@@",
-      "@@@STEP_LOG_LINE@json.output@    \"_number\": 123, @@@",
-      "@@@STEP_LOG_LINE@json.output@    \"revisions\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@      \"a1b2c3\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@        \"_number\": 4, @@@",
-      "@@@STEP_LOG_LINE@json.output@        \"files\": {@@@",
-      "@@@STEP_LOG_LINE@json.output@          \"polygerrit-ui/app/foo.ts\": {}@@@",
-      "@@@STEP_LOG_LINE@json.output@        }@@@",
-      "@@@STEP_LOG_LINE@json.output@      }@@@",
-      "@@@STEP_LOG_LINE@json.output@    }@@@",
-      "@@@STEP_LOG_LINE@json.output@  }@@@",
-      "@@@STEP_LOG_LINE@json.output@]@@@",
-      "@@@STEP_LOG_END@json.output@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "vpython3",
       "-u",
       "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
       "--json-output",
diff --git a/recipes/recipes/gerrit.py b/recipes/recipes/gerrit.py
index 89d6fc7..f008016 100644
--- a/recipes/recipes/gerrit.py
+++ b/recipes/recipes/gerrit.py
@@ -9,14 +9,12 @@
 # All the deps get combined into an `api` variable passed in to RunSteps and
 # GenTests. Versions and urls are specified in `recipes.cfg`.
 DEPS = [
-    'depot_tools/gerrit',
     'depot_tools/gsutil',
     'infra/zip',
     'fuchsia/git',
     'recipe_engine/buildbucket',
     'recipe_engine/context',
     'recipe_engine/file',
-    'recipe_engine/json',
     'recipe_engine/nodejs',
     'recipe_engine/path',
     'recipe_engine/raw_io',
@@ -26,16 +24,7 @@
 
 def RunSteps(api):
     # Check out the change and run the frontend linter, type checker, and tests
-    # to verify the change as part of Change Verification (ie. CQ label). Skips
-    # everything if no polygerrit-ui/ files are in the change.
-
-    files = _getModifiedFiles(api)
-
-    if not [f for f in files if f.startswith("polygerrit-ui/")]:
-        return RawResult(
-            status=common.SUCCESS,
-            summary_markdown='No polygerrit-ui/ files found. All checks skipped.',
-        )
+    # to verify the change as part of Change Verification (ie. CQ label).
 
     # Checkout the change into a special 'cleanup' folder that is cleared
     # between runs of the recipe.
@@ -64,28 +53,6 @@
             )
 
 
-def _getModifiedFiles(api):
-    # Type: https://chromium.googlesource.com/infra/luci/luci-go/+/refs/heads/main/buildbucket/proto/common.proto#179
-    gerrit_change = api.buildbucket.build.input.gerrit_changes[0]
-    # Endpoint: https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
-    changeInfo = api.gerrit.get_changes(
-        'https://gerrit-review.googlesource.com',
-        query_params=[('change', gerrit_change.change)],
-        o_params=['ALL_REVISIONS', 'ALL_FILES'],
-        limit=1
-    )[0]
-    return _filesFromChangeInfo(changeInfo, gerrit_change.patchset)
-
-
-def _filesFromChangeInfo(changeInfo, patchset):
-    return [
-        file
-        for revision in changeInfo['revisions'].values()
-        if revision['_number'] == patchset
-        for file in revision['files']
-    ]
-
-
 def _downloadChange(api):
     gerrit_change = api.buildbucket.build.input.gerrit_changes[0]
     remote = "https://gerrit.googlesource.com/gerrit"
@@ -152,18 +119,6 @@
             change_number=123,
             patch_set=4
         ),
-        api.override_step_data(
-            'gerrit changes',
-            api.json.output([{
-                '_number': 123,
-                'revisions': {
-                    'a1b2c3': {
-                        '_number': 4,
-                        'files': {"polygerrit-ui/app/foo.ts": {}}
-                    }
-                }
-            }])
-        ),
         api.post_process(MustRun, 'run type checker'),
         api.post_process(MustRun, 'run linter'),
         api.post_process(MustRun, 'run tests'),
@@ -180,18 +135,6 @@
             patch_set=4
         ),
         api.override_step_data(
-            'gerrit changes',
-            api.json.output([{
-                '_number': 123,
-                'revisions': {
-                    'a1b2c3': {
-                        '_number': 4,
-                        'files': {"polygerrit-ui/app/foo.ts": {}}
-                    }
-                }
-            }])
-        ),
-        api.override_step_data(
             'run linter',
             retcode=1,
             stdout=api.raw_io.output('Linter fail: xyz')
@@ -202,32 +145,3 @@
         api.post_process(StatusFailure),
         api.post_process(SummaryMarkdown, 'Step(\'run linter\') (retcode: 1)'),
     )
-
-    yield api.test(
-        'no_polygerrit-ui_changes skips tests',
-        api.buildbucket.try_build(
-            project="gerrit",
-            git_repo="https://gerrit.googlesource.com/gerrit",
-            change_number=123,
-            patch_set=4
-        ),
-        api.override_step_data(
-            'gerrit changes',
-            api.json.output([{
-                '_number': 123,
-                'revisions': {
-                    'a1b2c3': {
-                        '_number': 4,
-                        'files': {"java/com/gerrit/Foo.java": {}}
-                    }
-                }
-            }])
-        ),
-        api.post_process(DoesNotRun, 'run type checker'),
-        api.post_process(DoesNotRun, 'run linter'),
-        api.post_process(DoesNotRun, 'run tests'),
-        api.post_process(StatusSuccess),
-        api.post_process(
-            SummaryMarkdown,
-            'No polygerrit-ui/ files found. All checks skipped.'),
-    )
diff --git a/repos/gerrit.star b/repos/gerrit.star
index fc9667c..a81311e 100644
--- a/repos/gerrit.star
+++ b/repos/gerrit.star
@@ -45,6 +45,36 @@
         repo = "https://gerrit.googlesource.com/gerrit",
         refs = ["refs/heads/master"],
     ),
+    post_actions = [
+        cq.post_action_gerrit_label_votes(
+            name = "success",
+            conditions = [
+                cq.post_action_triggering_condition(
+                    mode = cq.MODE_DRY_RUN,
+                    statuses=[cq.STATUS_SUCCEEDED],
+                ),
+                cq.post_action_triggering_condition(
+                    mode = cq.MODE_NEW_PATCHSET_RUN,
+                    statuses=[cq.STATUS_SUCCEEDED],
+                ),
+            ],
+            labels = {"Frontend-Verified": 1},
+        ),
+        cq.post_action_gerrit_label_votes(
+            name = "failure",
+            conditions = [
+                cq.post_action_triggering_condition(
+                    mode = cq.MODE_DRY_RUN,
+                    statuses=[cq.STATUS_FAILED, cq.STATUS_CANCELLED],
+                ),
+                cq.post_action_triggering_condition(
+                    mode = cq.MODE_NEW_PATCHSET_RUN,
+                    statuses=[cq.STATUS_FAILED, cq.STATUS_CANCELLED],
+                ),
+            ],
+            labels = {"Frontend-Verified": -1},
+        ),
+    ],
 )
 
 # Attach our "Verify gerrit CL" builder to this CQ group.
@@ -57,6 +87,11 @@
         cq.MODE_FULL_RUN,
         cq.MODE_NEW_PATCHSET_RUN,
     ],
+    location_filters = [
+        cq.location_filter(
+            path_regexp = 'polygerrit-ui/.+'
+        ),
+    ],
 )
 
 # Show on https://ci.chromium.org/p/gerrit