Skip to content

wesleyscholl/create-discussion-comment

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Create Discussion Comment ⌨️💬✅

Create Comments on Exsiting GitHub Discussions using GitHub Actions

Tests

Code Style: prettier

GitHub Marketplace

About

This action allows you to add comments to GitHub Discussions using GitHub Actions.

Usage

In your workflow, to create a new comment on a discussion topic, include a step like this:

    - name: Run create-discussion-comment
      uses: wesleyscholl/[email protected]
      id: create-comment
      with:
        token: ${{ secrets.DISCUSS_TOKEN }}
        body: "This is a test comment from a GitHub action"          
        discussion-id: 'D_kwdje64ife75s9o'
        client-mutation-id: '1234'

Ensure you provide the discussion ID, this can be found using the GitHub GraphQL Explorer. (See below)

Action Inputs

Name Description Requried? Default
token A GitHub PAT is required. Ensure the PAT has discussion: write and public_repo: read for public repos and repo: write for private repositories. See more details about tokens here PAT. Yes N/A
body The contents of the comment in string format. No "Comment provided by GitHub Action create-discussion-comment"
discussion-id The node ID of the discussion to comment on. This can be found using the GitHub GraphQL explorer, more details below. Yes N/A
client-mutation-id A unique identifier for the client performing the mutation. No "1234"
replyToId The node ID of the discussion comment to reply to. If absent, the created comment will be a top-level comment. No N/A

Action Outputs

Name Description Data Model
clientMutationId The unique identifier provided as an input. See below
comment The discussion comment that was created. See below

Response

{"data":
{"addDiscussionComment":
{"clientMutationId":"1234",
"comment":{
    "id":"DC_kwdje64ife75s9o",
    "body":"This is a test comment from a GitHub action"
    }}}}

Obtaining the discussion-id

You can find your discussion-id and using GitHub's GraphQL Explorer. Replace <REPO_NAME> and <REPO_OWNER> to find the discussion id you wish to comment on.

GraphQL Query

query {
  repository(owner: "<REPO_OWNER>`", name: "cohere") {
    discussions(first: 5) {
      edges {
        node {
          # The value below is the discussion-id
          id
          title
          category {
            id
            name
          }
          body
          id
        }
      }
    }
  }
}

GraphQL Output

{
  "data": {
    "repository": {
      "discussions": {
        "edges": [
          {
            "node": {
              // This is the discussion-id  
              "id": "D_kwdje64ife75s9o",
              "title": "Test Topic Title - Insert Question Here",
              "category": {
                "id": "DIC_kwSWEbhiT23EW-rr",
                "name": "Q&A"
              },
              "body": "This is the body of the discussion topic"
            }
          }
        ]
      }
    }
  }
}

Example

Example workflow can be found here.

Credits

Inspired by: