@@ -2,8 +2,10 @@ package github
2
2
3
3
import (
4
4
"context"
5
- "github.com/mercari/tfnotify/terraform"
6
5
"net/http"
6
+ "unicode/utf8"
7
+
8
+ "github.com/mercari/tfnotify/terraform"
7
9
)
8
10
9
11
// NotifyService handles communication with the notification related
@@ -70,7 +72,7 @@ func (g *NotifyService) Notify(body string) (exit int, err error) {
70
72
Link : cfg .CI ,
71
73
UseRawOutput : cfg .UseRawOutput ,
72
74
})
73
- body , err = template . Execute ( )
75
+ body , err = templateExecute ( template )
74
76
if err != nil {
75
77
return result .ExitCode , err
76
78
}
@@ -113,7 +115,7 @@ func (g *NotifyService) notifyDestroyWarning(body string, result terraform.Parse
113
115
Link : cfg .CI ,
114
116
UseRawOutput : cfg .UseRawOutput ,
115
117
})
116
- body , err := destroyWarningTemplate . Execute ( )
118
+ body , err := templateExecute ( destroyWarningTemplate )
117
119
if err != nil {
118
120
return err
119
121
}
@@ -144,3 +146,20 @@ func (g *NotifyService) removeResultLabels() error {
144
146
145
147
return nil
146
148
}
149
+
150
+ func templateExecute (template terraform.Template ) (string , error ) {
151
+ body , err := template .Execute ()
152
+ if err != nil {
153
+ return "" , err
154
+ }
155
+
156
+ if utf8 .RuneCountInString (body ) <= 65536 {
157
+ return body , nil
158
+ }
159
+
160
+ templateValues := template .GetValue ()
161
+ templateValues .Body = "Body is too long. Please check the CI result."
162
+
163
+ template .SetValue (templateValues )
164
+ return template .Execute ()
165
+ }
0 commit comments