Skip to content

Commit 602a5ef

Browse files
Use AST parser to validate alt text - markdown-lint (#33)
* Use AST parser to check alt text * test * AST with markdownkint * clean * bump markdownlint * bump * Update src/index.js * Apply suggestions from code review * Update action.yml * check in nodes * check in nodes * check in nodes * check in nodes
1 parent b5828a5 commit 602a5ef

File tree

9,715 files changed

+686959
-951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

9,715 files changed

+686959
-951
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ jobs:
1111
steps:
1212
- name: Checkout repo
1313
uses: actions/checkout@v3
14+
- name: Install dependencies
15+
run: npm ci
1416
- name: Run test
15-
shell: bash
16-
run: |
17-
ls
18-
./test-flag-alt-text.sh
17+
run: npm run test

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
.DS_Store
2-
.env
3-
/node_modules
2+
.env

action.yml

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,77 @@
11
name: Accessibility alt text bot
2-
description: 'This action will check a repos issue, discussion, or PR for correct alt text usage.'
2+
description: "This action will check a repos issue, discussion, or PR for correct alt text usage."
33
branding:
4-
icon: 'eye'
5-
color: 'purple'
4+
icon: "eye"
5+
color: "purple"
66
runs:
77
using: "composite"
88
steps:
99
- name: Runs alt text check and adds comment
1010
run: |
11-
source ${{ github.action_path }}/flag-alt-text.sh
12-
source ${{ github.action_path }}/queries.sh
11+
source ${{ github.action_path }}/queries.sh
1312
14-
if [ ${{ github.event.comment }} ]; then
15-
content=$COMMENT
16-
user=${{ github.event.comment.user.login }}
17-
if ${{ github.event.issue.pull_request.url != '' }}; then
18-
type=pr_comment
19-
issue_url=${{ github.event.issue.html_url }}
20-
elif ${{ github.event.discussion.id != '' }}; then
21-
type=discussion_comment
22-
discussion_node_id='${{ github.event.discussion.node_id }}'
23-
comment_node_id='${{ github.event.comment.node_id }}'
24-
if ${{ github.event.comment.parent_id != '' }}; then
25-
reply_to_id=$(getDiscussionReplyToId $comment_node_id)
26-
else
27-
reply_to_id=$comment_node_id
28-
fi
13+
if [ ${{ github.event.comment }} ]; then
14+
content=$COMMENT
15+
user=${{ github.event.comment.user.login }}
16+
if ${{ github.event.issue.pull_request.url != '' }}; then
17+
type=pr_comment
18+
issue_url=${{ github.event.issue.html_url }}
19+
elif ${{ github.event.discussion.id != '' }}; then
20+
type=discussion_comment
21+
discussion_node_id='${{ github.event.discussion.node_id }}'
22+
comment_node_id='${{ github.event.comment.node_id }}'
23+
if ${{ github.event.comment.parent_id != '' }}; then
24+
reply_to_id=$(getDiscussionReplyToId $comment_node_id)
2925
else
30-
type=issue_comment
31-
issue_url=${{ github.event.issue.html_url }}
26+
reply_to_id=$comment_node_id
3227
fi
33-
target=${{ github.event.comment.html_url }}
3428
else
35-
if [ ${{ github.event.issue }} ]; then
36-
type=issue_description
37-
content=$ISSUE_BODY
38-
issue_url=${{ github.event.issue.html_url }}
39-
user=${{ github.event.issue.user.login }}
40-
target=" your issue body"
41-
elif [ ${{ github.event.pull_request }} ]; then
42-
type=pr_description
43-
content=$PR_BODY
44-
issue_url=${{ github.event.pull_request.html_url }}
45-
user=${{ github.event.pull_request.user.login }}
46-
target=" your pull request body"
47-
elif [ ${{ github.event.discussion }} ]; then
48-
type=discussion_description
49-
content=$DISCUSSION_BODY
50-
discussion_node_id='${{ github.event.discussion.node_id }}'
51-
user=${{ github.event.discussion.user.login }}
52-
target=" your discussion body"
53-
fi
29+
type=issue_comment
30+
issue_url=${{ github.event.issue.html_url }}
31+
fi
32+
target=${{ github.event.comment.html_url }}
33+
else
34+
if [ ${{ github.event.issue }} ]; then
35+
type=issue_description
36+
content=$ISSUE_BODY
37+
issue_url=${{ github.event.issue.html_url }}
38+
user=${{ github.event.issue.user.login }}
39+
target=" your issue body"
40+
elif [ ${{ github.event.pull_request }} ]; then
41+
type=pr_description
42+
content=$PR_BODY
43+
issue_url=${{ github.event.pull_request.html_url }}
44+
user=${{ github.event.pull_request.user.login }}
45+
target=" your pull request body"
46+
elif [ ${{ github.event.discussion }} ]; then
47+
type=discussion_description
48+
content=$DISCUSSION_BODY
49+
discussion_node_id='${{ github.event.discussion.node_id }}'
50+
user=${{ github.event.discussion.user.login }}
51+
target=" your discussion body"
5452
fi
55-
message="Uh oh! @$user, the image you shared is missing helpful alt text. Check $target.
53+
fi
54+
flag=$(node ${{ github.action_path }}/src/index.js "$content")
55+
message="Uh oh! @$user, the image you shared is missing helpful alt text. Check $target.
5656
57-
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.
58-
59-
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)."
60-
flag="$(flagAltText "$content")"
61-
62-
echo "Detected bad alt text: ${flag}"
63-
echo "Event type: $type"
57+
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.
6458
65-
if [[ $flag = true ]]; then
66-
if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
67-
gh pr comment $issue_url --body "$message"
68-
elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
69-
gh issue comment $issue_url --body "$message"
70-
elif [[ $type = discussion_description ]]; then
71-
addDiscussionComment $discussion_node_id "$message"
72-
elif [[ $type = discussion_comment ]]; then
73-
addDiscussionComment $discussion_node_id "$message" $reply_to_id
74-
fi
59+
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)."
60+
61+
echo "Detected bad alt text: ${flag}"
62+
echo "Event type: $type"
63+
64+
if [[ $flag = true ]]; then
65+
if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
66+
gh pr comment $issue_url --body "$message"
67+
elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
68+
gh issue comment $issue_url --body "$message"
69+
elif [[ $type = discussion_description ]]; then
70+
addDiscussionComment $discussion_node_id "$message"
71+
elif [[ $type = discussion_comment ]]; then
72+
addDiscussionComment $discussion_node_id "$message" $reply_to_id
7573
fi
74+
fi
7675
shell: bash
7776
env:
7877
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)