-
Notifications
You must be signed in to change notification settings - Fork 15
Use AST parser to validate alt text - markdown-lint #33
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
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9fdf222
Use AST parser to check alt text
kendallgassner d96d4f1
test
kendallgassner 9b301bc
AST with markdownkint
kendallgassner aa50fd7
clean
kendallgassner 87a47bb
bump markdownlint
kendallgassner 5886dc6
bump
kendallgassner 622bdd5
Update src/index.js
kendallgassner e98c1d7
Apply suggestions from code review
kendallgassner 7a71619
Update action.yml
kendallgassner 90cc187
check in nodes
kendallgassner 163e10a
check in nodes
kendallgassner 5ea785d
check in nodes
kendallgassner 71c7b87
check in nodes
kendallgassner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,78 @@ | ||
name: Accessibility alt text bot | ||
description: 'This action will check a repos issue, discussion, or PR for correct alt text usage.' | ||
description: "This action will check a repos issue, discussion, or PR for correct alt text usage." | ||
branding: | ||
icon: 'eye' | ||
color: 'purple' | ||
icon: "eye" | ||
color: "purple" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Runs alt text check and adds comment | ||
run: | | ||
source ${{ github.action_path }}/flag-alt-text.sh | ||
source ${{ github.action_path }}/queries.sh | ||
source ${{ github.action_path }}/queries.sh | ||
|
||
if [ ${{ github.event.comment }} ]; then | ||
content=$COMMENT | ||
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 | ||
if [ ${{ github.event.comment }} ]; then | ||
content=$COMMENT | ||
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 | ||
type=issue_comment | ||
issue_url=${{ github.event.issue.html_url }} | ||
reply_to_id=$comment_node_id | ||
fi | ||
target=${{ github.event.comment.html_url }} | ||
else | ||
if [ ${{ github.event.issue }} ]; then | ||
type=issue_description | ||
content=$ISSUE_BODY | ||
issue_url=${{ github.event.issue.html_url }} | ||
user=${{ github.event.issue.user.login }} | ||
target=" your issue body" | ||
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" | ||
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" | ||
fi | ||
type=issue_comment | ||
issue_url=${{ github.event.issue.html_url }} | ||
fi | ||
target=${{ github.event.comment.html_url }} | ||
else | ||
if [ ${{ github.event.issue }} ]; then | ||
type=issue_description | ||
content=$ISSUE_BODY | ||
issue_url=${{ github.event.issue.html_url }} | ||
user=${{ github.event.issue.user.login }} | ||
target=" your issue body" | ||
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" | ||
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" | ||
fi | ||
message="Uh oh! @$user, the image you shared is missing helpful alt text. Check $target. | ||
fi | ||
npm ci | ||
flag=$(node index.js "$content") | ||
message="Uh oh! @$user, the image you shared is missing helpful alt text. Check $target. | ||
|
||
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. | ||
|
||
Learn more about alt text at [Basic writing and formatting syntax: images on GitHub Docs](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#images)." | ||
flag="$(flagAltText "$content")" | ||
|
||
echo "Detected bad alt text: ${flag}" | ||
echo "Event type: $type" | ||
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. | ||
|
||
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 | ||
fi | ||
Learn more about alt text at [Basic writing and formatting syntax: images on GitHub Docs](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#images)." | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would love if we can eventually move all of this bash logic into a well-tested node script! Out of scope here though :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed!! |
||
fi | ||
fi | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.