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

Create works but update doesn't? #364

Closed
PureKrome opened this issue Nov 1, 2024 · 3 comments
Closed

Create works but update doesn't? #364

PureKrome opened this issue Nov 1, 2024 · 3 comments

Comments

@PureKrome
Copy link

PureKrome commented Nov 1, 2024

Hi there 👋🏻

I'm testing this GH Action out and I can't seem to Update an existing comment which this Action created. It keeps creating the a new comment each time.

The content of the comment is from a markdown file -> code coverage results. These are usually dynamic with each PR-commit that is pushed up.

I'm guessing this might be because it cannot find the hidden html comment? my markdown content overrides it?

Suggestion: New Action inputs

Name Description Info
secret-key A secret piece of HTML text that is prepended to any content. This is an HTML Comment secret-html-hidden-value (which ends up becoming <!-- secret-html-hidden-value -->

example:

- name: Create or Update PR Comment
    uses: peter-evans/create-or-update-comment@v4
    with:
        issue-number: ${{ github.event.pull_request.number }}
        secret-key: i-am-your-father
        body-file: code-coverage-results.md
        edit-mode: replace

I don't care what that value is. it's just something which should NOT be part of my markdown file or the body text/content i manually provide.

This means we wouldn't have use your find-comment action.

Maybe the default is empty string so nothing is pre-pended? and if the value is provided then it is pre-pended and wrapped in the <!-- --> html comment element.

@peter-evans
Copy link
Owner

Hi @PureKrome

I'm guessing this might be because it cannot find the hidden html comment? my markdown content overrides it?

I think find-comment should be able to find that. It's just searching the text of the comment body. The markdown rendering should have nothing to do with it. If you show me your workflow and perhaps a log of the run we might be able to work out why it doesn't work for you.

@PureKrome
Copy link
Author

👋🏻 Hi @peter-evans - thanks heaps for prompt reply. Legend!

Here's my existing workflow:

- name: Create or Update PR Comment
    uses: peter-evans/create-or-update-comment@v4
    with:
        issue-number: ${{ github.event.pull_request.number }}
        body-file: code-coverage-results.md
        edit-mode: replace

So there's nothing crazy here.

I'm not using find-comment. What I was hoping was that I didn't need to use that action but this action could do the replace automatically and that was why I was thinking "how would it know to replace" and this is because it is looking for that secret html which this action can auto add into the comment.

@peter-evans
Copy link
Owner

@PureKrome edit-mode: replace only works if you supply a comment-id, otherwise the action assumes that you want to make a new comment.

It's deliberate that the functionality of find-comment is separate in a different action. I believe that actions work best when they are small, composable units that do one thing well. It allows them to be used in many different use cases, and just makes them more maintainable - just like code functions.

So if you want replace behaviour, please use find-comment as described in the example here: https://github.com/peter-evans/create-or-update-comment?#where-to-find-the-id-of-a-comment

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

2 participants