GithubHelp home page GithubHelp logo

thollander / actions-comment-pull-request Goto Github PK

View Code? Open in Web Editor NEW
287.0 1.0 79.0 291 KB

GitHub action to comment pull request

License: MIT License

JavaScript 99.39% TypeScript 0.61%
actions github github-actions

actions-comment-pull-request's Introduction

Comment Pull Request - GitHub Actions

What is it ?

A GitHub action that comments with a given message the pull request linked to the pushed branch. You can even put dynamic data thanks to Contexts and expression syntax.

Usage

Classic usage

on: pull_request

jobs:
  example_comment_pr:
    runs-on: ubuntu-latest
    name: An example job to comment a PR
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Comment PR
        uses: thollander/actions-comment-pull-request@v2
        with:
          message: |
            Hello world ! :wave:

Comment a file content

Thanks to the filePath input, a file content can be commented. You can either pass an absolute filePath or a relative one that will be by default retrieved from GITHUB_WORKSPACE. (Note that if both a message and filePath are provided, message will take precedence.)

- name: PR comment with file
  uses: thollander/actions-comment-pull-request@v2
  with:
    filePath: /path/to/file.txt

Setting reactions

You can also set some reactions on your comments through the reactions input. It takes only valid reactions and adds it to the comment you've just created. (See https://docs.github.com/en/rest/reactions#reaction-types)

- name: PR comment with reactions
  uses: thollander/actions-comment-pull-request@v2
  with:
    message: |
      Hello world ! :wave:
    reactions: eyes, rocket

Specifying which pull request to comment on

You can explicitly input which pull request should be commented on by passing the pr_number input. That is particularly useful for manual workflow for instance (workflow_run).

...
- name: Comment PR
  uses: thollander/actions-comment-pull-request@v2
  with:
    message: |
      Hello world ! :wave:
    pr_number: 123 # This will comment on pull request #123

Update a comment

Editing an existing comment is also possible thanks to the comment_tag input.

Thanks to this parameter, it will be possible to identify your comment and then to upsert on it. If the comment is not found at first, it will create a new comment.

That is particularly interesting while committing multiple times in a PR and that you just want to have the last execution report printed. It avoids flooding the PR.

...
- name: Comment PR with execution number
  uses: thollander/actions-comment-pull-request@v2
  with:
    message: |
      _(execution **${{ github.run_id }}** / attempt **${{ github.run_attempt }}**)_
    comment_tag: execution

Note: the input mode can be used to either upsert (by default) or recreate the comment (= delete and create)

Delete a comment

Deleting an existing comment is also possible thanks to the comment_tag input combined with mode: delete.

This will delete the comment at the end of the job.

...
- name: Write a comment that will be deleted at the end of the job
  uses: thollander/actions-comment-pull-request@v2
  with:
    message: |
      The PR is being built...
    comment_tag: to_delete
    mode: delete

Inputs

Action inputs

Name Description Required Default
GITHUB_TOKEN Token that is used to create comments. Defaults to ${{ github.token }}
message Comment body
filePath Path of the file that should be commented
reactions List of reactions for the comment (comma separated). See https://docs.github.com/en/rest/reactions#reaction-types
pr_number The number of the pull request where to create the comment current pull-request/issue number (deduced from context)
comment_tag A tag on your comment that will be used to identify a comment in case of replacement
mode Mode that will be used to update comment (upsert/recreate/delete) upsert
create_if_not_exists Whether a comment should be created even if comment_tag is not found true

Outputs

Action outputs

You can get some outputs from this actions :

Name Description
id Comment id that was created or updated
body Comment body
html_url URL of the comment created or updated

Example output

- name: Comment PR
  uses: thollander/actions-comment-pull-request@v2
  id: hello
  with:
    message: |
      Hello world ! :wave:
- name: Check outputs
  run: |
    echo "id : ${{ steps.hello.outputs.id }}"
    echo "body : ${{ steps.hello.outputs.body }}"
    echo "html_url : ${{ steps.hello.outputs.html_url }}"

Permissions

Depending on the permissions granted to your token, you may lack some rights. To run successfully, this actions needs at least :

permissions: 
   pull-requests: write 

Add this in case you get Resource not accessible by integration error. See jobs.<job_id>.permissions for more information.

