Skip to content

Commit

Permalink
Merge pull request #14 from github/kh-add-discussion-support
Browse files Browse the repository at this point in the history
Add support for validating discussion description
  • Loading branch information
khiga8 authored May 22, 2023
2 parents 81a448e + 2666605 commit 0a70e40
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test-accessibility-alt-text-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ on:
types: [opened, edited]
issue_comment:
types: [created, edited]
discussion:
types: [created, edited]

jobs:
accessibility_alt_text_bot:
name: Check alt text is set on issue or pull requests
runs-on: ubuntu-latest
if: ${{ github.event.issue || github.event.pull_request && github.event.comment.user.login != 'accessibility-bot' }}
if: ${{ github.event.issue || github.event.pull_request || github.event.discussion && github.event.comment.user.login != 'accessibility-bot' }}
steps:
- name: Check alt text
uses: github/accessibility-alt-text-bot@main
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Accessibility-alt-text-bot

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).
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).
Alternative text helps convey the context of the image to those who use assistive technologies such as a screen reader and removes accessibility barriers.

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

jobs:
accessibility_alt_text_bot:
name: Check alt text is set on issue or pull requests
runs-on: ubuntu-latest
if: ${{ github.event.issue || github.event.pull_request }}
if: ${{ github.event.issue || github.event.pull_request || github.event.discussion }}
steps:
- name: Get action 'github/accessibility-alt-text-bot'
uses: github/accessibility-alt-text-bot
Expand Down Expand Up @@ -83,4 +85,4 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
73 changes: 50 additions & 23 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Accessibility alt text bot
description: 'This action will check a repos issue and pr comments 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'
Expand All @@ -11,35 +11,61 @@ runs:
source ${{ github.action_path }}/flag-alt-text.sh
if [ ${{ github.event.comment }} ]; then
comment=$COMMENT
issue=${{ github.event.issue.html_url }}
comment_owner=${{ github.event.comment.user.login }}
is_pr=${{ github.event.issue.pull_request.url != '' }}
content=$COMMENT
issue_url=${{ github.event.issue.html_url }}
user=${{ github.event.comment.user.login }}
if ${{ github.event.issue.pull_request.url != '' }}; then
type=pr_comment
else
type=issue_comment
fi
target=${{ github.event.comment.html_url }}
elif [ ${{ github.event.issue && !github.event.comment }} ]; then
comment=$ISSUE_BODY
issue=${{ github.event.issue.html_url }}
comment_owner=${{ github.event.issue.user.login }}
is_pr=false
target=" your issue body"
elif [ ${{ github.event.pull_request && !github.event.comment }} ]; then
comment=$PR_BODY
issue=${{ github.event.pull_request.html_url }}
comment_owner=${{ github.event.pull_request.user.login }}
is_pr=true
target=" your pull request body"
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
message="Uh oh! @$comment_owner, the image you shared is missing helpful alt text. Check $target.
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 "$comment")"
flag="$(flagAltText "$content")"
echo $flag
echo $type
if [[ $flag = true ]]; then
if [[ $is_pr = true ]]; then
gh pr comment $issue --body "$message"
else
gh issue comment $issue --body "$message"
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
gh api graphql -F discussionId="$discussion_node_id" -F body="$message" -f query='
mutation($discussionId: ID!, $body: String!) {
addDiscussionComment(input: {discussionId: $discussionId, body: $body}) {
comment {
id
}
}
}
'
fi
fi
shell: bash
Expand All @@ -48,3 +74,4 @@ runs:
COMMENT: ${{ github.event.comment.body }}
ISSUE_BODY: ${{ github.event.issue.body }}
PR_BODY: ${{ github.event.pull_request.body }}
DISCUSSION_BODY: ${{ github.event.discussion.body }}

0 comments on commit 0a70e40

Please sign in to comment.