-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from github/kh-discussion-comment-support
Add support for discussion comment
- Loading branch information
Showing
4 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
# Given a node_id for a discussion comment that is a reply in thread, return the parent comment's node ID. | ||
function getDiscussionReplyToId() { | ||
local NODE_ID=$1 | ||
local REPLY_TO_DATA=$(gh api graphql -f query=' | ||
query($nodeId: ID!) { | ||
node(id: $nodeId) { | ||
... on DiscussionComment { | ||
replyTo { | ||
id | ||
} | ||
} | ||
} | ||
}' -F nodeId=$NODE_ID) | ||
echo $REPLY_TO_DATA | jq -r '.data.node.replyTo.id' | ||
} | ||
|
||
# Given a discussion node ID, a message, and an optional reply to node ID, adds a discussion comment. | ||
function addDiscussionComment() { | ||
local DISCUSSION_NODE_ID=$1 | ||
local MESSAGE=$2 | ||
local REPLY_TO_ID=$3 | ||
|
||
if [ -n "$REPLY_TO_ID" ]; then | ||
gh api graphql -F discussionId="$DISCUSSION_NODE_ID" -F replyToId="$REPLY_TO_ID" -F body="$MESSAGE" -f query=' | ||
mutation($discussionId: ID!, $replyToId: ID, $body: String!) { | ||
addDiscussionComment(input: {discussionId: $discussionId, replyToId: $replyToId, body: $body}) { | ||
comment { | ||
id | ||
} | ||
} | ||
} | ||
' | ||
else | ||
gh api graphql -F discussionId="$discussion_node_id" -F body="$message" -f query=' | ||
mutation($discussionId: ID!, $body: String!) { | ||
addDiscussionComment(input: {discussionId: $discussionId, body: $body}) { | ||
comment { | ||
id | ||
} | ||
} | ||
} | ||
' | ||
fi | ||
} |