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,6 +83,8 @@ class PhabTalk:
def _comment_on_diff_from_file(self, diff: str, text_file_path: str, test_results: TestResults):
"""Comment on a diff, read text from file."""
header = ''
if test_results.result_type is not None:
header = 'Build result: {} - '.format(test_results.result_type)
header += '{} tests passed, {} failed and {} were skipped.\n'.format(
test_results.test_stats['pass'],
@ -92,10 +94,16 @@ class PhabTalk:
for test_case in test_results.unit:
if test_case['result'] == 'fail':
header += ' failed: {}/{}\n'.format(test_case['namespace'], test_case['name'])
text = ''
if text_file_path is not None and os.path.exists(text_file_path):
with open(text_file_path) as input_file:
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)
def _report_test_results(self, phid: str, test_results: TestResults):
@ -120,11 +128,11 @@ class PhabTalk:
if build_result_file is None:
# If no result file is specified: assume this is intentional
result.result_type = 'pass'
result.result_type = None
return result
if not os.path.exists(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
root_node = etree.parse(build_result_file)