Skip to content

Commit

Permalink
feat(sgterraform): do not comment plan if larger than gh supported size
Browse files Browse the repository at this point in the history
GitHub has a limit of 65536 characters in a comment so if the terraform
plan exceeded this size (due to too many resource changes for example),
only comment summary and point to CI logs for details
  • Loading branch information
alethenorio committed Aug 31, 2023
1 parent 2567b0f commit ecc447f
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions tools/sgterraform/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func CommentOnPRWithPlanSummarized(ctx context.Context, prNumber, environment, p
sg.Logger(ctx).Fatal(err)
}
statusIcon, summary := getCommentSummary(ctx, planFilePath)
comment := fmt.Sprintf(`
template := `
<div>
<img
align="right"
Expand All @@ -94,12 +94,29 @@ func CommentOnPRWithPlanSummarized(ctx context.Context, prNumber, environment, p
</p>
</details>
`,
`

comment := fmt.Sprintf(
template,
statusIcon,
environment,
statusIcon,
summary,
fmt.Sprintf("```"+"hcl\n%s\n"+"```", strings.TrimSpace(string(out))))
fmt.Sprintf("```"+"hcl\n%s\n"+"```", strings.TrimSpace(string(out))),
)

// GitHub has a limit on how many characters a message is allowed to have.
// If we are over that limit, make it visible for the user.
if len(comment) > 65536 {
comment = fmt.Sprintf(
template,
statusIcon,
environment,
statusIcon,
summary,
"```markdown\nPlan is too large to show in a GitHub comment. See CI logs for details\n```",
)
}
return sgghcomment.Command(
ctx,
"--pr",
Expand Down

0 comments on commit ecc447f

Please sign in to comment.