Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | # Copyright 2016 The Chromium Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 4 | |
| 5 | """Presubmit script just for Monorail's SQL files.""" |
| 6 | from __future__ import print_function |
| 7 | from __future__ import division |
| 8 | from __future__ import absolute_import |
| 9 | |
| 10 | |
| 11 | def AlterTableCheck(input_api, output_api): # pragma: no cover |
| 12 | this_dir = input_api.PresubmitLocalPath() |
| 13 | sql_files = set(x for x in input_api.os_listdir(this_dir) |
| 14 | if (x.endswith('.sql') and x != 'queries.sql')) |
| 15 | log_file = input_api.os_path.join(this_dir, 'alter-table-log.txt') |
| 16 | affected_files = set(f.LocalPath() for f in input_api.AffectedTextFiles()) |
| 17 | |
| 18 | if (any(f in affected_files for f in sql_files) ^ |
| 19 | (log_file in affected_files)): |
| 20 | return [output_api.PresubmitPromptOrNotify( |
| 21 | 'It looks like you have modified the sql schema without updating\n' |
| 22 | 'the alter-table-log, or vice versa. Are you sure you want to do this?') |
| 23 | ] |
| 24 | return [] |
| 25 | |
| 26 | |
| 27 | def CheckChangeOnUpload(input_api, output_api): # pragma: no cover |
| 28 | output = AlterTableCheck(input_api, output_api) |
| 29 | return output |
| 30 | |
| 31 | |
| 32 | def CheckChangeOnCommit(input_api, output_api): # pragma: no cover |
| 33 | output = AlterTableCheck(input_api, output_api) |
| 34 | return output |