Giter Site home page Giter Site logo

peter-evans / create-or-update-comment Goto Github PK

View Code? Open in Web Editor NEW
631.0 9.0 110.0 1.76 MB

A GitHub action to create or update an issue or pull request comment

License: MIT License

JavaScript 2.30% TypeScript 97.70%
github-action github-comments comment-reactions github-issues

create-or-update-comment's People

Contributors

actions-bot avatar danielhabenicht avatar dependabot[bot] avatar dermah avatar ematipico avatar kurt-von-laven avatar larshp avatar mfn avatar peter-evans avatar renovate-bot avatar robdodson avatar umanghome 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

create-or-update-comment's Issues

Error - Missing either 'issue-number' or 'comment-id' - How to not run the step conditionally?

I'm trying to handle an edge case where my workflow fails because there is no existing branch to write the comment to.

My goal is to not run the Comment PR (Deployment failure) step when the ${{ steps.pr_id_finder.outputs.number }} is not defined, but I don't really understand how to do that.

      # We need to find the PR id. Will be used later to comment on that PR.
      - name: Finding Pull Request ID
        uses: jwalton/gh-find-current-pr@v1
        id: pr_id_finder
        if: always() # It forces the job to be always executed, even if a previous job fail.
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

      # On deployment failure, add a comment to the PR, if there is an open PR for the current branch
      - name: Comment PR (Deployment failure)
        uses: peter-evans/create-or-update-comment@v1
        if: failure()
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          issue-number: ${{ steps.pr_id_finder.outputs.number }}
          body: |
            :x:  Deployment **FAILED**
            Commit ${{ github.sha }} failed to deploy to [${{ env.ZEIT_DEPLOYMENT_URL }}](${{ env.ZEIT_DEPLOYMENT_URL }})
            [click to see logs](https://github.com/UnlyEd/TFP-v4/pull/${{ steps.pr_id_finder.outputs.number }}/checks)

I tried to do

      - name: Comment PR (Deployment failure)
        uses: peter-evans/create-or-update-comment@v1
        if: ${{ steps.pr_id_finder.outputs.number }} && failure()
		...

But it didn't work out. Would you know how to achieve it?

Updating URLs in comments

Hello,

I'm looking for a way to update specific URLs within a comment, each time a new comment is posted. Context: AntennaPod/AntennaPod#6142

Would that be possible with this action? I have the impression that the comment update ability simply replaces the whole comment body. I'm not sure I can update a part of a comment, e.g. based on RegEx.

Maybe it would work to extract the existing comment body, store it in a variable, perform an action on it, and then use the updated variable to replace the comment body?

How do I output env.GITHUB_RUN_ID?

No matter what I try I can't output this var

- name: Create comment
        uses: peter-evans/create-or-update-comment@v1
        with:
          issue-number: ${{ github.event.inputs.related-issue-id }}
          body: |
            Deployed OK: https://github.com/bitsofinfo/github-actions-demo/actions/runs/${{env.GITHUB_RUN_ID}}

Action running without progress

Yesterday, the action started as usual but never finished. After about an hour I canceled it because I was very confused. See the image below.

image

After running the exact same workflow again a little later, it worked without any issue. This could be related to the GitHub Actions outage yesterday (see GitHub status entry), but the action actually ran a few hourse before the reported starting date for the incident. Not sure what else could have caused this.

Here is the workflow I'm using:

on:
  issues:
    types:
      - assigned

jobs:
  ## Before deploy let user now it is running ##
  issue-comment-confirm:
    name: Comment Start
    if: contains(github.event.issue.assignee.login, 'timmeinerzhagen')

    runs-on: ubuntu-latest

    steps:
      - name: Create comment
        uses: peter-evans/create-or-update-comment@a35cf36e5301d70b76f316e867e7788a55a31dae # v1.4.5
        with:
          token: ${{ secrets.GH_TOKEN }}
          issue-number: ${{ github.event.issue.number }}
          body: |
            <message>

Add list of users or groups for whom no comment is created

When certain people open an issue on a repository, like for example the owner themselves, there might be no need to create a comment on the issue. With a pass list users and groups could be specified for whom the action does not create comments.

Clearing comment before updating

This may be a trivial question, but using the example in the README.md, I'm getting text appended to existing comments. Is there any way to replace the text completely? Thanks!

Feature Request: Delete Comment

I am using this action for displaying informative comments. It would be great to remove the comment to avoid clutter as soon as the issue is resolved.

Would that be something to add to your action?

File not found

I have a text file created in step prior to running comment action. File does exist, but the action says it doesn't. Any idea what am I doing wrong?

2022-10-25_14-20-46

Error: Not Found

Having used this action for over a year, I'm now receiving Error: Not Found

peter-evans/create-or-update-comment@v2

[Question] can update bot comments on PRs?

Hi @peter-evans,

I hope you find very well.

I was wondering if this GitHub action could be used to update a bot comment on an opened PR so we can avoid having a lot of comments from the same bot multiple times. Is something related to this #110, but with a focus on bots.

Truncate files which are too long

/opt/github/actions-runner-1/_work/_actions/peter-evans/create-or-update-comment/v3.0.0/dist/index.js:4685
      const error = new requestError.RequestError(toErrorMessage(data), status, {
                    ^

RequestError [HttpError]: Validation Failed: {"resource":"IssueComment","code":"custom","field":"body","message":"body is too long (maximum is 65536 characters)"}
    at /opt/github/actions-runner-1/_work/_actions/peter-evans/create-or-update-comment/v3.0.0/dist/index.js:4685:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  status: 422,

This is caused when the body-path file is too large. Can we limit the body content to 65535 characters with a mode (head/tail)? This would limit an unexpected error handling if an additional warning was output when the file size if more than the limit

A prototype in shell:

if [ stat -c "%s" <file> -gt 65535 ]; then
  echo "::warning file=${filename},line=1,endLine=1,title=Content too long::Restricting content to just 65535 bytes as per truncation setting: ${mode}"
  # get extra bytes since unicode characters can be longer than 1 byte
  if [ ${mode} == "tail" ]; then command=tail else command=head; fi
  content=$(${command} -c 65538 ${filename} | iconv -c -f UTF-8 -t UTF-8 | ${command} -c 65535)
else
  content=$(cat ${filename}
fi

GITHUB_TOKEN permissions that needs write access

Since it's now possible to control the permissions of the GITHUB_TOKEN on a job basis (https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/) it would be nice to know what permissions need write access to get this job to work.

I've currently set all of my repos permissions to read and then the job failed using this action with the following error
image

After reading the readme I found that this is expected and is caused by not having the correct permissions.
So it would be really awesome if it could be added to the readme what permissions are required to have write access for this action to work.

Only posting comment if condition is met

Hey peter,
I have a question , if I wanted to only post the comment on the return value of a script
for example if the script returns a non-zero value post the comment.
I am new to github actions so there might be something I am not doing properly

I am trying to assign the return value of the script to an environment variable
and then checking that in the if statement of your example code.

  - name: Find Comment
    uses: peter-evans/find-comment@v2
    id: fc
    with:
      issue-number: ${{ github.event.pull_request.number }}
      comment-author: 'github-actions[bot]'
      body-includes: This comment was written by a bot!

  - name: Create comment
    if: steps.fc.outputs.comment-id == '' && env.failedNum != 0
    uses: peter-evans/create-or-update-comment@v2
    with:
      issue-number: ${{ github.event.pull_request.number }}
      body: |
        This comment was written by a bot!
      reactions: rocket

  - name: Update comment
    if: steps.fc.outputs.comment-id != '' && env.failedNum != 0
    uses: peter-evans/create-or-update-comment@v2
    with:
      comment-id: ${{ steps.fc.outputs.comment-id }}
      body: |
        This comment has been updated!
      reactions: hooray`

Update comment, replace body

Hi, first of all thanks for your great actions!

My question: Is there are way to replace the body of a comment, when updating it?

I monitor an external pipeline status and want to change the status from running to success or failed. Replacing the comment with the new status is much more readable, than adding an edit to the comment.

How to use comment on current PR and populate body from output of previous step

Couple of questions, I want to use this action with a pull request triggered workflow which has a single job.

What's not clear to me is:

  • How can I comment on the PR that triggered the job, the issue-number argument requires a hardcoded value but that's not much use in real world, do you have an example on how to do this?

  • How can I populate the body of the comment with data from a previous step. Essentially I've created a txt file on the runner which I want to use as the content for the comment.

Here is an example of my workflow:

name: Code Coverage

on: pull_request

jobs:
  test:
    name: Test
    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v2  
      
    - name: Switch XCode version to 11.4
      run: sudo xcode-select -s /Applications/Xcode_11.4.app
      
    - name: Run code coverage
      run: |
        xcodebuild clean test -project test.xcodeproj -scheme test -destination "platform=iOS Simulator,name=iPhone 11 Pro" -derivedDataPath Build/ -enableCodeCoverage YES CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO ONLY_ACTIVE_ARCH=NO
        xcrun xccov view --report Build/Logs/Test/Run-test-*.xcresult > coverage.txt
        
    - name: Upload artifacts
      uses: actions/upload-artifact@v1
      with:
        name: Code Coverage Report
        path: coverage.txt
        
    - name: Add test report comment on PR
      uses: peter-evans/create-or-update-comment@v1
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        issue-number: ????????
        body: |
          ```
          *****content of coverage.txt to go here*****
          ```
        reaction-type: 'rocket'

Thanks.

Error: Missing either 'issue-number' or 'comment-id'.

Hi
I'm trying to use this step to add comments on both new PR and PR that already exists.
Right now this part github workflow looks like this:
`name: deploy swagger specs

on:
push:
paths:
- 'swagger-/**.yaml'

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
...
- name: Deploy
run: aws s3 sync .....
- name: Create comment
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Swagger specs were deployed to https://swagger.example.com/${GITHUB_REF##*/}/example.yaml`

But this workflow fails on Create comment step, with such error:
Run peter-evans/create-or-update-comment@v1 Error: Missing either 'issue-number' or 'comment-id'.
I don't know how to troubleshoot this further. I already tried to use github.event.issue.number and github.event.number instead of github.event.pull_request.number but error never changed. Any idea what am I doing wrong? thanks.

Support removing reactions

I would like to be able to remove reactions from a comment that I previously added.

Consider for example the following use case:
I have a long running job that results in a comment to PR.
When a new change is pushed, I want to indicate that I will update this comment by adding a reaction.
After the new comment content has been posted, I would like to remove this reaction again.

(This can of course as well be handled by adding text and replacing it later. If you want, I can think of a better use case ๐Ÿ˜‚ )

body-file markdown formatting code block

I can add markdown file as an issue comment but how can I format this comment as a code block? Is that possible?

      - name: Run Trivy vulnerability scanner in repo mode
        uses: aquasecurity/trivy-action@master
        with:
          image-ref: ''
          scan-type: 'fs'
          format: 'table'
          exit-code: '0'
          ignore-unfixed: true
          vuln-type: 'os,library'
          severity: 'CRITICAL,HIGH'
          output: 'trivy-result.md'

      - name: Upload Trivy report
        uses: actions/upload-artifact@v3
        with:
          path: trivy-result.md
          name: trivy-result

      - name: Download Trivy report
        uses: actions/download-artifact@v1
        with:
          name: trivy-result

      - name: Create comment
        uses: peter-evans/create-or-update-comment@v2
        with:
          issue-number: ${{ github.event.issue.number }}
          body-file: 'trivy-result.md'

[question] Is body-path relative to root? (Also, some ideas)

The title pretty much says it.

I think it is, but I wasn't entirely sure either, so I wanted a bit of clarification here.

Also, I would also ask about supported file types.
Like does it need to be a txt file? Or will .md work too? What about other formats?

And finally, will values like context (i.e. ${{ github.event.pull_request.number }} be properly parsed by GitHub Actions, or would it need to remain in the GitHub workflow file as a body option itself?

If it doesn't parse, maybe offer an option to define placeholders that should be replaced?
Like f.e. in my case:

placeholders: |
  commit: ${{ env.HEAD_SHA }}
  logs: ${{ env.LOGS }}
  download: ${{ env.DOWNLOAD }}

This could actually even be a good idea to allow much more customizable file templates, by allowing to replace parts within it with values you define.

Like - again - in my personal case would the file look like this...

![badge]

{{ text }}

| Name     | Link           |
| -------- | -------------- |
| Commit   | {{ commit }}   |
| Logs     | {{ logs }}     |
| Download | {{ download }} |

[badge]: https://img.shields.io/badge/{{ badge_text }}-0d1117?style=for-the-badge&labelColor={{ badge_color }}&logo={{ badge_logo }}

...and when used, I would have a setup like this:

- uses: peter-evans/create-or-update-comment@v3
  with:
    issue-number: ${{ github.event.pull_request.number }}
    comment-id: ${{ steps.find-comment.outputs.comment-id }}
    edit-mode: replace
    body-path: ./.github/pr-comment-template.md
    options: |
      text: The build of this pull request was successfull! You can find a download link below.
      commit: ${{ env.COMMIT }}
      logs: ${{ env.LOGS }}
      download: ${{ env.DOWNLOAD }}
      badge_text: Build successful!
      badge_color: 00FF00
      badge_logo: github

The only issues I currently would see is how stuff like line-breaks could be implemented and if there should be an option to hide content based stuff like if a placeholder has a value or not... Tho, that all depends on if this is even a good option to add at all...

Multi line strings

Thanks for trying to explain how to create multi line strings in output at https://github.com/peter-evans/create-or-update-comment#setting-the-comment-body-from-a-file, but for some reason that did not work for me when I created the string in a previous run step.

What did work, was just directly use %0A instead of \n ๐Ÿ‘ Maybe worth another note somewhere.

And thanks for this great extension, especially the last code block at https://github.com/peter-evans/create-or-update-comment#where-to-find-the-id-of-a-comment is a great use case ๐Ÿ™‡

Option to append new body immediately after existing body (no break or space char in between)

The default behavior to add a newline break between the existing comment body and the new body is a good default.

I think it will be nice to have feature if we can disable the added break, or use a space instead. (Could be called append-separator with three options: newline, space, none.)

Example: If the original comment is:

Look out for an update here:

With append-separator: newline (default):

Look out for an update here:
This is the update.

With append-separator: space:

Look out for an update here: This is the update.

With append-separator: none:

Look out for an update here:This is the update.

GITHUB_TOKEN permissions used by this action

At https://github.com/step-security/secure-workflows we are building a knowledge-base (KB) of GITHUB_TOKEN permissions needed by different GitHub Actions. When developers try to set minimum token permissions for their workflows, they can use this knowledge-base instead of trying to research permissions needed by each GitHub Action they use.

Below you can see the KB of your GITHUB Action.

name: 'Create or Update Comment'
github-token:
  action-input:
    input: token
    is-default: true
  permissions:
    issues: write
    issues-reason: to create or update comment
    pull-requests: write
    pull-requests-reason: to create or update comment #Checkout: https://github.com/peter-evans/create-or-update-comment#action-inputs

If you think this information is not accurate, or if in the future your GitHub Action starts using a different set of permissions, please create an issue at https://github.com/step-security/secure-workflows/issues to let us know.

This issue is automatically created by our analysis bot, feel free to close after reading :)

References:

GitHub asks users to define workflow permissions, see https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/ and https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token for securing GitHub workflows against supply-chain attacks.

Setting minimum token permissions is also checked for by Open Source Security Foundation (OpenSSF) Scorecards. Scorecards recommend using https://github.com/step-security/secure-workflows so developers can fix this issue in an easier manner.

It don't work

I have this error in my github action steps console

Run peter-evans/create-or-update-comment@v3
/home/runner/work/_actions/peter-evans/create-or-update-comment/v3/dist/index.js:4690
const error = new requestError.RequestError(toErrorMessage(data), status, {
^

RequestError [HttpError]: Resource not accessible by integration
at /home/runner/work/_actions/peter-evans/create-or-update-comment/v3/dist/index.js:4690:21
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
status: 403,
response: {
url: 'https://api.github.com/repos/ngimdock/express-typescript-starter/issues/6/comments',
status: 403,
headers: {
'access-control-allow-origin': '*',
'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
connection: 'close',
'content-encoding': 'gzip',
'content-security-policy': "default-src 'none'",
'content-type': 'application/json; charset=utf-8',
date: 'Sat, 06 May 2023 04:37:34 GMT',
'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
server: 'GitHub.com',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
'transfer-encoding': 'chunked',
vary: 'Accept-Encoding, Accept, X-Requested-With',
'x-content-type-options': 'nosniff',
'x-frame-options': 'deny',
'x-github-api-version-selected': '2022-11-28',
'x-github-media-type': 'github.v3; format=json',
'x-github-request-id': '6C82:173A:19743B:353232:6455D98E',
'x-ratelimit-limit': '1000',
'x-ratelimit-remaining': '998',
'x-ratelimit-reset': '1683351219',
'x-ratelimit-resource': 'core',
'x-ratelimit-used': '2',
'x-xss-protection': '0'
},
data: {
message: 'Resource not accessible by integration',
documentation_url: 'https://docs.github.com/rest/reference/issues#create-an-issue-comment'
}
},
request: {
method: 'POST',
url: 'https://api.github.com/repos/ngimdock/express-typescript-starter/issues/6/comments',
headers: {
accept: 'application/vnd.github.v3+json',
'user-agent': 'octokit-core.js/3.6.0 Node.js/16.16.0 (linux; x64)',
authorization: 'token [REDACTED]',
'content-type': 'application/json; charset=utf-8'
},
body: '{"body":"This is a multi-line test comment\n- With GitHub Markdown โœจ\n- Created by [create-or-update-comment][1]\n\n[1]: https://github.com/peter-evans/create-or-update-comment"}',
request: {
agent: Agent {
_events: [Object: null prototype] {
free: [Function (anonymous)],
newListener: [Function: maybeEnableKeylog]
},
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object: null prototype] { path: null },
requests: [Object: null prototype] {},
sockets: [Object: null prototype] {},
freeSockets: [Object: null prototype] {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 0,
maxCachedSessions: 100,
_sessionCache: {
map: {
'api.github.com:443:::::::::::::::::::::': [Buffer [Uint8Array]]
},
list: [ 'api.github.com:443:::::::::::::::::::::' ]
},
[Symbol(kCapture)]: false
},
hook: [Function: bound bound register]
}
}
}

[Testing Issue]

This is an issue used by this action's workflow test cases.

Feature request: Delete prior comment and add new

Thank you so much for making this extremely useful Action. It's been immensely helpful for my workflows. In my use case, I publish unit and E2E test results as comments to my team's PRs. However, I've noticed sometimes on PRs with a lot of commits or lengthy discussions that, due to their age, the comments produced using this Action get buried behind the following separator, and so when they are updated, those updates get lost.

CleanShot 2022-04-01 at 13 47 10

I was hoping you might consider adding a feature that, instead of updating the previous comment, will delete it and add a new comment entirely so that the latest updates always appear on screen.

Thank you!

Unable to update the comment on github discussion room, please help

Hi @peter-evans / anyone

Hope you are doing well , we are using your repo at our organization noticed few issues like issue-number and comment-id are hardcoded in your github action can we make it more generic like depends on the run like below yaml

Use case :

  1. whenever their is an new discussion room opened or modified .
  2. it should automatically respond with an GIF in a comic way and it will convey that we are taking care of the issue
  3. it should update that new or old discussion room with the ticket

Below is my workflow file please do help

name: Auto Reply to Discussions

on:
workflow_dispatch:
discussion:
types: [created, edited, labeled, answered, unanswered]
discussion_comment:
types: [created, edited, labeled, answered, unanswered]

jobs:
auto_reply:
runs-on: ubuntu-latest

steps:
  - name: Checkout repository
    uses: actions/checkout@v2
    with:
      repository: ${{ secrets.REPO }}
      GH_TOKEN: ${{ secrets.SECRET_TOKEN }}  
  
  - name: Get discussion payload
    uses: actions/github-script@v4
    with:
      github-token: ${{ secrets.SECRET_TOKEN }}
      script: |
        console.log(JSON.stringify(context.payload))

  - name: Login
    uses: atlassian/gajira-login@v3
    env:
      JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
      JIRA_USER_EMAIL: ${{ secrets.JIRA_CLOUD_USER_EMAIL }}
      JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}

  - name: Handle discussion event
    uses: peter-evans/create-or-update-comment@v3
    with:
      issue-number: ${{ github.event.discussion.number }}
      token: ${{ secrets.SECRET_TOKEN }}
      body: |
        A new discussion event has occurred!

        **Action**: ${{ github.event.action }}
        **Discussion ID**: ${{ github.event.discussion.id }}
        **Discussion Title**: ${{ github.event.discussion.title }}
        **Discussion URL**: ${{ github.event.discussion.html_url }}
        **Repository Name**: ${{ github.event.repository.name }}
        Here's a GIF to make it more interactive: https://github.com/<organization-name>/athena-poc-design1/blob/06ab282c735c3d6bab0b760e198144301a5eb2b5/Automated_response.gif
      reactions: heart

Post comment with image

Would be great if it would be possible to create a comment with a image.

I think it would be useful after creating github action local images (like screenshots) and post the image(s) with this action in a comment (like a user can copy/paste images in a regular comment)

In the end it would be helpful when the image urls would be available as output variable to re-use the image urls for other action steps

Old setOutput function before @actions/core 1.10.0 is deprecated

The old setOutput function is deprecated and its use leads to the following deprecation warning:

The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

See https://github.com/Kas-tle/java2bedrock.sh/actions/runs/3247277630 for example.

This can be remedied by upgrading the @actions/core package to 1.10.0 as described here:
https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Instructions for using a file content as a comment body are not valid anymore

I've noted that the following instructions on the README, regarding how to use a file content as the body comment, that involve parsing and replacing values from a multiline body https://github.com/peter-evans/create-or-update-comment#setting-the-comment-body-from-a-file are not valid anymore: the comment being posted ends up not being in a correct markdown format.
I've observed this behaviour after moving away from the now deprecated ::set-output command on one of the GHA I'm using.

Check the attached screenshot
Screenshot 2022-10-19 at 15 20 25

Based on the following comment, we can just use the regular approach to set multiline string as output.
https://github.com/orgs/community/discussions/26288#discussioncomment-3876281

I updated my wokflows and everything is displayed correctly once more:

image

Only works for organizations?

I was testing out this action via this YT tutorial but could only get it to work when the repo was in an organisation. If it was just a 'normal' repo it didn't work.

The tutorial states that only works for organization repos, in the pinned comment.

Is there any way to get this to work on all repo types? Thanks.

Creating/updating comment on push event

So I'm trying to update PR with comment with results written in `md` on each push from generated file, but event "push" doesn't have property "number" so I can't search/update PR for comment. How to do that, or bypass?

This is what I have so far.

name: End-to-end tests
on: [push]
jobs:
  cypress-run:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        
      - name: Cypress run
        uses: cypress-io/github-action@v2
        
      # Create md report from generated reports
      - name: Merge generated reports into one
        run: yarn run merge:reports
        
      - name: Create md report
        run: yarn run create:markdown:report
        
      # Read created md
      - name: Read md content
        id: read_file
        uses: andstor/file-reader-action@v1
        with:
          path: "merged.md"
          
      # Create or update comment in PR
      - name: Find Comment
        uses: peter-evans/find-comment@v1
        id: fc
        with:
          issue-number: ${{ github.event.pull_request.number }}
          comment-author: 'github-actions[bot]'
          
      - name: Create or update comment
        uses: peter-evans/create-or-update-comment@v1
        with:
          comment-id: ${{ steps.fc.outputs.comment-id }}
          issue-number: ${{ github.event.pull_request.number }}
          body: ${{ steps.read_file.outputs.contents }}
          edit-mode: replace

Should this work on PRs raised from forks?

I tried to use this instead of the default GHA, because token takes the PAT token. So that I can run an action on a PR from fork, but I get the following message:

[@octokit/rest] `const Octokit = require("@octokit/rest")` is deprecated. Use `const { Octokit } = require("@octokit/rest")` instead
[@octokit/rest] `const Octokit = require("@octokit/rest")` is deprecated. Use `const { Octokit } = require("@octokit/rest")` instead
##[error]Bad credentials

Is this expected behaviour or should it work?

NaN when using github.event.number

Hello, I'm using this action like that:

     - name: Publish URLs
        uses: peter-evans/create-or-update-comment@v1
        with:
          issue-number: ${{ github.event.number }}
          body: |

and it returns the following error:

##[error]Invalid value for parameter 'issue_number': "github.event.number" is NaN

I guess that it's because there isn't a string to int conversion in the action. However, actions don't provide data type conversion, so it's impossible for me to use this action.

Terraform plan colors

Would it be possible to output the proper 'create' 'destroy' colors in the body? I've tried using the below:
body: |
Terraform Plan:

      ```hcl
      ${{ steps.plan.outputs.plan }}
      ```

And it's ok, but it doesn't show proper colors for create and destroy, create shows as red.
image
I know your action isn't specific to terraform, but thought maybe someone might be able to help.
Thanks

Combine create and update in a single configuration?

Hello ๐Ÿ‘‹

I was wondering if you would consider a PR which slightly changes the behavior of the Action to allow someone to create or update in a single configuration? My use case is I wanted to have a comment at the top of my PR that shows lint status. If it's the first the linter has run, it will create this comment. On subsequent runs, it will update this comment using replace.

Currently the Action will always create a new comment if an issue number is passed. Here's the relevant snippet of code:

if (inputs.issueNumber) {
  ...
} else if (inputs.commentId) {
  ...
}

However, if you swap the order of the condition, then you can have it first check for a comment-id to update, and if one isn't passed it will check for an issue number to create a new comment:

if (inputs.commentId) {
  ...
} else if (inputs.issueNumber) {
  ...
}

That enables a workflow like this:

# This finds the first comment id from the GitHub Actions bot.
# If it hasn't commented on the issue or PR yet then it returns an empty string.
- name: Find comment
  id: find_comment
  uses: ./.github/actions/find-comment
  with:
    token: ${{ secrets.GITHUB_TOKEN }}

- name: Create or update comment
  # I forked a version of this repo to implement the above mentioned conditional
  uses: robdodson/create-or-update-comment@master
  with:
    token: ${{ secrets.GITHUB_TOKEN }}
    issue-number: ${{ github.event.number }}
    # If the comment-id is blank, this will create a new comment.
    # Otherwise, it will update the comment.
    comment-id: ${{ steps.find_comment.outputs.comment-id }}
    body: |
      Create or update this comment.
    edit-mode: replace
  if: success()

I realize you could also achieve this by writing two steps and using if to check if it should create or update the comment, but that felt a bit noisy to me. If you'd be open to this change then I could send over a PR. I also understand if you'd prefer to keep the Action as is because it matches your use case :)

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.