1
0
Fork 0

only posting non-empty comments

This commit is contained in:
Christian Kühnel 2019-11-18 16:22:43 +01:00
parent c96a2d158c
commit db831d4c0e

View file

@ -83,19 +83,27 @@ class PhabTalk:
def _comment_on_diff_from_file(self, diff: str, text_file_path: str, test_results: TestResults): def _comment_on_diff_from_file(self, diff: str, text_file_path: str, test_results: TestResults):
"""Comment on a diff, read text from file.""" """Comment on a diff, read text from file."""
header = 'Build result: {} - '.format(test_results.result_type) header = ''
header += '{} tests passed, {} failed and {} were skipped.\n'.format( if test_results.result_type is not None:
test_results.test_stats['pass'], header = 'Build result: {} - '.format(test_results.result_type)
test_results.test_stats['fail'], header += '{} tests passed, {} failed and {} were skipped.\n'.format(
test_results.test_stats['skip'], test_results.test_stats['pass'],
) test_results.test_stats['fail'],
for test_case in test_results.unit: test_results.test_stats['skip'],
if test_case['result'] == 'fail': )
header += ' failed: {}/{}\n'.format(test_case['namespace'], test_case['name']) for test_case in test_results.unit:
if test_case['result'] == 'fail':
header += ' failed: {}/{}\n'.format(test_case['namespace'], test_case['name'])
text = '' text = ''
if text_file_path is not None and os.path.exists(text_file_path): if text_file_path is not None and os.path.exists(text_file_path):
with open(text_file_path) as input_file: with open(text_file_path) as input_file:
text = input_file.read() text = input_file.read()
if len(header+text) == 0:
print('Comment for Phabricator would be empty. Not posting it.')
return
self._comment_on_diff(diff, header + text) self._comment_on_diff(diff, header + text)
def _report_test_results(self, phid: str, test_results: TestResults): def _report_test_results(self, phid: str, test_results: TestResults):
@ -120,11 +128,11 @@ class PhabTalk:
if build_result_file is None: if build_result_file is None:
# If no result file is specified: assume this is intentional # If no result file is specified: assume this is intentional
result.result_type = 'pass' result.result_type = None
return result return result
if not os.path.exists(build_result_file): if not os.path.exists(build_result_file):
print('Warning: Could not find test results file: {}'.format(build_result_file)) print('Warning: Could not find test results file: {}'.format(build_result_file))
result.result_type = 'pass' result.result_type = None
return result return result
root_node = etree.parse(build_result_file) root_node = etree.parse(build_result_file)