Note that, if the PR comes from a fork, it will have only read permission despite the permissions given in the action for the pull_request event. In this case, you may use the pull_request_target event. With this event, permissions can be given without issue (the difference is that it will execute the action from the target branch and not from the origin PR).

Contributing

Build

The build steps transpiles the src/main.ts to lib/index.js which is used in a NodeJS environment. It is handled by vercel/ncc compiler.

$ npm run build

actions-comment-pull-request's People

Contributors

dependabot[bot] avatar ericcornelissen avatar fehmianac avatar liyishuai avatar lukasz-mitka avatar moop-moop avatar thollander avatar tunetheweb avatar vinodsai-a avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

actions-comment-pull-request's Issues

Question: how to use a file content as comment messages on a PR?

Hi, I'm trying to auto generate comments for new PRs in my repository.

I found this action, it looks like the filePath option can help me do these things:

  • read the content from a file, for example: pr-template.md file (it has a markdown content, and it is complicated and cannot be directly put into this action as a message).
  • use the content from the file as a message.

Here's my pr.yml actions:

name: PR
on:
  pull_request: ~
  push:
    branches:
      - main
jobs:
  pr_comment:
    name: PR comment
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v4
    - name: ls -lha
      shell: bash
      run: |
          echo "ls -lha ."
          ls -lha .
    - name: PR Comment
      uses: thollander/actions-comment-pull-request@v2
      with:
        filePath: pr-template.md

But there's an error in my workflow:

https://github.com/linrongbin16/fzfx.nvim/actions/runs/6439036401/job/17486263012?pr=244

The error is:

Error: Resource not accessible by integration

image

Would you please help me?

[FEATURE] Add ability to delete and re-create current comment

Hello,
it will be good if possible to add the behaviour when the comment can be not just replaced, but removed and created again.

Sometimes with long commit history in feature branch it is not obvious is comment actual if one is somewhere on the top.
If we have ability to "move" comment to the last commit which "triggered" comment update it probably can be a little bit more obvious.

Any feedback is appreciated.

Populate an output variable with the input message

I want to use the message from the PR to populate the Github Job Summary as well. Ideally, the action should generate an output variable that I can use in later steps. It would be even better if this could include the URL of the comment as another variable.

Thanks for the library; it's really useful.

On `delete` mode new comment always will be created

Hello,
i have the situation when i change mode dynamically based on the result of another step, but on delete mode extra comment will be temporarily added all the time due to current logic.

I use this Action to add comment on PR in case if TFLinter finds some concerns based on exit code.
When TFLinter finds concern, the Action adds comment as it runs based on

      - name: 'Set comment PR mode'
        run: |
          if [ "${{ steps.tflint.outputs.exitcode }}" != "0" ]; then
            echo "pr_comment_mode=recreate" >> $GITHUB_ENV 
          else
            echo "pr_comment_mode=delete" >>  $GITHUB_ENV
          fi

      - name: 'Comment PR'
        if: ${{ steps.tflint.outputs.exitcode != '0' || env.pr_comment_mode == 'delete'}}
        uses: thollander/actions-comment-pull-request@v2
        with:
          message: |
            ## :microscope: TFLint validation
            ```shell
            ${{ steps.tflint.outputs.stdout || 'TFLint is running...' }}
            ```
          pr_number: ${{ github.event.pull_request.number }}
          mode: ${{ env.pr_comment_mode }}
          comment_tag: "tflint_comment"
          GITHUB_TOKEN: ${{ secrets.SOME_TOKEN }}

so, if there is any concerns it will be pr_comment_mode=recreate means comment will be added. Everything as expected.
When there is a new commit with changes, but still some concerns from TFLinter, comment will be recreated and Action works as expected.
But if all the TFLint concerns were fixed, then mentioned step sets pr_comment_mode=delete .
In this situation there is a small side effect as delete mode always creates comment. The thing is, there is a situation when it will be two PR comments from this Action, one created when it was TFLint concerns and the new extra short living comment as createComment function will be executed before post step which will remove both comments later.

It will be great if it can be avoided the creation of new intermediate PR comment when mode: delete in the situation I've described.

Maybe, it is kind of "new" mode (cleanup ?) when delete works just as delete, without creation of any comment before the deletion in the end during post step.

[Feature] Ability to specify a comment should NOT be created if its tag does not yet exist

I have a workflow that checks the codebase for the existence of some token, and then checks a file within the codebase for a baseline of that token. In some cases, the token is removed but the baseline remains, and we want to notify PR authors that they can remove the baseline. We do this with a comment:

      - name: Comment on PR
        uses: thollander/actions-comment-pull-request@c22fb302208b7b170d252a61a505d2ea27245eff #v2.0.0
        if: ${{ steps.check_for_useless_baselines.outputs.useless_baselines == 'true' }}
        with:
          message: Violations exist <tag>
          comment_tag: <tag>

I would love to be able to tell the author that they have resolved all the issues, which would be based on the following conditional in a separate step that looks much like the one above:

if: ${{ steps.check_for_useless_baselines.outputs.useless_baselines == 'false' }}

However, I don't want to post this comment unless the first one has been posted (i.e unless the author had previous violations in a past commit), and since my workflow can't know the state of previous runs, I feel it would need to be something like:

      - name: Comment on PR
        uses: thollander/actions-comment-pull-request@c22fb302208b7b170d252a61a505d2ea27245eff #v2.0.0
        if: ${{ steps.check_for_useless_baselines.outputs.useless_baselines == 'false' }}
        with:
          message: Violations fixed <tag>
          comment_tag: <tag>
          create_if_not_exists: false # defaults to true

The end result, when violations existed, would be:

  1. Comment indicating violations exist
  2. Comment indicating violations were resolved

The end result, when no violations existed, would be that no comments are posted.

incompatible with lockfileversion2

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
image

it works but takes about 10sec to comment whereas alternatives like mshick/add-pr-comment take less than a second.

Thollander's (11sec taken) Mshic's (0sec taken)
image image

Update a specific comment that was not created by this action?

Hello,

i'm interested in using this action, and i would like to use it to update a comment that was already created.

My use case is as follows:

  • user comment on a PR with a keyword
  • I trigger a workflow with issue_comment
  • I use https://github.com/Khan/pull-request-comment-trigger to verify the keyword, if the keyword matches, the workflow goes on
  • I would like to update the comment that triggered issue_comment by appending text to it

Is that something that would fall under the scope of this project, and you would be willing to add as a new feature?

Thanks

Get `pr_number` when triggered by `issue_comment`

I am using https://github.com/Khan/pull-request-comment-trigger with just on: issue_comment: types: [created] to trigger the Action when I write my command on the PR as a comment. I don't use pull_request: types: [opened] as I don't want it to mess up every PR with those checks.

However, I had this error:

image

I fixed it by adding this, as this guy said: actions/checkout#331 (comment)
pr_number: ${{ github.event.issue.number }}

So, I think this action should try to get this var if the current one isn't available to handle the issue_comment event.

Resource not accessible by integration

Not an expert on github actions, something obvious i'm missing?

In my github actions log:

Run thollander/[email protected]
  with:
    GITHUB_TOKEN: ***
    pr_number: 1
    filePath: /home/runner/work/llvm-project/llvm-project/clang-format.patch
    mode: upsert
    create_if_not_exists: true
Error: Resource not accessible by integration

the code:

    - name: Comment Pull Request
      uses: thollander/[email protected]
      with:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        pr_number: ${{github.event.number}}
        filePath: ${{ github.workspace }}/clang-format.patch

i seem to recall that the default github token has access to everything, is that not the case?

README update

It is great to see that you've moved to the main branch terminology!

Can you please update your README to reflect that? Thank you so much!

- name: Comment PR
  uses: thollander/actions-comment-pull-request@main

Delete a Comment Without Creating a New One

Desired functionality:

  1. Workflow runs, creating a comment with tag foo
  2. Workflow runs again, deletes the comment with tag foo

Current functionality

  1. Workflow runs, creating a comment with tag foo
  2. Workflow runs again, deletes the comment with tag foo
  3. New comment is created in deletion step
    a. Ideally, you would not have to create a new comment upon deletion of another comment

Here's an example workflow snippet

      - name: Post Comment
        uses: thollander/actions-comment-pull-request@v2
        with:
          message: |
            #### hello world
          comment_tag: foo
          mode: recreate

      - name: Delete Comment
        uses: thollander/actions-comment-pull-request@v2
        with:
          message: |
            #### Why do I need this to delete?
          comment_tag: foo
          mode: delete
          create_if_not_exists: false # thought this may fix it (it does not :/)

At the end of this, the Post Comment comment is deleted, but seemingly always replaced with a new comment that has the contents of the message in the Delete Comment step.

Ideally, there would be a way to delete an existing comment without creating a new one.

If there is a way to do this and I'm missing something here, please let me know

Thanks!

Update: seems this functionality may not be supported by GitHub: https://github.com/orgs/community/discussions/26256

Custom Pr_number after merge to master not working

Hello!

I have got simple workflow:

on:
  workflow_dispatch:
    inputs:
      action:
        required: true
        default: "deploy"
        type: choice
        options:
        - test1
        - test

  push:
    branches:
      - master

      - name: Comment to PR with action link 
        uses: thollander/actions-comment-pull-request@v2
        with:
          message: |
             Deploy Begins! Actions URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
          pr_number: ${{ github.event.pull_request.number }} 
          GITHUB_TOKEN: ${{ secrets.COMMENT_TOKEN }}

After merge to master, I need to post commit on PR, which was merged to master. In action log I see, that it's now pr_number env:


Run thollander/actions-comment-pull-request@v2
  with:
    message: Deploy Begins! Actions URL: https://github.com/*]
  
    GITHUB_TOKEN: ***
    mode: upsert
    create_if_not_exists: true
Error: No issue/pull request in input neither in current context.

Is any ideas, why pr_number did not set?

Thank you!

[v2.3.1] Resource not accessible by integration

First of all, thank you very much for developing such a useful and convenient Actions.

I was using v2.3.0 and it worked very well and helped me simplify some of my work. But just now, @dependabot opened a new pull request yusancky/AllUp-Satwiki#9 in my repository, which wants to upgrade this Actions to v2.3.1. However, the pull request did not pass the test and no comment was given - it failed in The comment gives an error.

Bump thollander/actions-comment-pull-request from 2.3.0 to 2.3.1 #43

Error: Resource not accessible by integration

Here's part of the workflow file. This workflow runs on Ubuntu-latest.

      - name: Preview on Pull Request
        if: ${{ github.event_name == 'pull_request' }}
        uses: thollander/[email protected]
        with:
          message: |
            # 预览
            ```go
            ${{ steps.fetch_make.outputs.ALLUP_CONTENT }}
            ```
            > **Note**
            > 上方的 wikitext 代码块因展示高亮便利而使用 Go 语言高亮器,敬请理解。
          reactions: eyes
          comment_tag: actions-wikitext-preview

Failure with NPM and stack overflow while building this action image

Today we started getting the following error during our workflows, not sure if this is an npm issue or the package-lock.json in this repo:

Build container for action use: '/home/runner/work/_actions/thollander/actions-comment-pull-request/master/Dockerfile'.
  /usr/bin/docker build -t 1e5c35:ad639c88d707402b8e5ba2e8e25386b6 -f "/home/runner/work/_actions/thollander/actions-comment-pull-request/master/Dockerfile" "/home/runner/work/_actions/thollander/actions-comment-pull-request/master"
  Sending build context to Docker daemon  36.35kB
  
  Step 1/4 : FROM node:slim
  slim: Pulling from library/node
  babf97a3f00a: Pulling fs layer
  d81eb1809d95: Pulling fs layer
  54b0718e1fd5: Pulling fs layer
  9f80bf52a6c0: Pulling fs layer
  28724063fd29: Pulling fs layer
  9f80bf52a6c0: Waiting
  28724063fd29: Waiting
  d81eb1809d95: Verifying Checksum
  d81eb1809d95: Download complete
  9f80bf52a6c0: Verifying Checksum
  9f80bf52a6c0: Download complete
  babf97a3f00a: Verifying Checksum
  babf97a3f00a: Download complete
  28724063fd29: Verifying Checksum
  28724063fd29: Download complete
  54b0718e1fd5: Verifying Checksum
  54b0718e1fd5: Download complete
  babf97a3f00a: Pull complete
  d81eb1809d95: Pull complete
  54b0718e1fd5: Pull complete
  9f80bf52a6c0: Pull complete
  28724063fd29: Pull complete
  Digest: sha256:a39f2854f7fc02c8636c11227ca2d6680bd46a2173168650928b69cc03dffb1c
  Status: Downloaded newer image for node:slim
   ---> 2870b8b46426
  Step 2/4 : COPY . .
   ---> e1de5efdbd73
  Step 3/4 : RUN npm install --production
   ---> Running in 5263be933aac
  npm notice 
  npm notice New patch version of npm available! 7.0.2 -> 7.0.3
  npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
  npm notice Run `npm install -g [email protected]` to update!
  npm notice 
  npm ERR! Maximum call stack size exceeded
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-10-22T19_01_38_190Z-debug.log
  The command '/bin/sh -c npm install --production' returned a non-zero code: 1
  
  Warning: Docker build failed with exit code 1, back off 2.14 seconds before retry.
  /usr/bin/docker build -t 1e5c35:ad639c88d707402b8e5ba2e8e25386b6 -f "/home/runner/work/_actions/thollander/actions-comment-pull-request/master/Dockerfile" "/home/runner/work/_actions/thollander/actions-comment-pull-request/master"
  Sending build context to Docker daemon  36.35kB
  
  Step 1/4 : FROM node:slim
   ---> 2870b8b46426
  Step 2/4 : COPY . .
   ---> Using cache
   ---> e1de5efdbd73
  Step 3/4 : RUN npm install --production
   ---> Running in 8e917ec8efea
  npm notice 
  npm notice New patch version of npm available! 7.0.2 -> 7.0.3
  npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
  npm notice Run `npm install -g [email protected]` to update!
  npm notice 
  npm ERR! Maximum call stack size exceeded
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-10-22T19_01_41_950Z-debug.log
  The command '/bin/sh -c npm install --production' returned a non-zero code: 1
  
  Warning: Docker build failed with exit code 1, back off 7.085 seconds before retry.
  /usr/bin/docker build -t 1e5c35:ad639c88d707402b8e5ba2e8e25386b6 -f "/home/runner/work/_actions/thollander/actions-comment-pull-request/master/Dockerfile" "/home/runner/work/_actions/thollander/actions-comment-pull-request/master"
  Sending build context to Docker daemon  36.35kB
  
  Step 1/4 : FROM node:slim
   ---> 2870b8b46426
  Step 2/4 : COPY . .
   ---> Using cache
   ---> e1de5efdbd73
  Step 3/4 : RUN npm install --production
   ---> Running in 9362d4ee85ea
  npm notice 
  npm notice New patch version of npm available! 7.0.2 -> 7.0.3
  npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.0.3>
  npm notice Run `npm install -g [email protected]` to update!
  npm notice 
  npm ERR! Maximum call stack size exceeded
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /root/.npm/_logs/2020-10-22T19_01_50_702Z-debug.log
  The command '/bin/sh -c npm install --production' returned a non-zero code: 1
  
Error: Docker build failed with exit code 1

How to link to a file created in previous step of a github action?

I am running pytest like this in one of the steps:
pytest --html=test_rounding_results/report.html -s --capture=tee-sys test_rounding.py
So this test is triggered if there is a pull request. It stores the report.html in the test_rounding_results folder. However this is just part of the workspace runner (and is later uploaded as an artifact).
Is it possible to link to this file somehow from the pull request comment created by the github-bot?
Alternatively, is it possible for the action to "commit" the file and then link to it?

On pull_request_target information

Hi! I only want to explain my problem and the solution, to see if it can be documented in the project and help to others.

I was stuck with the error Resource not accessible by integration and adding the write permission as explained in the readme of your project didn't work. Looking at the GitHub documentation, when the PR comes from a fork, it will have only read permission despite the permissions given in the action for the pull_request event.

The solution was to use the pull_request_target event. With this event, I can give write permissions without problem. The difference is that it will execute the action from the "target" branch and not from the origin PR. But this is usually good for the major part of projects.

This is my code change, if you want to look at it: betaflight/betaflight#12851

Maybe this information can be added to the readme to help others like me.

Regards and thanks for your project! It's very useful.

Can I use this action to comment on PRs coming from a fork?

Hi,

Thanks for this action!

I have been able to use the action to comment on PRs coming from a fork (thanks for documenting the pull_request_target event).

I my comment I would need to use the fork repository, not the target.

Do you know what I could use to get the equivalent for ${{ github.repository }} on the fork? After I switched to pull_request_target, that variable became the target repository...

https://github.com/mwouts/jupytext/blob/main/.github/workflows/step_comment-pr.yml#L26

Thanks !

Comment content from a file

I'd like to be able to populate comment body with a content of a file.

Example use case:

  • publish test coverage results

Available workarounds:

  • use some env variable as a proxy.

What's the license of the project?

Hello, I'd like to use the action provided by your project but I'd first like to confirm the license.
Can you please clarify by creating a LICENSE file containing the license terms? A MIT license would be great for me.

Issue interpolating multiline outputs into the comment

Hi!

I'm currently trying to add a comment to a PR with the results of an end-to-end snapshot test. The results are generated in a prior step and I interpolate the step's output into the message field of this action, but am struggling to get the comment to keep its multilined formatting.

Here is a minimal reproduction of my workflow:

name: snapshot test
on: pull_request
jobs:
  api-regression-test:
    runs-on: ubuntu-latest
    steps:
      # [...steps to generate json snapshots and install the jd diffing utility]
      - name: Diff snapshot against canonical
        id: diff
        run: |
          # I've verified in CI that this output is being saved with multiple lines
          # I have also tried the >> $GITHUB_ENV method in referenced the github docs, with the same results
          SNAPSHOT_DIFF=$(jd current.json canonical.json)
          SNAPSHOT_DIFF="${SNAPSHOT_DIFF//'%'/'%25'}"
          SNAPSHOT_DIFF="${SNAPSHOT_DIFF//$'\n'/'%0A'}"
          SNAPSHOT_DIFF="${SNAPSHOT_DIFF//$'\r'/'%0D'}"
          echo "snapshot-diff=$SNAPSHOT_DIFF" >> $GITHUB_OUTPUT
      - name: Comment diff onto PR
        uses: thollander/actions-comment-pull-request@v2
        with:
          message: |
            ```diff
            [...some metadata about diff]
            ${{ steps.diff.outputs.snapshot-diff }}
            ```

And here is the output that I get:

[...some metadata about diff]
@ ["loc1","loc2",loc3]%0A- {"key1":{"key2": "val1"}}%0A @ ["loc1","loc2",loc3]%0A- {"key1":{"key2": "val1"}}

Converting \n characters to '%0A', as I'm doing in the diff step, is required to get outputs to not collapse onto one line. It also seems like @actions/core does this under the hood, as well.

But, the PR comment is outputting %0A where a newline should be. I'm not sure how to go about deserialising this output in the PR comment action in a way that allows for proper formatting. Is this something that there is an established pattern for?

Upload images

Hey,

great repo and action. I was wondering how hard it would be to add the option to also upload images as a comment into the PR conversation.

Feature request: `append` mode to add to existing comment

I would like to add content to a comment after each step (or job) of a workflow. Right now I can upsert the content to replace the previous content with the new content, but to implement append I'd need to get the content of the comment myself before manipulating. It would be nice if that functionality was built in.

Abstain from renaming branches

First: Thank you for all the work you put into this.

One more thing: Please abstain from renaming branches in the future. The github syntax forced us to name a branch when using your github action. So we hardwired "master", and now we have to go through 30 projects to rename it to "main". Actually I would suggest to just stick with conventions or at least not change directions.

Possibility to comment with a clickable images / badges with a link

Hello, really like the action, but it looks like it is not possible to comment with a clickable image / badge smth. like

