@@ -13,13 +13,16 @@ runs:
13
13
if [ ${{ github.event.comment }} ]; then
14
14
content=$COMMENT
15
15
user=${{ github.event.comment.user.login }}
16
+ target_id=${{ github.event.comment.id }}
16
17
if ${{ github.event.issue.pull_request.url != '' }}; then
17
18
type=pr_comment
18
19
issue_url=${{ github.event.issue.html_url }}
20
+ 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')
19
21
elif ${{ github.event.discussion.id != '' }}; then
20
22
type=discussion_comment
21
23
discussion_node_id='${{ github.event.discussion.node_id }}'
22
24
comment_node_id='${{ github.event.comment.node_id }}'
25
+ 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')
23
26
if ${{ github.event.comment.parent_id != '' }}; then
24
27
reply_to_id=$(getDiscussionReplyToId $comment_node_id)
25
28
else
28
31
else
29
32
type=issue_comment
30
33
issue_url=${{ github.event.issue.html_url }}
34
+ 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')
31
35
fi
32
36
target=${{ github.event.comment.html_url }}
33
37
else
@@ -36,23 +40,31 @@ runs:
36
40
content=$ISSUE_BODY
37
41
issue_url=${{ github.event.issue.html_url }}
38
42
user=${{ github.event.issue.user.login }}
39
- target=" your issue body"
43
+ target="your issue body"
44
+ target_id=${{ github.event.issue.id }}
45
+ 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')
40
46
elif [ ${{ github.event.pull_request }} ]; then
41
47
type=pr_description
42
48
content=$PR_BODY
43
49
issue_url=${{ github.event.pull_request.html_url }}
44
50
user=${{ github.event.pull_request.user.login }}
45
- target=" your pull request body"
51
+ target="your pull request body"
52
+ target_id=${{ github.event.pull_request.id }}
53
+ 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')
46
54
elif [ ${{ github.event.discussion }} ]; then
47
55
type=discussion_description
48
56
content=$DISCUSSION_BODY
49
57
discussion_node_id='${{ github.event.discussion.node_id }}'
50
58
user=${{ github.event.discussion.user.login }}
51
- target=" your discussion body"
59
+ target="your discussion body"
60
+ target_id=${{ github.event.discussion.id }}
61
+ 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')
52
62
fi
53
63
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.
64
+ flag=$(node ${{ github.action_path }}/src/index.js "$content")
65
+ 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:
66
+
67
+ $flag
56
68
57
69
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
70
@@ -63,16 +75,37 @@ runs:
63
75
64
76
echo "Detected bad alt text: ${flag}"
65
77
echo "Event type: $type"
66
-
67
- if [[ $flag = true ]]; then
68
- if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
69
- gh pr comment $issue_url --body "$message"
70
- elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
71
- gh issue comment $issue_url --body "$message"
72
- elif [[ $type = discussion_description ]]; then
73
- addDiscussionComment $discussion_node_id "$message"
74
- elif [[ $type = discussion_comment ]]; then
75
- addDiscussionComment $discussion_node_id "$message" $reply_to_id
78
+ if [[ $flag && ${{ github.event.action }} != 'deleted' ]]; then
79
+ if [ $bot_comment_id ]; then
80
+ if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
81
+ gh api repos/${{ github.repository }}/issues/comments/$bot_comment_id -X PATCH -f body="$message"
82
+ elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
83
+ gh api repos/${{ github.repository }}/issues/comments/$bot_comment_id -X PATCH -f body="$message"
84
+ elif [[ $type = discussion_description ]] || [[ $type = discussion_comment ]]; then
85
+ 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"
86
+ fi
87
+ else
88
+ if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
89
+ gh pr comment $issue_url --body "$message"
90
+ elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
91
+ gh issue comment $issue_url --body "$message"
92
+ elif [[ $type = discussion_description ]]; then
93
+ addDiscussionComment $discussion_node_id "$message"
94
+ elif [[ $type = discussion_comment ]]; then
95
+ addDiscussionComment $discussion_node_id "$message" $reply_to_id
96
+ fi
97
+ fi
98
+ else
99
+ echo "bot_comment_id: $bot_comment_id"
100
+ if [ $bot_comment_id ]; then
101
+ echo "Deleting bot comment..."
102
+ if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
103
+ gh api -X DELETE /repos/${{ github.repository }}/issues/comments/$bot_comment_id
104
+ elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
105
+ gh api -X DELETE /repos/${{ github.repository }}/issues/comments/$bot_comment_id
106
+ elif [[ $type = discussion_description ]] || [[ $type = discussion_comment ]]; then
107
+ gh api graphql -f query='mutation($id: ID!) { deleteDiscussionComment(input: {id: $id}) { clientMutationId } }' -f id=$bot_comment_id
108
+ fi
76
109
fi
77
110
fi
78
111
shell : bash
0 commit comments