Skip to content

Latest commit

 

History

History
144 lines (97 loc) · 8.09 KB

README.md

File metadata and controls

144 lines (97 loc) · 8.09 KB

Mark Discussion Comment Answer 🙋🏻‍♂️💬✅

This GitHub Action marks a discussion comment as the answer

Tests GitHub Workflow Status (with event) GitHub Release Date - Published_At coverage badge GitHub Marketplace GitHub package.json dynamic Dynamic YAML Badge Code Style: prettier Code Linter: ESLint GitHub top language GitHub contributors GitHub Discussions GitHub Release (with filter) GitHub code size in bytes GitHub repo size GitHub package.json dynamic MIT

About

This GitHub action automatically marks discussion comments with the highest number of reactions as the answer.

Usage

In your workflow, to use this github action add a step like this to your workflow:

      - name: Run Mark Discussion Comment Answer
        id: markanswer
        uses: konjoinfinity/[email protected]
        with:
          GH_TOKEN: "${{ secrets.DISCUSS_TOKEN }}" # PAT required for private repos
          reaction_threshold: 3 # Number of reactions required to mark a comment as the answer   
          
Example Output
DC_kwDOKczwv84AbnqH
{
  markDiscussionCommentAsAnswer: {
    clientMutationId: '1234',
    discussion: { id: 'D_kwDOKczwv84AV0aF' }
  }
}
discussionId = {id:D_kwDOKczwv84AV0aF}

Requirements

No extra configuration required to run this GitHub Action.

Inputs

Name Type Description Requried? Default
GH_TOKEN String A GitHub PAT is required, but the default is sufficient for public repos. For private repos, ensure you create a PAT that has discussion: write and repo: write, then store it as an action secret for usage within the workflow. See more details about tokens here - PAT. No "${{ secrets.GITHUB_TOKEN }}"
reaction_threshold Number Number of positive comment reactions required to mark as an answer. (Ex. 3, 10) Positive emoji reactions are: ["+1", "LAUGH", "HEART", "HOORAY", "ROCKET"] No 0

Outputs

Name Description How To Access
discussionId Discussion ID where the marked as answered comment resides. ${{ steps.<your-step>.outputs.discussionId }}
clientMutationId GraphQL Mutation ID for the client. ${{ steps.<your-step>.outputs.clientMutationId }}
commentText Body of the comment with the highest number of positive reactions/emojis. ${{ steps.<your-step>.outputs.commentText }}
reactionThreshold Number of positive reactions/emojis required to mark a comment as the answer. ${{ steps.<your-step>.outputs.reactionThreshold }}
totalReactions Total number of reactions for the comment with the highest number of positive reactions/emojis. ${{ steps.<your-step>.outputs.totalReactions }}
commentId Comment ID for the comment with the highest number of positive reactions/emojis. ${{ steps.<your-step>.outputs.commentId }}

Accessing Outputs

- name: Show Output
  run: |
    echo ${{ steps.<your-step>.outputs.discussionId }}
    echo ${{ steps.<your-step>.outputs.clientMutationId }}
    echo ${{ steps.<your-step>.outputs.commentText }}
    echo ${{ steps.<your-step>.outputs.reactionThreshold }}
    echo ${{ steps.<your-step>.outputs.totalReactions }}
    echo ${{ steps.<your-step>.outputs.commentId }}

Example

Link to workflow

name: Mark Discussion Comment Answer

on:
  discussion_comment:
    types: [created]

jobs:
  mark-comment-answer:
    name: Mark a discussion comment as the answer
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3
        
      - name: Run Mark Discussion Comment Answer
        id: markanswer
        uses: konjoinfinity/[email protected]
        with:
          GH_TOKEN: "${{ secrets.DISCUSS_TOKEN }}" # PAT required for private repos
          reaction_threshold: 3 # Number of reactions required to mark a comment as the answer
          
      - name: Show Mark Answer Output
        run: |
          echo "discussionId = ${{ steps.markanswer.outputs.discussionId }}"
          echo "clientMutationId = ${{ steps.markanswer.outputs.clientMutationId }}"
          echo "commentText = ${{ steps.markanswer.outputs.commentText }}"
          echo "reactionThreshold = ${{ steps.markanswer.outputs.reactionThreshold }}"
          echo "totalReactions = ${{ steps.markanswer.outputs.totalReactions }}"
          echo "commentId = ${{ steps.markanswer.outputs.commentId }}"
Example Output
{
  markDiscussionCommentAsAnswer: {
    clientMutationId: '1234',
    discussion: { id: 'D_kwDOKczwv84AV0aF' }
  }
}

Credits

Inspired by: