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

Github diff markdown formatting does not work properly for embedded YAML content #1899

Closed
dyurovskykh-tivo opened this issue Nov 15, 2021 · 17 comments
Labels
bug Something isn't working waiting-on-response Waiting for a response from the user

Comments

@dyurovskykh-tivo
Copy link

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 #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

@dyurovskykh-tivo dyurovskykh-tivo added the bug Something isn't working label Nov 15, 2021
@jamengual
Copy link
Contributor

is this still happening with v0.19.8?

@jamengual jamengual added the waiting-on-response Waiting for a response from the user label Aug 26, 2022
@dyurovskykh-tivo
Copy link
Author

Hello, @jamengual,

Diff looks much better with v0.19.8 but there is still unexpected diff:
Screenshot from 2022-09-26 15:19:04

Thanks!

@jamengual
Copy link
Contributor

are you using ? enable-diff-markdown-format: true

@dyurovskykh-tivo
Copy link
Author

Yes, we have env var ATLANTIS_ENABLE_DIFF_MARKDOWN_FORMAT set to true

@jamengual
Copy link
Contributor

this one is hard to fix since you could have anything on that yaml.

I think there is always going to be some discrepancies

@dyurovskykh-tivo
Copy link
Author

dyurovskykh-tivo commented Sep 27, 2022

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 (https://go.dev/play/p/uTH9ogZJcCe). Note: test TestRenderProjectResultsWithEnableDiffMarkdownFormat passes with ^ change too.

@jamengual
Copy link
Contributor

jamengual commented Sep 27, 2022 via email

@jamengual
Copy link
Contributor

jamengual commented Sep 27, 2022 via email

@dyurovskykh-tivo
Copy link
Author

Sure, I've asked an engineer from my team to work on the PR.

@jamengual
Copy link
Contributor

jamengual commented Sep 27, 2022 via email

@pauloconnor
Copy link
Contributor

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

I think I added it to catch situations where the change is like

+           types            = [
+               "REGIONAL",
            ]

so it'd catch the types = [ line. This whole regex is annoying. Wish Golang let us use lookaheads, though I understand why it doesn't

@dyurovskykh-tivo
Copy link
Author

@pauloconnor
Looks like this type of pattern works fine even without [ in the regex:
image
Result:
image

If you are aware of other patterns to be covered/tested, please, let @VladimirSt-XP know and he will try adding it to his #2551

@nitrocode
Copy link
Member

We probably need a test for the types = [] to ensure the regex handles it correctly.

It would help if we commented the regex too so each significant character has a reason for being there.

@nitrocode
Copy link
Member

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

@dyurovskykh-tivo
Copy link
Author

@nitrocode It should work for anything covered in tests but I am not sure it covers everything. Consider adding more tests to cover more use cases.

@nitrocode
Copy link
Member

nitrocode commented Nov 21, 2022

Sorry, my question was more for the lack of functionality described in the original post above and not the tests themselves.

Is the markdown formatting working properly now in the latest atlantis for embedded YAML? or should we keep this open? What are the other edge cases?

@dyurovskykh-tivo
Copy link
Author

ah, I think this should be fixed by #2551

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting-on-response Waiting for a response from the user
Projects
None yet
Development

No branches or pull requests

4 participants