runbot/runbot_merge/utils.py
Xavier Morel 42046cb21c [IMP] runbot_merge: logging on github requests failures
Github is subject to a fair amount of transient failures, which are
currently ill-logged: an exception is raised and the caller /
responsible might eventually log something, but it's not really
formalised and centralised, and is thus inconvenient to try and
post-mortem issues with github's support.

Change this such that *almost* all github API calls get extensively
logged (status, reason, all headers, body) on failure.

Also automatically sets debug logging for odoo in local tests, and
alter the fake response constructor thing so it doesn't set a json
mimetype when the body is not valid json.

Closes #98
2019-03-01 16:42:57 +01:00

17 lines
554 B
Python

# -*- coding: utf-8 -*-
def shorten(text_ish, length):
""" If necessary, cuts-off the text or bytes input and appends ellipsis to
signal the cutoff, such that the result is below the provided length
(according to whatever "len" means on the text-ish so bytes or codepoints
or code units).
"""
if len(text_ish or ()) <= length:
return text_ish
cont = '...'
if isinstance(text_ish, bytes):
cont = cont.encode('ascii') # whatever
# add enough room for the ellipsis
return text_ish[:length-3] + cont