Skip to content

Conversation

@nghialv
Copy link
Member

@nghialv nghialv commented Jun 30, 2021

What this PR does / why we need it:

This PR updates pipectl to make its plan-preview command renders the results to both stdout and a given file.
This also adds the needed fields to the PlanPreview's models.

Which issue(s) this PR fixes:

Fixes #2109

Does this PR introduce a user-facing change?:

NONE

@pipecd-bot
Copy link
Collaborator

GO_LINTER

The following files are not gofmt-ed. By commenting /golinter fmt, the formatted one will be appended to this pull request automatically.

pkg/app/pipectl/cmd/planpreview/planpreview_test.go
--- pkg/app/pipectl/cmd/planpreview/planpreview_test.go.orig
+++ pkg/app/pipectl/cmd/planpreview/planpreview_test.go
@@ -39,12 +39,12 @@
 		{
 			name: "there is only a plannable application",
 			results: []*model.PlanPreviewCommandResult{
-				&model.PlanPreviewCommandResult{
+				{
 					CommandId: "command-2",
 					PipedId:   "piped-2",
 					PipedUrl:  "https://pipecd.dev/piped-2",
 					Results: []*model.ApplicationPlanPreviewResult{
-						&model.ApplicationPlanPreviewResult{
+						{
 							ApplicationId:   "app-1",
 							ApplicationName: "app-1",
 							ApplicationUrl:  "https://pipecd.dev/app-1",
@@ -67,12 +67,12 @@
 		{
 			name: "there is only a failure application",
 			results: []*model.PlanPreviewCommandResult{
-				&model.PlanPreviewCommandResult{
+				{
 					CommandId: "command-2",
 					PipedId:   "piped-2",
 					PipedUrl:  "https://pipecd.dev/piped-2",
 					Results: []*model.ApplicationPlanPreviewResult{
-						&model.ApplicationPlanPreviewResult{
+						{
 							ApplicationId:   "app-2",
 							ApplicationName: "app-2",
 							ApplicationUrl:  "https://pipecd.dev/app-2",
@@ -93,7 +93,7 @@
 		{
 			name: "there is only a failure piped",
 			results: []*model.PlanPreviewCommandResult{
-				&model.PlanPreviewCommandResult{
+				{
 					CommandId: "command-1",
 					PipedId:   "piped-1",
 					PipedUrl:  "https://pipecd.dev/piped-1",
@@ -110,18 +110,18 @@
 		{
 			name: "all kinds",
 			results: []*model.PlanPreviewCommandResult{
-				&model.PlanPreviewCommandResult{
+				{
 					CommandId: "command-1",
 					PipedId:   "piped-1",
 					PipedUrl:  "https://pipecd.dev/piped-1",
 					Error:     "failed to clone",
 				},
-				&model.PlanPreviewCommandResult{
+				{
 					CommandId: "command-2",
 					PipedId:   "piped-2",
 					PipedUrl:  "https://pipecd.dev/piped-2",
 					Results: []*model.ApplicationPlanPreviewResult{
-						&model.ApplicationPlanPreviewResult{
+						{
 							ApplicationId:   "app-1",
 							ApplicationName: "app-1",
 							ApplicationUrl:  "https://pipecd.dev/app-1",
@@ -130,7 +130,7 @@
 							SyncStrategy:    model.SyncStrategy_QUICK_SYNC,
 							Changes:         []byte("changes-1"),
 						},
-						&model.ApplicationPlanPreviewResult{
+						{
 							ApplicationId:   "app-2",
 							ApplicationName: "app-2",
 							ApplicationUrl:  "https://pipecd.dev/app-2",
@@ -139,7 +139,7 @@
 							SyncStrategy:    model.SyncStrategy_PIPELINE,
 							Changes:         []byte("changes-2"),
 						},
-						&model.ApplicationPlanPreviewResult{
+						{
 							ApplicationId:   "app-3",
 							ApplicationName: "app-3",
 							ApplicationUrl:  "https://pipecd.dev/app-3",
@@ -147,7 +147,7 @@
 							EnvName:         "env-3",
 							Error:           "wrong application configuration",
 						},
-						&model.ApplicationPlanPreviewResult{
+						{
 							ApplicationId:   "app-4",
 							ApplicationName: "app-4",
 							ApplicationUrl:  "https://pipecd.dev/app-4",
@@ -157,7 +157,7 @@
 						},
 					},
 				},
-				&model.PlanPreviewCommandResult{
+				{
 					CommandId: "command-3",
 					PipedId:   "piped-3",
 					PipedUrl:  "https://pipecd.dev/piped-3",

Copy link
Collaborator

@pipecd-bot pipecd-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GO_LINTER

Some issues were detected while linting go source files in your changes.

@nghialv
Copy link
Member Author

nghialv commented Jun 30, 2021

/golinter fmt

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.64%. This pull request increases coverage by 0.08%.

File Function Base Head Diff
pkg/app/pipectl/cmd/planpreview/planpreview.go NewCommand -- 0.00% +0.00%
pkg/app/pipectl/cmd/planpreview/planpreview.go command.run -- 0.00% +0.00%
pkg/app/pipectl/cmd/planpreview/planpreview.go printResults -- 44.44% +44.44%
pkg/app/pipectl/cmd/planpreview/planpreview.go convert -- 100.00% +100.00%
pkg/app/pipectl/cmd/planpreview/planpreview.go ReadableResult.String -- 100.00% +100.00%
pkg/model/application.go MakeApplicationURL -- 0.00% +0.00%
pkg/model/environment.go MakeEnvironmentURL -- 0.00% +0.00%
pkg/model/piped.go MakePipedURL -- 0.00% +0.00%
pkg/model/planpreview.go PlanPreviewCommandResult.FillURLs -- 0.00% +0.00%
pkg/app/api/grpcapi/api.go API.GetPlanPreviewResults 0.00% 0.00% +0.00%
pkg/app/piped/planpreview/builder.go builder.Build 0.00% 0.00% +0.00%

@pipecd-bot pipecd-bot added size/XL and removed size/L labels Jun 30, 2021
@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.61%. This pull request increases coverage by 0.05%.

File Function Base Head Diff
pkg/app/pipectl/cmd/planpreview/planpreview.go NewCommand -- 0.00% +0.00%
pkg/app/pipectl/cmd/planpreview/planpreview.go command.run -- 0.00% +0.00%
pkg/app/pipectl/cmd/planpreview/planpreview.go printResults -- 44.44% +44.44%
pkg/app/pipectl/cmd/planpreview/planpreview.go convert -- 100.00% +100.00%
pkg/app/pipectl/cmd/planpreview/planpreview.go ReadableResult.String -- 100.00% +100.00%
pkg/model/application.go MakeApplicationURL -- 0.00% +0.00%
pkg/model/environment.go MakeEnvironmentURL -- 0.00% +0.00%
pkg/model/piped.go MakePipedURL -- 0.00% +0.00%
pkg/model/planpreview.go PlanPreviewCommandResult.FillURLs -- 0.00% +0.00%
pkg/app/api/grpcapi/api.go API.GetPlanPreviewResults 0.00% 0.00% +0.00%
pkg/app/piped/planpreview/builder.go builder.Build 0.00% 0.00% +0.00%

// All URL fields inside the result model are empty.
// So we fill them before sending to the client.
for _, r := range results {
r.FillURLs(a.webBaseURL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I thought putting this inside right after the loop is enough (like you did before commit 😄 ). But if you intend to be more clear, it's on you

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will keep this as it is because there are 2 loops (L480, L512) that are updating this list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true 👍

@pipecd-bot
Copy link
Collaborator

GO_LINTER

The golinter build is completed with FAILURE. The build will be triggered again when you push any other commits. Or you can trigger it manually by /golinter trigger command right now.

You can check the build log from here.

@pipecd-bot
Copy link
Collaborator

COVERAGE

Code coverage for golang is 32.61%. This pull request increases coverage by 0.05%.

File Function Base Head Diff
pkg/app/pipectl/cmd/planpreview/planpreview.go NewCommand -- 0.00% +0.00%
pkg/app/pipectl/cmd/planpreview/planpreview.go command.run -- 0.00% +0.00%
pkg/app/pipectl/cmd/planpreview/planpreview.go printResults -- 44.44% +44.44%
pkg/app/pipectl/cmd/planpreview/planpreview.go convert -- 100.00% +100.00%
pkg/app/pipectl/cmd/planpreview/planpreview.go ReadableResult.String -- 100.00% +100.00%
pkg/model/application.go MakeApplicationURL -- 0.00% +0.00%
pkg/model/environment.go MakeEnvironmentURL -- 0.00% +0.00%
pkg/model/piped.go MakePipedURL -- 0.00% +0.00%
pkg/model/planpreview.go PlanPreviewCommandResult.FillURLs -- 0.00% +0.00%
pkg/app/api/grpcapi/api.go API.GetPlanPreviewResults 0.00% 0.00% +0.00%
pkg/app/piped/planpreview/builder.go builder.Build 0.00% 0.00% +0.00%

@nakabonne
Copy link
Member

excellent!
/lgtm

@khanhtc1202
Copy link
Member

Way to go 🚀
/approve

@pipecd-bot
Copy link
Collaborator

APPROVE

This pull request is APPROVED by khanhtc1202.

Approvers can cancel the approval by writing /approve cancel in a comment. Any additional commits also will change this pull request to be not-approved.

@pipecd-bot pipecd-bot merged commit c769d7c into master Jun 30, 2021
@pipecd-bot pipecd-bot deleted the plan-preview branch June 30, 2021 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Format preview results and support writing the result into file.

5 participants