Adding check for team and component tags in owners files.

As a part of presubmit, if an OWNERS file is modified or added the
following checks will be performed:

- Ensure that at most one line starts with `# COMPONENT: ` exists in the
  file.
- Ensure that at most one line starts with `# TEAM: ` exists in the
  file, and that it contains exactly one email address.

[email protected],[email protected],[email protected]
BUG=667954

Review-Url: https://codereview.chromium.org/2601773004
Cr-Commit-Position: refs/heads/master@{#441420}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 32a16e14..2677a4e4 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -751,6 +751,26 @@
         long_text=error.output)]
 
 
+def _CheckTeamTags(input_api, output_api):
+  """Checks that OWNERS files have consistent TEAM and COMPONENT tags."""
+  checkteamtags_tool = input_api.os_path.join(
+      input_api.PresubmitLocalPath(),
+      'tools', 'checkteamtags', 'checkteamtags.py')
+  args = [input_api.python_executable, checkteamtags_tool,
+          '--root', input_api.change.RepositoryRoot()]
+  files = [f.LocalPath() for f in input_api.AffectedFiles()
+           if input_api.os_path.basename(f.AbsoluteLocalPath()).upper() ==
+           'OWNERS']
+  try:
+    if files:
+      input_api.subprocess.check_output(args + files)
+    return []
+  except input_api.subprocess.CalledProcessError as error:
+    return [output_api.PresubmitError(
+        'checkteamtags.py failed:',
+        long_text=error.output)]
+
+
 def _CheckNoAuraWindowPropertyHInHeaders(input_api, output_api):
   """Makes sure we don't include ui/aura/window_property.h
   in header files.
@@ -2045,6 +2065,7 @@
   results.extend(_CheckNoTrinaryTrueFalse(input_api, output_api))
   results.extend(_CheckUnwantedDependencies(input_api, output_api))
   results.extend(_CheckFilePermissions(input_api, output_api))
+  results.extend(_CheckTeamTags(input_api, output_api))
   results.extend(_CheckNoAuraWindowPropertyHInHeaders(input_api, output_api))
   results.extend(_CheckIncludeOrder(input_api, output_api))
   results.extend(_CheckForVersionControlConflicts(input_api, output_api))