-
Notifications
You must be signed in to change notification settings - Fork 14
/
action.yml
84 lines (78 loc) · 3.8 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Accessibility alt text bot
description: "This action will check a repos issue, discussion, or PR for correct alt text usage."
branding:
icon: "eye"
color: "purple"
runs:
using: "composite"
steps:
- name: Runs alt text check and adds comment
run: |
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
else
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
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.
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).
> 🤖 Beep boop! This comment was added automatically by [github/accessibility-alt-text-bot](https://github.com/github/accessibility-alt-text-bot).
"
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
fi
fi
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
COMMENT: ${{ github.event.comment.body }}
ISSUE_BODY: ${{ github.event.issue.body }}
PR_BODY: ${{ github.event.pull_request.body }}
DISCUSSION_BODY: ${{ github.event.discussion.body }}