Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test-accessibility-alt-text-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
types: [created, edited]
discussion:
types: [created, edited]
discussion_comment:
types: [created, edited]

jobs:
accessibility_alt_text_bot:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ on:
types: [created, edited]
discussion:
types: [created, edited]
discussion_comment:
types: [created, edited]

permissions:
issues: write
Expand Down
25 changes: 15 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ runs:
- name: Runs alt text check and adds comment
run: |
source ${{ github.action_path }}/flag-alt-text.sh
source ${{ github.action_path }}/queries.sh

if [ ${{ github.event.comment }} ]; then
content=$COMMENT
issue_url=${{ github.event.issue.html_url }}
user=${{ github.event.comment.user.login }}
if ${{ github.event.issue.pull_request.url != '' }}; then
type=pr_comment
issue_url=${{ github.event.issue.html_url }}
elif ${{ github.event.discussion.id != '' }}; then
type=discussion_comment
discussion_node_id='${{ github.event.discussion.node_id }}'
comment_node_id='${{ github.event.comment.node_id }}'
if ${{ github.event.comment.parent_id != '' }}; then
reply_to_id=$(getDiscussionReplyToId $comment_node_id)
else
reply_to_id=$comment_node_id
fi
else
type=issue_comment
issue_url=${{ github.event.issue.html_url }}
fi
target=${{ github.event.comment.html_url }}
else
Expand Down Expand Up @@ -57,15 +68,9 @@ runs:
elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
gh issue comment $issue_url --body "$message"
elif [[ $type = discussion_description ]]; then
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
}
}
}
'
addDiscussionComment $discussion_node_id "$message"
elif [[ $type = discussion_comment ]]; then
addDiscussionComment $discussion_node_id "$message" $reply_to_id
fi
fi
shell: bash
Expand Down
46 changes: 46 additions & 0 deletions queries.sh
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='
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

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
}