Aaron leventhal | 6719bb73 | 2025-08-06 23:36:53 | [diff] [blame] | 1 | # Copyright 2025 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. |
| 4 | |
| 5 | """A PRESUBMIT script to prevent direct edits to cached documentation.""" |
| 6 | |
| 7 | PRESUBMIT_VERSION = '2.0.0' |
| 8 | |
| 9 | def CheckChangeOnUpload(input_api, output_api): |
| 10 | """ |
| 11 | Checks that no cached documents in this directory are manually edited. |
| 12 | """ |
| 13 | results = [] |
| 14 | protected_dir = input_api.PresubmitLocalPath() |
| 15 | |
| 16 | # A list of files within this directory that are allowed to be edited. |
| 17 | allowed_to_edit = [ |
| 18 | input_api.os_path.join(protected_dir, 'readme.md'), |
| 19 | input_api.os_path.join(protected_dir, 'refresh_docs.py'), |
| 20 | input_api.os_path.join(protected_dir, 'PRESUBMIT.py'), |
| 21 | ] |
| 22 | |
| 23 | for f in input_api.AffectedFiles(): |
| 24 | # Check if the file is inside this directory, but is not one of the |
| 25 | # allowed files. |
| 26 | if (f.LocalPath().startswith(protected_dir) and |
| 27 | f.LocalPath() not in allowed_to_edit): |
| 28 | results.append( |
| 29 | output_api.PresubmitError( |
| 30 | f'Direct edits to cached documents are not allowed.\n' |
| 31 | f'Found modification in: {f.LocalPath()}\n' |
| 32 | f'To update these docs, please modify and run the ' |
| 33 | f'refresh_docs.py script.')) |
| 34 | |
| 35 | return results |