Skip to content

Commit

Permalink
fix: don't attempt to include super-long synth logs in a PR body
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuma authored Jul 30, 2020
1 parent 5936421 commit 0a8879a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions autosynth/change_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,21 @@ def build_pr_body(synth_log: str, trailers: str = ""):
build_log_text = ""
kokoro_build_id = os.environ.get("KOKORO_BUILD_ID")
if synth_log:
length_limit = 40000
if len(synth_log) > length_limit:
synth_log = "[LOG TRUNCATED]\n" + synth_log[-length_limit:]
build_log_text = f"""
<details><summary>Log from Synthtool</summary>
```
{synth_log}
```
</details>"""
if kokoro_build_id:
build_log_text += f"""
Full log will be available here:
https://source.cloud.google.com/results/invocations/{kokoro_build_id}/targets"""
elif kokoro_build_id:
build_log_text = f"""Synth log will be available here:
https://source.cloud.google.com/results/invocations/{kokoro_build_id}/targets"""
Expand Down
15 changes: 13 additions & 2 deletions tests/test_change_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,26 @@ def test_build_pr_body_with_kokoro_build_id():

def test_build_pr_body_with_synth_log_and_kokoro_build_id():
with util.ModifiedEnvironment({"KOKORO_BUILD_ID": "42"}):
# The synth log should override the kokoro build id.
synth_log = "A great pull request."
pr_body = build_pr_body(synth_log)
assert (
pr_body.find("https://source.cloud.google.com/results/invocations/42") == -1
pr_body.find("https://source.cloud.google.com/results/invocations/42") > -1
)
assert pr_body.find(synth_log) > -1


def test_build_pr_body_with_very_long_synth_log():
with util.ModifiedEnvironment({"KOKORO_BUILD_ID": "42"}):
synth_log = "abcdefghi\n" * 10000
pr_body = build_pr_body(synth_log)
assert (
pr_body.find("https://source.cloud.google.com/results/invocations/42") > -1
)
assert pr_body.find("abcdefghi") > -1
assert pr_body.find("[LOG TRUNCATED]") > -1
assert len(pr_body) < 60000


def test_build_pr_body_with_synth_trailers():
synth_log = "synth log"
pr_body = build_pr_body(synth_log, "a: b\nc: d")
Expand Down

0 comments on commit 0a8879a

Please sign in to comment.