github format: Update output to utilize groups

Resolves #421

Update the github formatting to utilize groups in the output and provide
the line/column number for the error in the output log.
pull/431/head
Trevor Royer 3 years ago committed by GitHub
parent 7246a0c800
commit d0392b34ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -553,11 +553,13 @@ class CommandLineTestCase(unittest.TestCase):
with RunContext(self) as ctx: with RunContext(self) as ctx:
cli.run((path, '--format', 'github')) cli.run((path, '--format', 'github'))
expected_out = ( expected_out = (
'::error file=%s,line=2,col=4::[trailing-spaces] trailing' '::group::%s\n'
'::error file=%s,line=2,col=4::2:4 [trailing-spaces] trailing'
' spaces\n' ' spaces\n'
'::error file=%s,line=3,col=4::[new-line-at-end-of-file] no' '::error file=%s,line=3,col=4::3:4 [new-line-at-end-of-file] no'
' new line character at the end of file\n' ' new line character at the end of file\n'
% (path, path)) '::endgroup::\n\n'
% (path, path, path))
self.assertEqual( self.assertEqual(
(ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, '')) (ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, ''))
@ -571,11 +573,13 @@ class CommandLineTestCase(unittest.TestCase):
os.environ['GITHUB_WORKFLOW'] = 'something' os.environ['GITHUB_WORKFLOW'] = 'something'
cli.run((path, )) cli.run((path, ))
expected_out = ( expected_out = (
'::error file=%s,line=2,col=4::[trailing-spaces] trailing' '::group::%s\n'
'::error file=%s,line=2,col=4::2:4 [trailing-spaces] trailing'
' spaces\n' ' spaces\n'
'::error file=%s,line=3,col=4::[new-line-at-end-of-file] no' '::error file=%s,line=3,col=4::3:4 [new-line-at-end-of-file] no'
' new line character at the end of file\n' ' new line character at the end of file\n'
% (path, path)) '::endgroup::\n\n'
% (path, path, path))
self.assertEqual( self.assertEqual(
(ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, '')) (ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, ''))

@ -93,6 +93,10 @@ class Format(object):
line += 'line=' + format(problem.line) + ',' line += 'line=' + format(problem.line) + ','
line += 'col=' + format(problem.column) line += 'col=' + format(problem.column)
line += '::' line += '::'
line += format(problem.line)
line += ':'
line += format(problem.column)
line += ' '
if problem.rule: if problem.rule:
line += '[' + problem.rule + '] ' line += '[' + problem.rule + '] '
line += problem.desc line += problem.desc
@ -117,6 +121,9 @@ def show_problems(problems, file, args_format, no_warn):
if args_format == 'parsable': if args_format == 'parsable':
print(Format.parsable(problem, file)) print(Format.parsable(problem, file))
elif args_format == 'github': elif args_format == 'github':
if first:
print('::group::%s' % file)
first = False
print(Format.github(problem, file)) print(Format.github(problem, file))
elif args_format == 'colored': elif args_format == 'colored':
if first: if first:
@ -129,6 +136,9 @@ def show_problems(problems, file, args_format, no_warn):
first = False first = False
print(Format.standard(problem, file)) print(Format.standard(problem, file))
if not first and args_format == 'github':
print('::endgroup::')
if not first and args_format != 'parsable': if not first and args_format != 'parsable':
print('') print('')

Loading…
Cancel
Save