Skip to content

Instantly share code, notes, and snippets.

@liushooter
Forked from oleksis/Notes.md
Created March 5, 2022 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liushooter/2cb76ea84fea4d21757a9f5c68f8e528 to your computer and use it in GitHub Desktop.
Save liushooter/2cb76ea84fea4d21757a9f5c68f8e528 to your computer and use it in GitHub Desktop.
Discussion API, Graphql using gh CLI
name: README.md Changed
on:
push:
paths:
- 'README.md'
jobs:
send_notification:
runs-on: ubuntu-latest
steps:
- name: Send notification to README Authors
env:
GITHUB_TOKEN: ${{ secrets.GHP_README_WORKFLOW }}
run: |
BODY='🤓 @willmcgugan @oleksis @Adilius README.md changed 📝'
DISCUSSIONID='MDEwOkRpc2N1c3Npb24zMzI2NzM0'
gh api graphql -H 'GraphQL-Features: discussions_api' -f body="$BODY" -F discussionId="$DISCUSSIONID" -f query='mutation($body: String!, $discussionId: ID!){addDiscussionComment(input:{body: $body , discussionId: $discussionId}){comment{id}}}'

Discussions with category

gh api graphql -H 'GraphQL-Features: discussions_api' -F owner=':owner' -F name=':repo' \
-f query='
query($name: String!, $owner: String!) {
  repository(owner: $owner, name: $name) {
    discussions(first: 1){
      nodes{
        number title body category{id name}
      }
    }
  }
}'

Discussion 322 and comments

gh api graphql -H 'GraphQL-Features: discussions_api' -F owner=':owner' -F name=':repo' \
-f query='query($name: String!, $owner: String!) {
  repository(owner: $owner, name: $name) {
    discussion(number: 1174){
      id title body comments(first:1){ edges{ node{ id body }}}
    }
  }
}'

DiscussionCategories

gh api graphql -H 'GraphQL-Features: discussions_api' -F owner=':owner' -F name=':repo' \
-f query='query($name: String!, $owner: String!) {
  repository(owner: $owner, name: $name) {
    discussionCategories(first: 10) {
      nodes {id name}
    }
  }
}'

Mutation: Reply to discussion comment

gh api graphql -H 'GraphQL-Features: discussions_api' \
-f body='@Adilius We can make Github Action on the README.en.md file change and send a comment on this discussions with the mentioning the interested parties' \
-F discussionId='MDEwOkRpc2N1c3Npb24yMjU2MA==' -F replyToId='MDE3OkRpc2N1c3Npb25Db21tZW50ODk1OTg=' \
-f query='
mutation($body: String!, $discussionId: ID!, $replyToId: ID!){
  addDiscussionComment(input:{body: $body , discussionId: $discussionId, replyToId: $replyToId }){
    comment{id}
  }
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment