-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance: Add --format=json flag option to comment commands (#2874)
* enhance: Add --format=json flag option to comment commands * fix: copy+paste error * test: update golden files
- Loading branch information
Showing
10 changed files
with
101 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,18 @@ import ( | |
) | ||
|
||
type CommentOutput struct { | ||
Body string | ||
HasDiff bool | ||
ValidAt *time.Time | ||
Body string | ||
HasDiff bool | ||
ValidAt *time.Time | ||
AddRunResponse apiclient.AddRunResponse | ||
} | ||
|
||
var ( | ||
validCommentOutputFormats = []string{ | ||
"json", | ||
} | ||
) | ||
|
||
func commentCmd(ctx *config.RunContext) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "comment", | ||
|
@@ -84,6 +91,7 @@ func buildCommentOutput(cmd *cobra.Command, ctx *config.RunContext, paths []stri | |
var additionalCommentData string | ||
var governanceFailures output.GovernanceFailures | ||
dryRun, _ := cmd.Flags().GetBool("dry-run") | ||
var result apiclient.AddRunResponse | ||
if ctx.IsCloudUploadEnabled() && !dryRun { | ||
if ctx.Config.IsSelfHosted() { | ||
ui.PrintWarning(cmd.ErrOrStderr(), "Infracost Cloud is part of Infracost's hosted services. Contact [email protected] for help.") | ||
|
@@ -93,7 +101,7 @@ func buildCommentOutput(cmd *cobra.Command, ctx *config.RunContext, paths []stri | |
if mdOpts.BasicSyntax { | ||
commentFormat = apiclient.CommentFormatMarkdown | ||
} | ||
result := shareCombinedRun(ctx, combined, inputs, commentFormat) | ||
result = shareCombinedRun(ctx, combined, inputs, commentFormat) | ||
combined.RunID, combined.ShareURL, combined.CloudURL, governanceFailures = result.RunID, result.ShareURL, result.CloudURL, result.GovernanceFailures | ||
additionalCommentData = result.GovernanceComment | ||
} | ||
|
@@ -139,9 +147,10 @@ func buildCommentOutput(cmd *cobra.Command, ctx *config.RunContext, paths []stri | |
ctx.ContextValues.SetValue("originalLength", md.OriginalMsgSize) | ||
|
||
out := &CommentOutput{ | ||
Body: string(b), | ||
HasDiff: combined.HasDiff(), | ||
ValidAt: &combined.TimeGenerated, | ||
Body: string(b), | ||
HasDiff: combined.HasDiff(), | ||
ValidAt: &combined.TimeGenerated, | ||
AddRunResponse: result, | ||
} | ||
|
||
if policyChecks.HasFailed() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters