Skip to content

Add support for discussion comment #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 31, 2023
Merged

Conversation

khiga8
Copy link
Contributor

@khiga8 khiga8 commented May 31, 2023

Fixes: #11

This PR adds support for discussion comments. Because the action.yml is getting big, I introduced a queries.sh file to move the GraphQL calls into, including the mutation call we introduced in #14.

We are using the addDiscussionComment and setting the replyToId to post a comment as a reply in a thread.

When replying to a top-level discussion comment, we're able to use github.event.comment.node_id as the replyToId to post a reply successfully.

However, I ran into issues making the same call when replying to a discussion comment inside of a thread. I kept running into the error:

gh: Parent comment is already in a thread, cannot reply to it

I discovered that replyToId has to be a top-level/parent comment node id. Since the github.event.comment.node_id only contains the node ID of the comment we're replying to, we must make a GraphQL query to get the parent comment node ID. We do that in the function getDiscussionReplyToId.

@khiga8 khiga8 requested a review from kendallgassner May 31, 2023 13:10
@khiga8 khiga8 marked this pull request as ready for review May 31, 2023 13:10
@khiga8 khiga8 requested a review from a team as a code owner May 31, 2023 13:10
@accessibility-bot
Copy link
Collaborator

👋 Hello and thanks for pinging us! You've entered our first responder queue. An accessibility first responder will review this soon.

  • 💻 On PRs for our review: please provide a review environment with steps to validate, screenshots (with alt text), or videos demonstrating functionality we should be checking. This will help speed up our review and feedback cycle.
  • ⚠️ If this is urgent, please visit us in #accessibility on Slack and tag the first responder(s) listed in the channel topic.

queries.sh Outdated
local DISCUSSION_NODE_ID=$1
local REPLY_TO_ID=$2
local MESSAGE=$3
gh api graphql -F discussionId="$DISCUSSION_NODE_ID" -F replyToId="$REPLY_TO_ID" -F body="$MESSAGE" -f query='
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to combine addDiscussionComment and addDiscussionCommentAsReply and just leave replyToId as undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ad9af45! :)

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='
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! I meant could you do something like this:

if [ -n $REPLY_TO_ID ]; then; else REPLY="$REPLY_TO_ID"; fi
gh api graphql -F discussionId="$DISCUSSION_NODE_ID" -F replyToId=$REPLY -F body="$MESSAGE" -f query='
      mutation($discussionId: ID!, , $replyToId: ID, $body: String!) {
          addDiscussionComment(input: {discussionId: $discussionId, replyToId: $replyToId, body: $body}) {
          comment {
              id
          }
        }
      }
    '

^ I think the var can be passed in as null on graphql

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: the if statement only is used to add "" around REPLY_TO_ID if it is not null.

Copy link
Contributor Author

@khiga8 khiga8 May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. I think I tried this before and ran into a GraphQL error. Let me try again to confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We run into the following error, so I think we need to stick with two separate calls.

gh: Could not resolve to a node with the global id of ''
{"data":{"addDiscussionComment":null},"errors":[{"type":"NOT_FOUND","path":["addDiscussionComment"],"locations":[{"line":3,"column":9}],"message":"Could not resolve to a node with the global id of ''"}]}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh weird it auto resolves it to an empty string.

Co-authored-by: Kendall Gassner <kendallgassner@github.com>
@khiga8 khiga8 requested a review from kendallgassner May 31, 2023 19:30
Copy link
Collaborator

@kendallgassner kendallgassner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@khiga8 khiga8 merged commit fa169a7 into main May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[accessibility-alt-text-bot] Support for Discussions
3 participants