GetTerminus / terraform-pr-commenter

A GitHub Action that adds opinionated comments to a PR from Terraform fmt/init/plan output
MIT License
28 stars 17 forks source link

Unhandled error with jq: error (at <stdin>:4): Cannot index string with string "body" #36

Open evertonspader-tomtom opened 5 months ago

evertonspader-tomtom commented 5 months ago

It seems there is an issue with an unhandled error:

INFO: Found no tfplan file. Using input argument.
INFO: Found 1 page(s) of comments at https://api.github.com/repos/<org>/<repo>/issues/236/comments?per_page=100.
INFO: Looking for an existing plan PR comment.
jq: error (at <stdin>:4): Cannot index string with string "body"
INFO: No existing plan PR comment found.

This is what I am using:

- name: "Generate PR comment from Terraform Plan"
  id: terraform-plan-pr
  uses: GetTerminus/terraform-pr-commenter@v3
  with:
    commenter_type: plan
    commenter_input: ${{ format('{0}{1}', steps.terraform-plan.outputs.stdout, steps.terraform-plan.outputs.stderr) }}
    commenter_exitcode: ${{ steps.terraform-plan.outputs.exitcode }}

From the releases I see that there has not been much activity in this repository but I hope this issue can be addressed

piotr-tokaj commented 4 months ago

I have the same issue, with exactly the following error:

INFO: Found no tfplan file. Using input argument.
INFO: Found 1 page(s) of comments at https://api.github.com/repos/<org>/<repo>/issues/18/comments?per_page=100.
INFO: Looking for an existing plan PR comment.
jq: error (at <stdin>:5): Cannot index string with string "body"
INFO: No existing plan PR comment found.
INFO: Found 1 page(s) of comments at https://api.github.com/repos/<org>/<repo>/issues/18/comments?per_page=100.
INFO: Looking for an existing outputs PR comment.
jq: error (at <stdin>:5): Cannot index string with string "body"
INFO: No existing outputs PR comment found.
INFO: Writing 1 plan comment(s)
INFO: Adding plan comment to PR.
INFO: Writing 0 outputs comment(s)
CpuID commented 4 months ago

Getting the same here

CpuID commented 4 months ago

Fairly sure it's something to do with this line (matches the line number and its calling jq): https://github.com/GetTerminus/terraform-pr-commenter/blob/master/utilities/comment_utility.sh#L5

CpuID commented 4 months ago

I think I solved this - was permissions related potentially on my secrets.GITHUB_TOKEN token.

piotr-tokaj commented 4 months ago

I think I solved this - was permissions related potentially on my secrets.GITHUB_TOKEN token.

@CpuID What exactly did you change?

piotr-tokaj commented 4 months ago

Ok you're right, I needed to make sure I have

permissions:
  pull-requests: 'write'

It seems to be granted by default, but I was overriding the permissions in the workflow for another reason, and this step was missing the ability to read or write PR comments