Add presubmit to dart_ci repository

The presubmit checks that all changed files are formatted with dartfmt.

Change-Id: I8f60091fb438b2882d6e78e2a92710861545e957
Reviewed-on: https://dart-review.googlesource.com/c/dart_ci/+/144420
Reviewed-by: Alexander Thomas <athom@google.com>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
new file mode 100644
index 0000000..4cfaec0
--- /dev/null
+++ b/PRESUBMIT.py
@@ -0,0 +1,43 @@
+# Copyright (c) 2020, the Dart project authors.  Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE file.
+"""Presubmit script for dart_ci repository.
+
+See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
+for more details about the presubmit API built into git cl.
+"""
+
+import subprocess
+
+
+def _NeedsFormat(path):
+  return subprocess.call(['dartfmt', '--set-exit-if-changed', '-n', path]) != 0
+
+
+def _CheckDartFormat(input_api, output_api):
+  files = [
+      git_file.AbsoluteLocalPath()
+      for git_file in input_api.AffectedTextFiles()
+  ]
+  unformatted_files = [
+      path for path in files
+      if path.endswith('.dart') and _NeedsFormat(path)
+  ]
+  if unformatted_files:
+    escapedNewline = ' \\\n'
+    return [
+        output_api.PresubmitError(
+            'File output does not match dartfmt.\n'
+            'Fix these issues with:\n'
+            'dartfmt -w%s%s' %
+            (escapedNewline, escapedNewline.join(unformatted_files)))
+    ]
+  return []
+
+
+def CommonChecks(input_api, output_api):
+  return _CheckDartFormat(input_api, output_api)
+
+
+CheckChangeOnCommit = CommonChecks
+CheckChangeOnUpload = CommonChecks