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

Feature request: Delete prior comment and add new #110

Closed
selfagency opened this issue Apr 1, 2022 · 4 comments
Closed

Feature request: Delete prior comment and add new #110

selfagency opened this issue Apr 1, 2022 · 4 comments

Comments

@selfagency
Copy link

selfagency commented Apr 1, 2022

Thank you so much for making this extremely useful Action. It's been immensely helpful for my workflows. In my use case, I publish unit and E2E test results as comments to my team's PRs. However, I've noticed sometimes on PRs with a lot of commits or lengthy discussions that, due to their age, the comments produced using this Action get buried behind the following separator, and so when they are updated, those updates get lost.

CleanShot 2022-04-01 at 13 47 10

I was hoping you might consider adding a feature that, instead of updating the previous comment, will delete it and add a new comment entirely so that the latest updates always appear on screen.

Thank you!

@peter-evans
Copy link
Owner

Hi @selfagency

I'm not sure about adding that functionality into this action itself, but what you want to do is very easy to achieve anyway with one extra workflow step to delete the comment.

Change this to suit your use case, but something like this should work.

    - name: Find Comment
      uses: peter-evans/find-comment@v2
      id: fc
      with:
        issue-number: ${{ github.event.pull_request.number }}
        comment-author: 'github-actions[bot]'
        body-includes: Build output

    - if: steps.fc.outputs.comment-id != ''
      uses: actions/github-script@v6
      with:
        script: |
          github.rest.issues.deleteComment({
            owner: context.repo.owner,
            repo: context.repo.repo,
            comment_id: ${{ steps.fc.outputs.comment-id }}
          })

    - name: Create or update comment
      uses: peter-evans/create-or-update-comment@v2
      with:
        issue-number: ${{ github.event.pull_request.number }}
        body: |
          Build output
          ${{ steps.build.outputs.build-log }}

@selfagency
Copy link
Author

@peter-evans Thanks

@sumanth-lingappa
Copy link

Hello @peter-evans. Your GitHub action is awesome.
I have a similar question.
I am running bandit tool on every pull request. For some of the pull requests, there are more than one bandit reports.
How can I find ALL the comments and delete all of them?

@peter-evans
Copy link
Owner

Hi @sumanth-lingappa

I'm not aware of any easy way to do that. I think you'll need to do something similar to the example above, but inside the script input you'll need to loop through all the comments and delete the ones that match your condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants