atlantis: Github diff markdown formatting does not work properly for embedded YAML content

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave “+1” or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

Github diff markdown formatter (added with https://github.com/runatlantis/atlantis/pull/1751) does not work properly for embedded YAML content because it incorrectly treats hyphen - symbol, used to denote an array element in YAML, as diff removal.

Reproduction Steps

Example of Terraform code:

provider "aws" {
  region = "us-east-1"
}

data "template_file" "yaml_file" {
  template = <<EOT
array:
  - value1
  - value2
EOT
}

resource "aws_api_gateway_rest_api" "rest_api" {
  name        = "test"
  body        = data.template_file.yaml_file.rendered
  endpoint_configuration {
    types = ["REGIONAL"]
  }
}

GitHub comment created by Atlantis: image

GitHub comment source:

  # aws_api_gateway_rest_api.rest_api will be created
+   resource "aws_api_gateway_rest_api" "rest_api" {
+       api_key_source               = (known after apply)
+       arn                          = (known after apply)
+       binary_media_types           = (known after apply)
+       body                         = <<~EOT
            array:
-               value1
-               value2
        EOT
+       created_date                 = (known after apply)
+       description                  = (known after apply)
+       disable_execute_api_endpoint = (known after apply)
+       execution_arn                = (known after apply)
+       id                           = (known after apply)
+       minimum_compression_size     = -1
+       name                         = "test"
+       policy                       = (known after apply)
+       root_resource_id             = (known after apply)
+       tags_all                     = (known after apply)

+       endpoint_configuration {
+           types            = [
+               "REGIONAL",
            ]
+           vpc_endpoint_ids = (known after apply)
        }
    }

Logs

Not available.

Environment details

  • Atlantis version: 0.17.4
  • Atlantis flags:

ATLANTIS_ENABLE_DIFF_MARKDOWN_FORMAT=true

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 13
  • Comments: 17 (10 by maintainers)

Most upvoted comments

Does the github diff markdown work now for embedded YAML content ? @dyurovskykh-tivo @pauloconnor

you can send a PR if you think that is a better regex.

On Tue, Sep 27, 2022 at 12:25 AM Pepe (Jose) Amengual < @.***> wrote:

no idea, that was added a while ago

On Tue, Sep 27, 2022 at 12:12 AM Dmytro Yurovskykh < @.***> wrote:

Any idea why [ was added to the regex - https://github.com/runatlantis/atlantis/blob/master/server/events/models/models.go#L387 ?

If you drop it like:

  • diffKeywordRegex := regexp.MustCompile((?m)^( +)([-+~]\s)(.*)(\s=\s|\s->\s|<<|\{|\(known after apply\)|\[)(.*))+ diffKeywordRegex := regexp.MustCompile((?m)^( +)([-+~]\s)(.*)(\s=\s|\s->\s|<<|\{|\(known after apply\))(.*))

The diff becomes correct. Note: test TestRenderProjectResultsWithEnableDiffMarkdownFormat passes with ^ change too.

— Reply to this email directly, view it on GitHub https://github.com/runatlantis/atlantis/issues/1899#issuecomment-1259081485, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ3ERF6BGLOOW2OLCSYSKDWAKM7FANCNFSM5IB62SRA . You are receiving this because you were mentioned.Message ID: @.***>