PRESUBMIT: Add safe guard for gerrit value in PRESUBMIT

This change will add a safe guard for gerrit value in PRESUBMIT.py to
avoid NoneType object error and be more robust.

[email protected]

Bug: 1167342
Change-Id: I4758e10244a1441479b0a87f631f591c5124278f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2719527
Reviewed-by: Edward Lesmes <[email protected]>
Reviewed-by: Dirk Pranke <[email protected]>
Commit-Queue: Edward Lesmes <[email protected]>
Cr-Commit-Position: refs/heads/master@{#858300}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index f5c00e6..ec9461e3 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -2310,6 +2310,11 @@
   target file or directory, to avoid layering violations from being
   introduced. This check verifies that this happens.
   """
+  # We rely on Gerrit's code-owners to check approvals.
+  # input_api.gerrit is always set for Chromium, but other projects
+  # might not use Gerrit.
+  if not input_api.gerrit:
+    return []
   if input_api.change.issue:
     # Skip OWNERS check when Bot-Commit label is approved. This label is
     # intended for commits made by trusted bots that don't require review nor