Skip to content
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

Reuse and delete alt-text-bot comment to update lint issues. #55

Merged
merged 3 commits into from
Jan 7, 2025
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
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:
kendallgassner marked this conversation as resolved.
Show resolved Hide resolved
types: [created, edited]
types: [created, edited, deleted]
discussion:
types: [created, edited]
discussion_comment:
types: [created, edited]
types: [created, edited, deleted]
Comment on lines 5 to +12
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this in place so that the alt text comment by the bot can be deleted if the relevant comment is deleted?

EDIT: ooh yeah looks like it!

Copy link
Contributor

Choose a reason for hiding this comment

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

If a consumer upgrades to the new version but forgets to add this, will the action start failing, or will it fail silently?

If it's a breaking change, I wonder if we'd want to bump to major version with a note 🤔.

Let's also update the config in the README!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It shouldn't fail! They just won't get their comments deleted. (I tested this!) AND GOOD CALL i'll add this to the README.


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
Loading