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

Could message and message-path be combined #109

Open
Betristor opened this issue Sep 9, 2023 · 4 comments
Open

Could message and message-path be combined #109

Betristor opened this issue Sep 9, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@Betristor
Copy link

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.

@danielytics
Copy link

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.

@Betristor
Copy link
Author

@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.

@danielytics
Copy link

danielytics commented Sep 11, 2023

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.

@mshick
Copy link
Owner

mshick commented Feb 1, 2024

@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 mshick added the enhancement New feature or request label Feb 1, 2024
@mshick mshick self-assigned this Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

3 participants