From 487b4706eabf791430b74cbd0dc7fbf9fd8f4cb2 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Tue, 30 May 2023 20:57:31 -0400 Subject: [PATCH 1/6] Add support for discussion comment --- .../test-accessibility-alt-text-bot.yml | 2 ++ action.yml | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-accessibility-alt-text-bot.yml b/.github/workflows/test-accessibility-alt-text-bot.yml index bb5d580..eff925f 100644 --- a/.github/workflows/test-accessibility-alt-text-bot.yml +++ b/.github/workflows/test-accessibility-alt-text-bot.yml @@ -8,6 +8,8 @@ on: types: [created, edited] discussion: types: [created, edited] + discussion_comment: + types: [created, edited] jobs: accessibility_alt_text_bot: diff --git a/action.yml b/action.yml index 072d799..00f890d 100644 --- a/action.yml +++ b/action.yml @@ -12,12 +12,17 @@ runs: 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 }}' + reply_to_id='${{ github.event.comment.node_id }}' else type=issue_comment + issue_url=${{ github.event.issue.html_url }} fi target=${{ github.event.comment.html_url }} else @@ -66,6 +71,16 @@ runs: } } ' + elif [[ $type = discussion_comment ]]; 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 + } + } + } + ' fi fi shell: bash From f8f23d6c9eaa02323aa0e9d2b8ca663ff369a785 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Tue, 30 May 2023 22:54:07 -0400 Subject: [PATCH 2/6] Introduce queries helper --- action.yml | 28 +++++++++------------------- queries.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 queries.sh diff --git a/action.yml b/action.yml index 00f890d..6cde934 100644 --- a/action.yml +++ b/action.yml @@ -9,6 +9,7 @@ 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 @@ -19,7 +20,12 @@ runs: elif ${{ github.event.discussion.id != '' }}; then type=discussion_comment discussion_node_id='${{ github.event.discussion.node_id }}' - reply_to_id='${{ github.event.comment.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 }} @@ -62,25 +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 - 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 - } - } - } - ' + addDiscussionCommentAsReply $discussion_node_id $reply_to_id "$message" fi fi shell: bash diff --git a/queries.sh b/queries.sh new file mode 100644 index 0000000..6d6217c --- /dev/null +++ b/queries.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Given a node_id for a Discussion Comment with a parent comment, 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' +} + +# Adds a top-level discussion comment given a discussion node ID and a message. +function addDiscussionComment() { + local DISCUSSION_NODE_ID=$1 + local MESSAGE=$2 + 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 + } + } + } + ' +} + +# Adds a Discussion Comment as a reply to an existing discussion comment given a discussion node ID, discussion comment node ID, and a message. +function addDiscussionCommentAsReply() { + 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=' + mutation($discussionId: ID!, , $replyToId: ID, $body: String!) { + addDiscussionComment(input: {discussionId: $discussionId, replyToId: $replyToId, body: $body}) { + comment { + id + } + } + } + ' +} From 91013ac63ba76abdbcef28f96e5b2c5389e9099c Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Wed, 31 May 2023 08:44:37 -0400 Subject: [PATCH 3/6] Update code comments --- queries.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/queries.sh b/queries.sh index 6d6217c..8f38049 100644 --- a/queries.sh +++ b/queries.sh @@ -1,6 +1,6 @@ #!/bin/bash -# Given a node_id for a Discussion Comment with a parent comment, return the parent comment's node ID. +# 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=' @@ -16,7 +16,7 @@ function getDiscussionReplyToId() { echo $REPLY_TO_DATA | jq -r '.data.node.replyTo.id' } -# Adds a top-level discussion comment given a discussion node ID and a message. +# Given a discussion node ID and a message, adds a top-level discussion comment. function addDiscussionComment() { local DISCUSSION_NODE_ID=$1 local MESSAGE=$2 @@ -31,7 +31,7 @@ function addDiscussionComment() { ' } -# Adds a Discussion Comment as a reply to an existing discussion comment given a discussion node ID, discussion comment node ID, and a message. +# Given a discussion node ID, discussion comment node ID, and a message, adds a discussion comment as a reply in thread. function addDiscussionCommentAsReply() { local DISCUSSION_NODE_ID=$1 local REPLY_TO_ID=$2 From ca6d2c6834b4214d099c7ab6dfd1de8e518e03ce Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Wed, 31 May 2023 08:45:26 -0400 Subject: [PATCH 4/6] Update README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5e3fdcc..719aaf5 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ on: types: [created, edited] discussion: types: [created, edited] + discussion_comment: + types: [created, edited] permissions: issues: write From ad9af45d3a480f82390b283cf5965af571d80548 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Wed, 31 May 2023 12:50:29 -0400 Subject: [PATCH 5/6] Combine helpers into one addDiscussionComment --- action.yml | 2 +- queries.sh | 40 +++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/action.yml b/action.yml index 6cde934..e2c6757 100644 --- a/action.yml +++ b/action.yml @@ -70,7 +70,7 @@ runs: elif [[ $type = discussion_description ]]; then addDiscussionComment $discussion_node_id "$message" elif [[ $type = discussion_comment ]]; then - addDiscussionCommentAsReply $discussion_node_id $reply_to_id "$message" + addDiscussionComment $discussion_node_id "$message" $reply_to_id fi fi shell: bash diff --git a/queries.sh b/queries.sh index 8f38049..a9aedc2 100644 --- a/queries.sh +++ b/queries.sh @@ -16,33 +16,31 @@ function getDiscussionReplyToId() { echo $REPLY_TO_DATA | jq -r '.data.node.replyTo.id' } -# Given a discussion node ID and a message, adds a top-level discussion comment. +# 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 - 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 + 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 + } } } - } - ' -} - -# Given a discussion node ID, discussion comment node ID, and a message, adds a discussion comment as a reply in thread. -function addDiscussionCommentAsReply() { - 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=' - mutation($discussionId: ID!, , $replyToId: ID, $body: String!) { - addDiscussionComment(input: {discussionId: $discussionId, replyToId: $replyToId, body: $body}) { - comment { + ' + 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 } From 438305aa8c5ef95d1d7e56d66696c6625122d5c0 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Wed, 31 May 2023 15:27:32 -0400 Subject: [PATCH 6/6] Update queries.sh Co-authored-by: Kendall Gassner --- queries.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/queries.sh b/queries.sh index a9aedc2..bd6b7d0 100644 --- a/queries.sh +++ b/queries.sh @@ -24,7 +24,7 @@ function addDiscussionComment() { 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!) { + mutation($discussionId: ID!, $replyToId: ID, $body: String!) { addDiscussionComment(input: {discussionId: $discussionId, replyToId: $replyToId, body: $body}) { comment { id