@@ -28,6 +28,8 @@ import (
2828 "unicode/utf8"
2929
3030 "github.com/shurcooL/githubv4"
31+
32+ "github.com/pipe-cd/pipecd/pkg/model"
3133)
3234
3335type PlanPreviewResult struct {
@@ -47,9 +49,13 @@ func (r *PlanPreviewResult) NoChange() bool {
4749type ApplicationResult struct {
4850 ApplicationInfo
4951 SyncStrategy string // QUICK_SYNC, PIPELINE
50- PlanSummary string
51- PlanDetails string
52- NoChange bool
52+ // Deprecated: Use PluginPlanResults in pipedv1
53+ PlanSummary string
54+ // Deprecated: Use PluginPlanResults in pipedv1
55+ PlanDetails string
56+ NoChange bool
57+
58+ PluginPlanResults []* model.PluginPlanPreviewResult
5359}
5460
5561type FailurePiped struct {
@@ -59,8 +65,11 @@ type FailurePiped struct {
5965
6066type FailureApplication struct {
6167 ApplicationInfo
62- Reason string
68+ Reason string
69+ // Deprecated: Use PluginPlanResults in pipedv1
6370 PlanDetails string
71+
72+ PluginPlanResults []* model.PluginPlanPreviewResult
6473}
6574
6675type PipedInfo struct {
@@ -69,12 +78,16 @@ type PipedInfo struct {
6978}
7079
7180type ApplicationInfo struct {
72- ApplicationID string
73- ApplicationName string
74- ApplicationURL string
75- Env string
81+ ApplicationID string
82+ ApplicationName string
83+ ApplicationURL string
84+ Env string
85+ // Deprecated: Use PluginNames in pipedv1
7686 ApplicationKind string // KUBERNETES, TERRAFORM, CLOUDRUN, LAMBDA, ECS
7787 ApplicationDirectory string
88+
89+ PlannedPluginNames string
90+ AllPluginNames string
7891}
7992
8093func retrievePlanPreview (
@@ -133,12 +146,14 @@ const (
133146 failureBadgeURL = `[](https://pipecd.dev/docs/user-guide/plan-preview/)`
134147 actionBadgeURLFormat = "[](%s)"
135148
136- noChangeTitleFormat = "Ran plan-preview against head commit %s of this pull request. PipeCD detected `0` updated application. It means no deployment will be triggered once this pull request got merged.\n "
137- hasChangeTitleFormat = "Ran plan-preview against head commit %s of this pull request. PipeCD detected `%d` updated applications and here are their plan results. Once this pull request got merged their deployments will be triggered to run as these estimations.\n "
138- detailsFormat = "<details>\n <summary>Details (Click me)</summary>\n <p>\n \n ``` %s\n %s\n ```\n </p>\n </details>\n \n "
139- detailsOmittedMessage = "The details are too long to display. Please check the actions log to see full details."
140- appInfoWithEnvFormat = "app: [%s](%s), env: %s, kind: %s"
141- appInfoWithoutEnvFormat = "app: [%s](%s), kind: %s"
149+ noChangeTitleFormat = "Ran plan-preview against head commit %s of this pull request. PipeCD detected `0` updated application. It means no deployment will be triggered once this pull request got merged.\n "
150+ hasChangeTitleFormat = "Ran plan-preview against head commit %s of this pull request. PipeCD detected `%d` updated applications and here are their plan results. Once this pull request got merged their deployments will be triggered to run as these estimations.\n "
151+ detailsFormat = "<details>\n <summary>Details (Click me)</summary>\n <p>\n \n ``` %s\n %s\n ```\n </p>\n </details>\n \n "
152+ detailsOmittedMessage = "The details are too long to display. Please check the actions log to see full details."
153+ appInfoWithEnvFormat = "app: [%s](%s), env: %s, kind: %s"
154+ appInfoWithoutEnvFormat = "app: [%s](%s), kind: %s"
155+ appInfoWithEnvFormatV1 = "app: [%s](%s), env: %s, planned plugin(s): %s"
156+ appInfoWithoutEnvFormatV1 = "app: [%s](%s), planned plugin(s): %s"
142157
143158 ghMessageLenLimit = 65536
144159
@@ -196,30 +211,67 @@ func makeCommentBody(event *githubEvent, r *PlanPreviewResult, title string) str
196211 for _ , app := range changedApps {
197212 fmt .Fprintf (& b , "### %s\n " , makeTitleText (& app .ApplicationInfo ))
198213 fmt .Fprintf (& b , "Sync strategy: %s\n " , app .SyncStrategy )
199- fmt .Fprintf (& b , "Summary: %s\n \n " , app .PlanSummary )
200-
201- var (
202- lang = "diff"
203- details = app .PlanDetails
204- )
205- if app .ApplicationKind == "TERRAFORM" {
206- lang = "hcl"
207- if shortened , err := generateTerraformShortPlanDetails (details ); err == nil {
208- details = shortened
214+
215+ if app .AllPluginNames == "" {
216+ // pipedv0
217+ fmt .Fprintf (& b , "Summary: %s\n \n " , app .PlanSummary )
218+ var (
219+ lang = "diff"
220+ details = app .PlanDetails
221+ )
222+ if app .ApplicationKind == "TERRAFORM" {
223+ lang = "hcl"
224+ if shortened , err := generateTerraformShortPlanDetails (details ); err == nil {
225+ details = shortened
226+ }
209227 }
210- }
211228
212- l := utf8 .RuneCountInString (details )
213- if detailLen + l > detailsLenLimit {
214- fmt .Fprintf (& b , detailsFormat , lang , detailsOmittedMessage )
215- detailLen += utf8 .RuneCountInString (detailsOmittedMessage )
216- continue
217- }
229+ l := utf8 .RuneCountInString (details )
230+ if detailLen + l > detailsLenLimit {
231+ fmt .Fprintf (& b , detailsFormat , lang , detailsOmittedMessage )
232+ detailLen += utf8 .RuneCountInString (detailsOmittedMessage )
233+ continue
234+ }
218235
219- if l > 0 {
220- detailLen += l
221- fmt .Fprintf (& b , detailsFormat , lang , details )
236+ if l > 0 {
237+ detailLen += l
238+ fmt .Fprintf (& b , detailsFormat , lang , details )
239+ }
240+ } else {
241+ // pipedv1
242+ fmt .Fprintf (& b , " Plugin(s): %s\n " , app .AllPluginNames )
243+ fmt .Fprintf (& b , " Summary:\n " )
244+ for _ , ppr := range app .PluginPlanResults {
245+ fmt .Fprintf (& b , " - %s(%s): %s\n " , ppr .PluginName , ppr .DeployTarget , ppr .PlanSummary )
246+ }
247+ fmt .Fprint (& b , " Details:\n " )
248+ for _ , ppr := range app .PluginPlanResults {
249+ fmt .Fprintf (& b , " - %s(%s):\n " , ppr .PluginName , ppr .DeployTarget )
250+
251+ details := string (ppr .PlanDetails )
252+ switch ppr .DiffLanguage {
253+ case "" :
254+ ppr .DiffLanguage = "diff" // Use diff by default
255+ case "hcl" :
256+ if shortened , err := generateTerraformShortPlanDetails (details ); err == nil {
257+ details = shortened
258+ }
259+ }
260+
261+ l := utf8 .RuneCountInString (details )
262+ if detailLen + l > detailsLenLimit {
263+ fmt .Fprintf (& b , detailsFormat , ppr .DiffLanguage , detailsOmittedMessage )
264+ detailLen += utf8 .RuneCountInString (detailsOmittedMessage )
265+ continue
266+ }
267+
268+ if l > 0 {
269+ detailLen += l
270+ fmt .Fprintf (& b , detailsFormat , ppr .DiffLanguage , details )
271+ }
272+ }
222273 }
274+
223275 }
224276
225277 if len (pipelineApps )+ len (quickSyncApps ) > 0 {
@@ -253,13 +305,24 @@ func makeCommentBody(event *githubEvent, r *PlanPreviewResult, title string) str
253305 fmt .Fprintf (& b , "\n ### %s\n " , makeTitleText (& app .ApplicationInfo ))
254306 fmt .Fprintf (& b , "Reason: %s\n \n " , app .Reason )
255307
256- var lang = "diff"
257- if app .ApplicationKind == "TERRAFORM" {
258- lang = "hcl"
259- }
260-
261- if len (app .PlanDetails ) > 0 {
262- fmt .Fprintf (& b , detailsFormat , lang , app .PlanDetails )
308+ if app .AllPluginNames == "" {
309+ // pipedv0
310+ var lang = "diff"
311+ if app .ApplicationKind == "TERRAFORM" {
312+ lang = "hcl"
313+ }
314+
315+ if len (app .PlanDetails ) > 0 {
316+ fmt .Fprintf (& b , detailsFormat , lang , app .PlanDetails )
317+ }
318+ } else {
319+ // pipedv1
320+ for _ , ppr := range app .PluginPlanResults {
321+ fmt .Fprintf (& b , " - %s(%s):\n " , ppr .PluginName , ppr .DeployTarget )
322+ if len (ppr .PlanDetails ) > 0 {
323+ fmt .Fprintf (& b , detailsFormat , ppr .DiffLanguage , ppr .PlanDetails )
324+ }
325+ }
263326 }
264327 }
265328 }
@@ -311,10 +374,19 @@ func makeActionLogURL() string {
311374}
312375
313376func makeTitleText (app * ApplicationInfo ) string {
314- if app .Env == "" {
315- return fmt .Sprintf (appInfoWithoutEnvFormat , app .ApplicationName , app .ApplicationURL , strings .ToLower (app .ApplicationKind ))
377+ if app .AllPluginNames == "" {
378+ // pipedv0
379+ if app .Env == "" {
380+ return fmt .Sprintf (appInfoWithoutEnvFormat , app .ApplicationName , app .ApplicationURL , strings .ToLower (app .ApplicationKind ))
381+ }
382+ return fmt .Sprintf (appInfoWithEnvFormat , app .ApplicationName , app .ApplicationURL , app .Env , strings .ToLower (app .ApplicationKind ))
383+ } else {
384+ // pipedv1
385+ if app .Env == "" {
386+ return fmt .Sprintf (appInfoWithoutEnvFormatV1 , app .ApplicationName , app .ApplicationURL , app .PlannedPluginNames )
387+ }
388+ return fmt .Sprintf (appInfoWithEnvFormatV1 , app .ApplicationName , app .ApplicationURL , app .Env , app .PlannedPluginNames )
316389 }
317- return fmt .Sprintf (appInfoWithEnvFormat , app .ApplicationName , app .ApplicationURL , app .Env , strings .ToLower (app .ApplicationKind ))
318390}
319391
320392func generateTerraformShortPlanDetails (details string ) (string , error ) {
0 commit comments