add-pr-comment icon indicating copy to clipboard operation
add-pr-comment copied to clipboard

Could ```message``` and ```message-path``` be combined

Open Betristor opened this issue 1 year ago • 4 comments

I got a question about the composition of the message. Could we combine usage of message and message-path to form a new message. Like, a template is posed in message and then some dynamic message is posed in the file. By doing so, we could generate more complex message as comment.

Betristor avatar Sep 09 '23 09:09 Betristor

You can do this right now by using multiple steps, for example:

on:
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - uses: mshick/add-pr-comment@v2
        with:
          message: |
            1. <<update1>>
            2. <<update2>>
      - uses: mshick/add-pr-comment@v2
        with:
          find: <<update1>>
          replace: Text Replacement 1
      - uses: mshick/add-pr-comment@v2
        with:
          find: <<update2>>
          replace: Text Replacement 2

results in the message:

  1. Text Replacement 1
  2. Text Replacement 2

As shown in https://github.com/mshick/add-pr-comment#find-and-replace you can also use message-path instead of replace for the replacement text, if you wish to take it from a file.

danielytics avatar Sep 10 '23 19:09 danielytics

@danielytics Thanks! So multi steps won't create multi comments. And actually we could use placeholder and then replace them with find & replace function. That's fantastic.

Betristor avatar Sep 11 '23 05:09 Betristor

You can use allow-repeats and message-id to control whether each step creates a new message or updates an old one. By default, it will update like in my example.

You can of course also use failure and success messages (or just if on steps) to conditionally update using find.

danielytics avatar Sep 11 '23 10:09 danielytics

@danielytics Thanks for the inventive solution!

I also think this is a reasonable feature to add. I might approach it as follows, supporting the custom tokens to figure out where to stick the file contents.

What do you think?

      - uses: mshick/add-pr-comment@v2
        with:
          message-path: |
             './path/to/file1.txt'
             './path/to/file2.txt'
          message: |
            1. {{MESSAGE_1}}
            2. {{MESSAGE_2}}

mshick avatar Feb 01 '24 19:02 mshick