Does such an action exist?

I have a Repository where I store various JSON files in it and now look for a way to display the newly added lines as a PR comment.

The JSON always has the same structure and a summary.json exists that essentially contains all other JSON files as a large array.

Is there an action that would allow me to get the newly added info of the updated summary.json to then display as a table?

For example, when I would add the following lines to the file…

[
// Previous entries...
  {
    "title": "some title",
    "description": "Lorum ipsum",
    "values": [
      "value1",
      "value2"
    ]
  }
]

would it result in a comment like this for the PR:

This Pull request would add the following information. Please check it for possible typos!

Title Description Values
some title Lorum ipsum value1, value2

Most things relating to JSON can be managed by jq.

Offhand, it sounds like you’d want to check out the base version of the file to one place, the head version to another, and then ask jq for the difference. It’d be a fairly simple workflow.

Personally, as long as you aren’t actually dealing w/ Lorem Ipsum text (n.b. not Lorum), have you considered a spell checker? (Technically w/ some effort someone could provide a Latin dictionary or a Lorem-Ipsum dictionary, but I don’t currently have one…)

Plug:

Spell-checking isn’t my main concern here. All I want is list the different keys and values added to a json file as a table in a comment for easier reading of what was changed.

Right, I figured, jq is definitely the answer, but I’d expect you’d need to write it yourself.

Maybe I’m missing something but isn’t this basically what a Pull Request diff is all about? you can also preview the diff which will present the markdown representation of it.

1 Like

I’m pretty sure they’re imagining wanting a human friendly content aware diff as opposed to a generic line oriented diff.

Maybe they’re not aware that this is possible in the diff preview. It’s literally a couple of clicks away and already built-in to GitHub with no additional setup.

1 Like

I am well aware of the diff feature, but this is not something about pull requests affecting markdown files

I stated it more than clear enough that my setup is about JSON files and that I would like to visualize the newly added entries of the PR as a markdown formatted comment.

Like when a PR adds

  {
    "key": "value",
    "description": "Some description",
    "array": [
      "entry1",
      "entry2"
    ]
  }

to a JSON file would I like a GH Action to take that added JSON and display it as a table showing the different values next to each other (Refer to my initial comment for the overall design)

This was never about displaying markdown in a diff.

1 Like

Gotcha. I’m not aware of any GitHub action like that, but definitely worth searching the actions marketplace: https://github.com/marketplace?type=actions

You could build your own pull_request_target workflow to check things out, diff with jq, then add a PR comment with a table containing the details.

Always be very careful when using pull_request_target. Speaking as someone who has been seriously bitten by it.

Here’s a pinned version of a workflow that uses pull_request_target and arranges to make a comment:

Note that only the comment (and update – which you wouldn’t need in this case) has:

    permissions:
      contents: write

For more information on permissions: