How to get comment Node ID of a discussion in GitHub Action with GitHub GraphQL API

How to get comment Node ID of a discussion in GitHub Action with GitHub GraphQL API


0

I’m working on a GitHub Action triggered on the comment of a certain discussion (say org/repo/discussions/6#discussioncomment-7349183) being created or edited. I’d like the action to reply the comment like "your pipeline is running here" with a link.

Then I found that there’s only GraphQL way to add a reply like:

mutation {
  addDiscussionComment(input:{  
    discussionId: "D_something",
    replyToId: "DC_something_", 
    body: "Test reply", 
  }) {
    clientMutationId
    comment {
      id
      body  
    }
  }
}

I’d like to get the Node ID of the comment with github.event.comment.id in the pipeline and use it as replyToId, but comments only accepts these arguments:

after: String
Returns the elements in the list that come after the specified cursor.

before: String
Returns the elements in the list that come before the specified cursor.

first: Int
Returns the first n elements from the list.

last: Int
Returns the last n elements from the list.

Which means I’ll use a query like:

{
  repository(owner: "org", name: "repo") {
    discussion(number: 6) {
      comments(first: 1) {
        nodes {
          id
        }
      }
    }
  }
}

However I don’t know the position of github.event.comment.id as the triggerer is not guaranteed to be the last comment.

Could you please show me how to get the comment’s Node ID?


Load 6 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *