Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Get the id from the issue_comment trigger event#419

Unanswered
sonomirco asked this question inQ&A
Discussion options

Hi@joshmgross
I have a quick question.
I am trying to use the action to update a specific comment, but I am havingInvalid or unexpected token.
Reading some previous posts it seems I am passing something wrong.
This is my action:

on:
issue_comment:
types: [created]
branches:
- develop

jobs:
deploy:
if: github.event.issue.pull_request && contains(github.event.comment.body, '/deploy')
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.issue.pull_request.head.sha }}
- uses: actions/github-script@v6
with:
script: |
github.rest.issues.updateComment({
comment_id: context.comment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: '${{ github.event.comment.body }} 👋 Thanks for reporting!'
})

iscontext.comment.id correct? Or should I use${{ github.event.comment.id }}?
Thanks for the help.

You must be logged in to vote

Replies: 2 comments 3 replies

Comment options

I had the same question. Looking at theGitHub Docs REST API, I figured I could extract it from theissue_url, sinceissue is not included in the payload. Leaving it for further reference.

This is a sample response present in the docs:

{"id":1,"node_id":"MDEyOklzc3VlQ29tbWVudDE=","url":"https://api.github.com/repos/octocat/Hello-World/issues/comments/1","html_url":"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1","body":"Me too","user": {"login":"octocat","id":1,"node_id":"MDQ6VXNlcjE=","avatar_url":"https://github.com/images/error/octocat_happy.gif","gravatar_id":"","url":"https://api.github.com/users/octocat","html_url":"https://github.com/octocat","followers_url":"https://api.github.com/users/octocat/followers","following_url":"https://api.github.com/users/octocat/following{/other_user}","gists_url":"https://api.github.com/users/octocat/gists{/gist_id}","starred_url":"https://api.github.com/users/octocat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octocat/subscriptions","organizations_url":"https://api.github.com/users/octocat/orgs","repos_url":"https://api.github.com/users/octocat/repos","events_url":"https://api.github.com/users/octocat/events{/privacy}","received_events_url":"https://api.github.com/users/octocat/received_events","type":"User","site_admin":false  },"created_at":"2011-04-14T16:00:49Z","updated_at":"2011-04-14T16:00:49Z","issue_url":"https://api.github.com/repos/octocat/Hello-World/issues/1347","author_association":"COLLABORATOR"}

The following Javascript code gives you theissue_number:

issue_number=issue_url.split('/issues/')[1]
You must be logged in to vote
3 replies
@joshmgross
Comment options

Thegithub.event will match the corresponding webhook event payload -https://docs.github.com/en/webhooks/webhook-events-and-payloads#issue_comment

github.event.issue.number should work if you wanted to avoid parsing the URL.

@caioariede
Comment options

Hmmm! Maybe that was it then? I was tryingcontext.issue, so I guess I should just pass${{ github.event.issue }} instead

@joshmgross
Comment options

Yeahcontext is pretty incomplete. I recommend relying on the event payload directly when you can.

Comment options

iscontext.comment.id correct? Or should I use${{ github.event.comment.id }}?

context is provided by@actions/github, I don't see acomment field there.

It's typically easier to use thegithub.event context directly.github.event.comment.id looks correct based onhttps://docs.github.com/en/webhooks/webhook-events-and-payloads#issue_comment

body: '${{ github.event.comment.body }} 👋 Thanks for reporting!'

One thing to watch out for is multi-line values though - expressions are evaluated and then the script itself is parsed as JavaScript. So itgithub.event.comment.body contains newlines, you'll end up with invalid JavaScript which could explain the "Invalid or unexpected token" error.

Typically I recommend working around that by passing expression values via theenv.

      -uses:actions/github-script@v7env:BODY:${{ github.event.comment.body }}with:script:|            console.log(process.env.BODY)
You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@sonomirco@caioariede@joshmgross

[8]ページ先頭

©2009-2025 Movatter.jp