Discord has a webhook limit of 2k chars
This commit is contained in:
+19
-6
@@ -135,12 +135,25 @@ def main():
|
||||
except ValueError as e:
|
||||
sys.stderr.write(f"Error calculating 2-week fallback date: {e}\n")
|
||||
|
||||
for i in issues:
|
||||
line = "* {name} (#{id})".format(name=i["title"], id=i["id"])
|
||||
# print to stdout (captured by workflow)
|
||||
print(line)
|
||||
# log to stderr (visible in build logs)
|
||||
debug(f"Outputting: {line}")
|
||||
# Discord limit is 2000. We reserve 300 chars for the header/mentions in the YAML.
|
||||
MAX_CHARS = 1700
|
||||
current_length = 0
|
||||
|
||||
for index, i in enumerate(issues):
|
||||
line = "* {name} (#{id})".format(name=i["title"], id=i["id"])
|
||||
line_len = len(line) + 1 # +1 for the newline character
|
||||
|
||||
# Check if adding this line would exceed the limit
|
||||
if current_length + line_len > MAX_CHARS:
|
||||
remaining = len(issues) - index
|
||||
truncation_msg = f"\n... (and {remaining} more issues truncated)"
|
||||
print(truncation_msg)
|
||||
debug(f"Truncating output. Hit character limit. {remaining} issues hidden.")
|
||||
break
|
||||
|
||||
print(line)
|
||||
current_length += line_len
|
||||
debug(f"Outputting: {line}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user