Wrap PR and discussion titles in toJSON
to escape them in Slack
#1986
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: New PR notification | |
# ℹ️ https://github.com/WordPress/openverse/blob/main/.github/GITHUB.md#new-pr-notification | |
on: | |
pull_request_target: | |
types: | |
- opened | |
- ready_for_review | |
jobs: | |
send_message: | |
name: Send Slack message | |
if: | | |
github.actor != 'dependabot[bot]' && | |
!startsWith(github.event.pull_request.title, '🔄') | |
runs-on: ubuntu-latest | |
env: | |
pr_url: ${{ github.event.pull_request.html_url }} | |
pr_number: ${{ github.event.pull_request.number }} | |
pr_title: ${{ toJSON(github.event.pull_request.title) }} | |
pr_author: ${{ github.event.pull_request.user.login }} | |
pr_repo: ${{ github.event.pull_request.base.repo.full_name }} | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK | |
steps: | |
- name: Send notification for new PR | |
if: github.event.action == 'opened' | |
id: slack | |
uses: slackapi/[email protected] | |
env: | |
pr_status: ${{ github.event.pull_request.draft && ' draft ' || ' ' }} | |
pr_icon: ${{ github.event.pull_request.draft && ':pr-draft:' || ':pull-request:' }} | |
with: | |
payload: | | |
{ | |
"text": "New${{ env.pr_status }}PR opened by ${{ env.pr_author }} in ${{ env.pr_repo }}: #${{ env.pr_number }} - ${{ env.pr_title }}", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "${{ env.pr_icon }} New${{ env.pr_status }}PR opened by *${{ env.pr_author }}* in `${{ env.pr_repo }}`:\n<${{ env.pr_url }}|#${{ env.pr_number }} - ${{ env.pr_title }}>" | |
} | |
} | |
] | |
} | |
- name: Send notification for PR marked ready | |
if: github.event.action == 'ready_for_review' | |
id: slack-notifications | |
uses: slackapi/[email protected] | |
with: | |
payload: | | |
{ | |
"text": "PR by ${{ env.pr_author }} in ${{ env.pr_repo }} marked ready for review: #${{ env.pr_number }} - ${{ env.pr_title }}", | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": ":pull-request: PR by *${{ env.pr_author }}* in `${{ env.pr_repo }}` marked ready for review:\n<${{ env.pr_url }}|#${{ env.pr_number }} - ${{ env.pr_title }}>" | |
} | |
} | |
] | |
} |