[![Contribute](https://img.shields.io/badge/Eclipse_Che-Hosted%20by%20Red%20Hat-525C86?logo=eclipse-che&labelColor=FDB940)](https://workspaces.openshift.com/)

in the comment, it should resolve to the following clickable badge Contribute

Currently, it is not parsed correctly by the action. Any pointers. Thanks!

Split PR comment if it is too long

Version:

thollander/actions-comment-pull-request@v2

Issue:

Run thollander/actions-comment-pull-request@v2
Error: An error occurred trying to start process '/home/runner/runners/2.310.2/externals/node16/bin/node' with working directory '/home/runner/work/somerepo/somerepo'. Argument list too long

The comment I am trying to add to PR is terraform plan, which size is bigger than can be added.

Possible solution

Ideally, PR comment might be divided into several parts and added one by one in PR

Parameter token or opts.auth is required

I am encountering an error message that says "Parameter token or opts.auth is required."

Run thollander/actions-comment-pull-request@v2
  with:
    filePath: /tmp/test.md
    comment_tag: nrt_file
    reactions: eyes, rocket
    mode: recreate
    create_if_not_exists: true
  env:
    CALLBACK_ENABLE: true
Error: Parameter token or opts.auth is required

filePath content as code

when using filePath I would like the rendered file to be shown as code e.g. a yaml file shown as yaml in a code block

Deleting the created comment?

I want to delete the comment as the last step on a workflow.

It doesn't look like that functionality exists, is there another way I could do it?

Question/Request: Is it possible to delete a comment without creating a new one?

First of all thanks for creating this GitHub Action! 🎉

Context

I've been working on making our pipeline check clearer in pull request. One of the ways of doing this is to comment some of the failing reasons.

Question/Request

I would like to remove an earlier created comment by this GitHub Action when for example the errors are fixed and the pipeline succeeds. Preferable in a way where I can run this action and have it succeed even if no comment was posted before. I assume it would be based on the comment_tag.

What do you think?

Change `comment_includes` to be automatic

Improvement idea: switch from comment_includes to comment_tag

If message body had something like this appended <!--- thollander/actions-comment-pull-request "comment_tag" --->
it would be easy to precisely select comment for editing and wouldn't be visible to user.

Benefits:

  • independent of message body
  • no false-positive matches
  • not displayed to user

Proper versionning

Context

Currently, versioning is managed thanks to pushing tags with the version number and updating the main branch.
It involves that if someone wants to have always the latest version updated (without breaking change), it's not possible.

Target

Manage a major tag that will help users to be updated everytime (eg v1 pointing to latest version v1.0.1 for instance).
And always update this tag when pushing a non breaking update.

Docs : https://docs.github.com/en/actions/creating-actions/about-actions#using-tags-for-release-management

Failing to add html file as comment on PR from forked repository

I have a template repository and I'd like to add a prettier check before submitted PRs are accepted. Not only that, I'd like prettier to run and, case failed, to generate a diff output of which files should be changed for the PR to be accepted.

I was able to create such a workflow, where prettier runs and when failed an html diff is created. I was trying to include this html file as a comment on the PR with your action, but I couldn't. I saw in the docs that you suggest using pull_request_target, but in GitHub docs they have a warning about using this and pwn PRs.

Any idea of how to work it out?

Allow to silently exit on no PR error

Hey,

Currently, when the action is run on non-PR event the condition below is triggered which exits the action but also throws an error, which is really non-blocking (when used with continue-on-error). In my case, that message confuses users seeing the logs.

core.setFailed('No issue/pull request in input neither in current context.');

I could of course add an if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' on this action step, but then the name of main branch is configurable in GitHub, so this is not really a bulletproof solution.

Would be good if we could decide (via input), whether the message is shown or not.

I would be glad to propose a PR for this change if this seems like a good idea.

Formatting of message

It would be great if you could apply some formatting to the comment such a code block, especially when it comes from a file

Using branches-ignore with comment-pull-request runs workflow when branch is set to be ignored

Hi all,
Currently I'm trying to comment on pull request to a master branch and using the "branches-ignore". I'm uncertain if this is github not running my workflow correct or my config. Can you steer me in the right direction?

  • If I open a hotfix/update branch and pull request to master, the workflow runs and places the comment in the PR when it's set to be ignored and no comment should be inserted.

This is the workflow-

name: 'Comment on PR'
on:
pull_request:
branches-ignore:
- 'release/**'
- 'hotfix/**'

jobs:
example_comment_pr:
runs-on: ubuntu-latest
name: comment PR if needed
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Comment PR
uses: thollander/actions-comment-pull-request@v1
with:
message: 'Thank you for the master PR. We only accept hotfix PRs for master branch. Please switch base branch to dev to get reviews'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

thank you

Unable to resolve `master` version

Is the master now main?
I get this error when using the action.
Error: Unable to resolve action thollander/actions-comment-pull-request@master, unable to find version master
If so, then please update the readme in the Usage section.

Deletion should delete new comment, not the "updated" one

The deletion does not work if an update happened (of a comment created an another workflow).

Steps:

  1. Workflow A creates comment
  2. Workflow A ends
  3. Workflow B starts (later)
  4. Workflow B creates new comment (instead of updating existing one)
  5. Workflow B post Action reports successful deletion. Comment from Workflow A is remived. Comment from Workflow B is still there.

Screenshot_2023-07-03-17-25-11-85_ffb2f5e1b976ff98cfc94f359fbce8de

Non-MWE:

JabRef/jabref#10057

State after post action of workflow B

Screenshot_2023-07-03-17-45-30-76_ffb2f5e1b976ff98cfc94f359fbce8de

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.