add-pr-comment
add-pr-comment copied to clipboard
Could ```message``` and ```message-path``` be combined
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.
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:
- Text Replacement 1
- 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 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.
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 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}}