Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only highlight Terraform changes on GitHub #2337

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions server/events/markdown_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2173,13 +2173,42 @@ Terraform will perform the following actions:
id = "redacted_redacted.redacted.redacted.io_A"
name = "redacted.redacted.redacted.io"
~ records = [
"foo",
- "redacted",
] -> (known after apply)
ttl = 300
type = "A"
zone_id = "redacted"
}

# helm_release.external_dns[0] will be updated in-place
~ resource "helm_release" "external_dns" {
id = "external-dns"
name = "external-dns"
~ values = [
- <<-EOT
image:
tag: "0.12.0"
pullSecrets:
- XXXXX

domainFilters: ["xxxxx","xxxxx"]
base64:
+dGhpcyBpcyBzb21lIHN0cmluZyBvciBzb21ldGhpbmcKCg==
EOT,
+ <<-EOT
image:
tag: "0.12.0"
pullSecrets:
- XXXXX

domainFilters: ["xxxxx","xxxxx"]
base64:
+dGhpcyBpcyBzb21lIHN0cmluZyBvciBzb21ldGhpbmcKCg==
EOT,
]
}

Plan: 1 to add, 1 to change, 1 to destroy.
`
cases := []struct {
Expand Down Expand Up @@ -2308,13 +2337,42 @@ Terraform will perform the following actions:
id = "redacted_redacted.redacted.redacted.io_A"
name = "redacted.redacted.redacted.io"
! records = [
"foo",
- "redacted",
] -> (known after apply)
ttl = 300
type = "A"
zone_id = "redacted"
}

# helm_release.external_dns[0] will be updated in-place
! resource "helm_release" "external_dns" {
id = "external-dns"
name = "external-dns"
! values = [
- <<-EOT
image:
tag: "0.12.0"
pullSecrets:
- XXXXX

domainFilters: ["xxxxx","xxxxx"]
base64:
+dGhpcyBpcyBzb21lIHN0cmluZyBvciBzb21ldGhpbmcKCg==
EOT,
+ <<-EOT
image:
tag: "0.12.0"
pullSecrets:
- XXXXX

domainFilters: ["xxxxx","xxxxx"]
base64:
+dGhpcyBpcyBzb21lIHN0cmluZyBvciBzb21ldGhpbmcKCg==
EOT,
]
}

Plan: 1 to add, 1 to change, 1 to destroy.

$$$
Expand Down
6 changes: 4 additions & 2 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,12 @@ func (p *PlanSuccess) Summary() string {

// DiffMarkdownFormattedTerraformOutput formats the Terraform output to match diff markdown format
func (p PlanSuccess) DiffMarkdownFormattedTerraformOutput() string {
diffKeywordRegex := regexp.MustCompile(`(?m)^( +)([-+~])`)
diffKeywordRegex := regexp.MustCompile(`(?m)^( +)([-+~]\s)(.*)(\s->\s|<<|\{|\(known after apply\)|\[)(.*)`)
diffListRegex := regexp.MustCompile(`(?m)^( +)([-+~]\s)(".*",)`)
diffTildeRegex := regexp.MustCompile(`(?m)^~`)

formattedTerraformOutput := diffKeywordRegex.ReplaceAllString(p.TerraformOutput, "$2$1")
formattedTerraformOutput := diffKeywordRegex.ReplaceAllString(p.TerraformOutput, "$2$1$3$4$5")
formattedTerraformOutput = diffListRegex.ReplaceAllString(formattedTerraformOutput, "$2$1$3")
formattedTerraformOutput = diffTildeRegex.ReplaceAllString(formattedTerraformOutput, "!")

return formattedTerraformOutput
Expand Down