Skip to content

Commit

Permalink
Truncate logs longer than 9000 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjoe committed Jul 6, 2019
1 parent 5dc53b6 commit fd9ea14
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lintipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ def __call__(self, event, context):
version = self.get_cmd_version()
code, log = self.run_process(code_path)

output = "```\n%s\n%s\n```" % (version, log)
if len(log) > 9000:
output = "```\n%s\n%s\nFull output truncated. Please run locally see full output.\n```" % (
version, log[:9000]
)
else:
output = "```\n%s\n%s\n```" % (version, log)

if code == 0:
self.update_check_run(
Expand Down
27 changes: 25 additions & 2 deletions tests/test_lintipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
from botocore.vendored import requests

from lintipy import CheckRun, TIMED_OUT
from lintipy import CheckRun, TIMED_OUT, FAILURE

BASE_DIR = Path(os.path.dirname(__file__))

Expand Down Expand Up @@ -111,7 +111,7 @@ def test_timeout(self, handler, caplog):
handler.download_code = lambda: '.'
with pytest.raises(subprocess.TimeoutExpired) as e:
handler(handler.event, {})
assert "timed out after 1 seconds" in str(e)
assert "timed out after 1 seconds" in str(e.value)

def test_installation_id(self, handler):
assert handler.installation_id == 234
Expand All @@ -138,6 +138,29 @@ def update_check_run(status, summary, conclusion=None):
assert data['conclusion'] == TIMED_OUT
assert data['summary'] == 'Downloading code timed out after 1e-10s'

def test_summary_cut(self, handler):
httpretty.register_uri(
httpretty.PATCH, handler.check_run_url,
data='',
status=200,
content_type='application/json',
)


data = {}

def update_check_run(status, summary, conclusion=None):
data['status'] = status
data['summary'] = summary
data['conclusion'] = conclusion

handler.update_check_run = update_check_run
handler.download_code = lambda: '.'
handler.run_process = lambda x: (1, str(list(range(9999))))
handler(handler.event, {})
assert data['conclusion'] == FAILURE
assert data['summary'][9889:] == '\nFull output truncated. Please run locally see full output.\n```'

def test_get_cmd_version(self, handler):
handler.cmd = 'pytest'
version_log = handler.get_cmd_version()
Expand Down

0 comments on commit fd9ea14

Please sign in to comment.