Skip to content

Commit

Permalink
Reuse and delete alt-text-bot comment to update lint issues. (#55)
Browse files Browse the repository at this point in the history
* Reuse and delete alt-text-bot comment to update lint issues.

* update readme

* clean
  • Loading branch information
kendallgassner authored Jan 7, 2025
1 parent 05db932 commit 34208bf
Show file tree
Hide file tree
Showing 29 changed files with 421 additions and 676 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-accessibility-alt-text-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on:
pull_request:
types: [opened, edited]
issue_comment:
types: [created, edited]
types: [created, edited, deleted]
discussion:
types: [created, edited]
discussion_comment:
types: [created, edited]
types: [created, edited, deleted]

jobs:
accessibility_alt_text_bot:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ on:
pull_request:
types: [opened, edited]
issue_comment:
types: [created, edited]
types: [created, edited, deleted]
discussion:
types: [created, edited]
discussion_comment:
types: [created, edited]
types: [created, edited, deleted]

permissions:
issues: write
Expand Down
63 changes: 48 additions & 15 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ runs:
if [ ${{ github.event.comment }} ]; then
content=$COMMENT
user=${{ github.event.comment.user.login }}
target_id=${{ github.event.comment.id }}
if ${{ github.event.issue.pull_request.url != '' }}; then
type=pr_comment
issue_url=${{ github.event.issue.html_url }}
bot_comment_id=$(gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments | jq -r '.[] | select(.user.login == "github-actions[bot]") | select(.body | test("<div alt-text-bot-id=\"${{ github.event.comment.id }}\"")) | .id')
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 }}'
bot_comment_id=$(gh api repos/${{ github.repository }}/discussions/${{ github.event.discussion.number }}/comments | jq -r '.[] | select(.user.login == "github-actions[bot]") | select(.body | test("<div alt-text-bot-id=\"${{ github.event.comment.id }}\"")) | .node_id')
if ${{ github.event.comment.parent_id != '' }}; then
reply_to_id=$(getDiscussionReplyToId $comment_node_id)
else
Expand All @@ -28,6 +31,7 @@ runs:
else
type=issue_comment
issue_url=${{ github.event.issue.html_url }}
bot_comment_id=$(gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments | jq -r '.[] | select(.user.login == "github-actions[bot]") | select(.body | test("<div alt-text-bot-id=\"${{ github.event.comment.id }}\"")) | .id')
fi
target=${{ github.event.comment.html_url }}
else
Expand All @@ -36,23 +40,31 @@ runs:
content=$ISSUE_BODY
issue_url=${{ github.event.issue.html_url }}
user=${{ github.event.issue.user.login }}
target=" your issue body"
target="your issue body"
target_id=${{ github.event.issue.id }}
bot_comment_id=$(gh api repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments | jq -r '.[] | select(.user.login == "github-actions[bot]") | select(.body | test("<div alt-text-bot-id=\"${{ github.event.issue.id }}\"")) | .id')
elif [ ${{ github.event.pull_request }} ]; then
type=pr_description
content=$PR_BODY
issue_url=${{ github.event.pull_request.html_url }}
user=${{ github.event.pull_request.user.login }}
target=" your pull request body"
target="your pull request body"
target_id=${{ github.event.pull_request.id }}
bot_comment_id=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments | jq -r '.[] | select(.user.login == "github-actions[bot]") | select(.body | test("<div alt-text-bot-id=\"${{ github.event.pull_request.id }}\"")) | .id')
elif [ ${{ github.event.discussion }} ]; then
type=discussion_description
content=$DISCUSSION_BODY
discussion_node_id='${{ github.event.discussion.node_id }}'
user=${{ github.event.discussion.user.login }}
target=" your discussion body"
target="your discussion body"
target_id=${{ github.event.discussion.id }}
bot_comment_id=$(gh api repos/${{ github.repository }}/discussions/${{ github.event.discussion.number }}/comments | jq -r '.[] | select(.user.login == "github-actions[bot]") | select(.body | test("<div alt-text-bot-id=\"${{ github.event.discussion.id }}\"")) | .node_id')
fi
fi
flag=$(node ${{ github.action_path }}/src/index.js "$content")
message="Uh oh! @$user, the image you shared is missing helpful alt text. Check $target.
flag=$(node ${{ github.action_path }}/src/index.js "$content")
message="<div alt-text-bot-id=\"$target_id\" /> Uh oh! @$user, at least one image you shared is missing helpful alt text. Check $target to fix the following violations:
$flag
Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.
Expand All @@ -63,16 +75,37 @@ runs:
echo "Detected bad alt text: ${flag}"
echo "Event type: $type"
if [[ $flag = true ]]; then
if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
gh pr comment $issue_url --body "$message"
elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
gh issue comment $issue_url --body "$message"
elif [[ $type = discussion_description ]]; then
addDiscussionComment $discussion_node_id "$message"
elif [[ $type = discussion_comment ]]; then
addDiscussionComment $discussion_node_id "$message" $reply_to_id
if [[ $flag && ${{ github.event.action }} != 'deleted' ]]; then
if [ $bot_comment_id ]; then
if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
gh api repos/${{ github.repository }}/issues/comments/$bot_comment_id -X PATCH -f body="$message"
elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
gh api repos/${{ github.repository }}/issues/comments/$bot_comment_id -X PATCH -f body="$message"
elif [[ $type = discussion_description ]] || [[ $type = discussion_comment ]]; then
gh api graphql -f query='mutation($commentId: ID!, $body: String!) { updateDiscussionComment(input: {commentId: $commentId, body: $body}) { comment { id body }}}' -f commentId=$bot_comment_id -f body="$message"
fi
else
if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
gh pr comment $issue_url --body "$message"
elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
gh issue comment $issue_url --body "$message"
elif [[ $type = discussion_description ]]; then
addDiscussionComment $discussion_node_id "$message"
elif [[ $type = discussion_comment ]]; then
addDiscussionComment $discussion_node_id "$message" $reply_to_id
fi
fi
else
echo "bot_comment_id: $bot_comment_id"
if [ $bot_comment_id ]; then
echo "Deleting bot comment..."
if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
gh api -X DELETE /repos/${{ github.repository }}/issues/comments/$bot_comment_id
elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
gh api -X DELETE /repos/${{ github.repository }}/issues/comments/$bot_comment_id
elif [[ $type = discussion_description ]] || [[ $type = discussion_comment ]]; then
gh api graphql -f query='mutation($id: ID!) { deleteDiscussionComment(input: {id: $id}) { clientMutationId } }' -f id=$bot_comment_id
fi
fi
fi
shell: bash
Expand Down
28 changes: 14 additions & 14 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

184 changes: 0 additions & 184 deletions node_modules/braces/CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion node_modules/braces/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 34208bf

Please sign in to comment.