Skip to content

Commit 0a70e40

Browse files
authored
Merge pull request #14 from github/kh-add-discussion-support
Add support for validating discussion description
2 parents 81a448e + 2666605 commit 0a70e40

File tree

3 files changed

+58
-27
lines changed

3 files changed

+58
-27
lines changed

.github/workflows/test-accessibility-alt-text-bot.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ on:
66
types: [opened, edited]
77
issue_comment:
88
types: [created, edited]
9+
discussion:
10+
types: [created, edited]
911

1012
jobs:
1113
accessibility_alt_text_bot:
1214
name: Check alt text is set on issue or pull requests
1315
runs-on: ubuntu-latest
14-
if: ${{ github.event.issue || github.event.pull_request && github.event.comment.user.login != 'accessibility-bot' }}
16+
if: ${{ github.event.issue || github.event.pull_request || github.event.discussion && github.event.comment.user.login != 'accessibility-bot' }}
1517
steps:
1618
- name: Check alt text
1719
uses: github/accessibility-alt-text-bot@main

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Accessibility-alt-text-bot
22

3-
This action supports accessible content sharing on GitHub by leaving an automated reminder whenever an image is shared on a GitHub Issue or Pull request without meaningful alternative text (alt text).
3+
This action supports accessible content sharing on GitHub by leaving an automated reminder whenever an image is shared on a GitHub Issue, Pull request, or Discussion without meaningful alternative text (alt text).
44
Alternative text helps convey the context of the image to those who use assistive technologies such as a screen reader and removes accessibility barriers.
55

66
For guidance on setting alternative text, see [Alternative text for images on Primer](https://primer.style/design/guides/accessibility/alternative-text-for-images).
@@ -24,12 +24,14 @@ on:
2424
types: [opened, edited]
2525
issue_comment:
2626
types: [created, edited]
27+
discussion:
28+
types: [created, edited]
2729

2830
jobs:
2931
accessibility_alt_text_bot:
3032
name: Check alt text is set on issue or pull requests
3133
runs-on: ubuntu-latest
32-
if: ${{ github.event.issue || github.event.pull_request }}
34+
if: ${{ github.event.issue || github.event.pull_request || github.event.discussion }}
3335
steps:
3436
- name: Get action 'github/accessibility-alt-text-bot'
3537
uses: github/accessibility-alt-text-bot
@@ -83,4 +85,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
8385
8486
<!-- ALL-CONTRIBUTORS-LIST:END -->
8587
86-
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
88+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

action.yml

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Accessibility alt text bot
2-
description: 'This action will check a repos issue and pr comments for correct alt text usage.'
2+
description: 'This action will check a repos issue, discussion, or PR for correct alt text usage.'
33
branding:
44
icon: 'eye'
55
color: 'purple'
@@ -11,35 +11,61 @@ runs:
1111
source ${{ github.action_path }}/flag-alt-text.sh
1212
1313
if [ ${{ github.event.comment }} ]; then
14-
comment=$COMMENT
15-
issue=${{ github.event.issue.html_url }}
16-
comment_owner=${{ github.event.comment.user.login }}
17-
is_pr=${{ github.event.issue.pull_request.url != '' }}
14+
content=$COMMENT
15+
issue_url=${{ github.event.issue.html_url }}
16+
user=${{ github.event.comment.user.login }}
17+
if ${{ github.event.issue.pull_request.url != '' }}; then
18+
type=pr_comment
19+
else
20+
type=issue_comment
21+
fi
1822
target=${{ github.event.comment.html_url }}
19-
elif [ ${{ github.event.issue && !github.event.comment }} ]; then
20-
comment=$ISSUE_BODY
21-
issue=${{ github.event.issue.html_url }}
22-
comment_owner=${{ github.event.issue.user.login }}
23-
is_pr=false
24-
target=" your issue body"
25-
elif [ ${{ github.event.pull_request && !github.event.comment }} ]; then
26-
comment=$PR_BODY
27-
issue=${{ github.event.pull_request.html_url }}
28-
comment_owner=${{ github.event.pull_request.user.login }}
29-
is_pr=true
30-
target=" your pull request body"
23+
else
24+
if [ ${{ github.event.issue }} ]; then
25+
type=issue_description
26+
content=$ISSUE_BODY
27+
issue_url=${{ github.event.issue.html_url }}
28+
user=${{ github.event.issue.user.login }}
29+
target=" your issue body"
30+
elif [ ${{ github.event.pull_request }} ]; then
31+
type=pr_description
32+
content=$PR_BODY
33+
issue_url=${{ github.event.pull_request.html_url }}
34+
user=${{ github.event.pull_request.user.login }}
35+
target=" your pull request body"
36+
elif [ ${{ github.event.discussion }} ]; then
37+
type=discussion_description
38+
content=$DISCUSSION_BODY
39+
discussion_node_id='${{ github.event.discussion.node_id }}'
40+
user=${{ github.event.discussion.user.login }}
41+
target=" your discussion body"
42+
fi
3143
fi
32-
message="Uh oh! @$comment_owner, the image you shared is missing helpful alt text. Check $target.
44+
message="Uh oh! @$user, the image you shared is missing helpful alt text. Check $target.
3345
3446
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.
3547
3648
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)."
37-
flag="$(flagAltText "$comment")"
49+
flag="$(flagAltText "$content")"
50+
51+
echo $flag
52+
echo $type
53+
3854
if [[ $flag = true ]]; then
39-
if [[ $is_pr = true ]]; then
40-
gh pr comment $issue --body "$message"
41-
else
42-
gh issue comment $issue --body "$message"
55+
if [[ $type = pr_comment ]] || [[ $type = pr_description ]]; then
56+
gh pr comment $issue_url --body "$message"
57+
elif [[ $type = issue_comment ]] || [[ $type = issue_description ]]; then
58+
gh issue comment $issue_url --body "$message"
59+
elif [[ $type = discussion_description ]]; then
60+
gh api graphql -F discussionId="$discussion_node_id" -F body="$message" -f query='
61+
mutation($discussionId: ID!, $body: String!) {
62+
addDiscussionComment(input: {discussionId: $discussionId, body: $body}) {
63+
comment {
64+
id
65+
}
66+
}
67+
}
68+
'
4369
fi
4470
fi
4571
shell: bash
@@ -48,3 +74,4 @@ runs:
4874
COMMENT: ${{ github.event.comment.body }}
4975
ISSUE_BODY: ${{ github.event.issue.body }}
5076
PR_BODY: ${{ github.event.pull_request.body }}
77+
DISCUSSION_BODY: ${{ github.event.discussion.body }}

0 commit comments

Comments
 (0)