cmd/watchflakes: truncate very large issue body text

postComment has automatic truncation of very long text for comments,
but GitHub's limit on issue comment length applies to issue bodies too.
This means watchflakes will sometimes error out on issue creation with:

	graphql error: Body is too long (maximum is 65536 characters)

Fix that by applying the same behavior in postNew as well.

For golang/go#70743.

Change-Id: I477ec0138320855c83864a9f639dfc77151fa55a
Reviewed-on: https://go-review.googlesource.com/c/build/+/724501
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
diff --git a/cmd/watchflakes/github.go b/cmd/watchflakes/github.go
index 35b400d..ba8216f 100644
--- a/cmd/watchflakes/github.go
+++ b/cmd/watchflakes/github.go
@@ -295,7 +295,6 @@
 	fmt.Fprintf(&b, "Found new dashboard test flakes for:\n\n%s", indent(spaces[:4], issue.ScriptText))
 	for _, f := range issue.Post {
 		b.WriteString("\n")
-		_ = f
 		b.WriteString(f.Markdown())
 	}
 	return b.String()
@@ -397,7 +396,7 @@
 // postNew creates a new issue with the given title and body,
 // setting the NeedsInvestigation label and placing the issue in
 // the Test Flakes project.
-// It automatically adds signature to the body.
+// It automatically caps issue body length and adds signature to it.
 func postNew(title, body string) *github.Issue {
 	var args []any
 	if lab := labels["NeedsInvestigation"]; lab != nil {
@@ -405,6 +404,10 @@
 	}
 	args = append(args, testFlakes)
 
+	if len(body) > 50000 {
+		// As of 2025-11-27, GitHub GraphQL API limits body length to 65536.
+		body = body[:50000] + "\n</details>\n(... long body truncated ...)\n"
+	}
 	issue, err := gh.CreateIssue(repo, title, body+signature, args...)
 	if err != nil {
 		log.Fatal(err)
@@ -431,16 +434,11 @@
 }
 
 // postComment posts a new comment on the issue.
-// It automatically adds signature to the comment.
+// It automatically caps comment body length and adds signature to it.
 func postComment(issue *Issue, body string) error {
-	if len(body) > 50000 {
-		// Apparently GitHub GraphQL API limits comment length to 65536.
-		body = body[:50000] + "\n</details>\n(... long comment truncated ...)\n"
-	}
 	if issue.Issue.Closed {
 		reopen := false
 		for _, p := range issue.Post {
-			_ = p
 			if p.Time.After(issue.ClosedAt) {
 				reopen = true
 				break
@@ -452,5 +450,9 @@
 			}
 		}
 	}
+	if len(body) > 50000 {
+		// As of 2025-11-27, GitHub GraphQL API limits comment length to 65536.
+		body = body[:50000] + "\n</details>\n(... long comment truncated ...)\n"
+	}
 	return gh.AddIssueComment(issue.Issue, body+signature)
 }