|
1 | 1 | from eventhandler import EventHandler
|
2 | 2 |
|
3 |
| -reftest_required_msg = 'These commits modify layout code, but no reftests are modified. Please consider adding a reftest!' |
| 3 | +TEST_REQUIRED_MSG = 'These commits modify {0} code, but no tests are modified. Please consider adding a test!' |
4 | 4 |
|
5 | 5 | class MissingTestHandler(EventHandler):
|
| 6 | + COMPONENT_DIRS_TO_CHECK = ('layout', 'script', 'gfx', 'style', 'net') |
| 7 | + TEST_DIRS_TO_CHECK = ('ref', 'wpt', 'unit') |
| 8 | + |
6 | 9 | def on_pr_opened(self, api, payload):
|
7 | 10 | diff = api.get_diff()
|
8 |
| - layout_changed = False |
| 11 | + components_changed = set() |
| 12 | + |
9 | 13 | for line in diff.split('\n'):
|
10 |
| - if line.startswith('diff --git') and line.find('components/layout/') > -1: |
11 |
| - layout_changed = True |
12 |
| - if line.startswith('diff --git') and \ |
13 |
| - (line.find('tests/ref') > -1 or line.find('tests/wpt') > -1): |
14 |
| - return |
15 |
| - |
16 |
| - if layout_changed: |
17 |
| - self.warn(reftest_required_msg) |
| 14 | + if line.startswith('diff --git'): |
| 15 | + for component in self.COMPONENT_DIRS_TO_CHECK: |
| 16 | + if 'components/{0}/'.format(component) in line: |
| 17 | + components_changed.add(component) |
| 18 | + |
| 19 | + for directory in self.TEST_DIRS_TO_CHECK: |
| 20 | + if 'tests/{0}'.format(directory) in line: |
| 21 | + return |
| 22 | + |
| 23 | + if components_changed: |
| 24 | + # Build a readable list of changed components |
| 25 | + if len(components_changed) == 1: |
| 26 | + components_msg = components_changed.pop() |
| 27 | + elif len(components_changed) == 2: |
| 28 | + components_msg = '{} and {}'.format(*components_changed) |
| 29 | + else: |
| 30 | + components_msg = ', '.join(components_changed) |
| 31 | + components_msg = ", and ".join(components_msg.rsplit(", ", 1)) |
| 32 | + |
| 33 | + self.warn(TEST_REQUIRED_MSG.format(components_msg)) |
18 | 34 |
|
19 | 35 |
|
20 | 36 | handler_interface = MissingTestHandler
|
0 commit comments