|
9 | 9 | notify_slack_on_issue: |
10 | 10 | runs-on: ubuntu-latest |
11 | 11 | steps: |
12 | | - - name: Send Slack Notification for New Issue |
| 12 | + - name: Send Slack Notification |
13 | 13 | env: |
14 | | - ISSUE_TITLE: ${{ github.event.issue.title }} |
15 | | - ISSUE_USER: ${{ github.event.issue.user.login }} |
16 | | - ISSUE_URL: ${{ github.event.issue.html_url }} |
| 14 | + # We use || to ensure this works for both 'issues' and 'pull_request' events |
| 15 | + EVENT_TITLE: ${{ github.event.issue.title || github.event.pull_request.title }} |
| 16 | + EVENT_USER: ${{ github.event.issue.user.login || github.event.pull_request.user.login }} |
| 17 | + EVENT_URL: ${{ github.event.issue.html_url || github.event.pull_request.html_url }} |
17 | 18 | REPO_NAME: ${{ github.repository }} |
18 | 19 | SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} |
19 | 20 | run: | |
20 | | - # Build message text using jq to safely handle user input |
21 | | - MESSAGE_TEXT=$(jq -n \ |
22 | | - --arg repo "$REPO_NAME" \ |
23 | | - --arg title "$ISSUE_TITLE" \ |
24 | | - --arg user "$ISSUE_USER" \ |
25 | | - --arg url "$ISSUE_URL" \ |
26 | | - "📢 @DevDocs a PR was opened or issue created in \($repo)\n*Title:* \($title)\n*By:* \($user)\n*URL:* \($url)" |
27 | | - }') |
28 | | -
|
29 | | - # Build Slack payload |
| 21 | + # Build Slack payload safely in one step to avoid quoting errors |
30 | 22 | SLACK_PAYLOAD=$(jq -n \ |
31 | | - --arg text "$MESSAGE_TEXT" \ |
| 23 | + --arg repo "$REPO_NAME" \ |
| 24 | + --arg title "$EVENT_TITLE" \ |
| 25 | + --arg user "$EVENT_USER" \ |
| 26 | + --arg url "$EVENT_URL" \ |
32 | 27 | '{ |
33 | 28 | "channel": "#docs-devdocs-notifications", |
34 | 29 | "username": "Issue Notifier", |
35 | 30 | "icon_emoji": ":mega:", |
36 | | - "text": $text |
| 31 | + "text": "📢 @DevDocs a PR was opened or issue created in \($repo)\n*Title:* \($title)\n*By:* \($user)\n*URL:* \($url)" |
37 | 32 | }') |
38 | 33 |
|
39 | 34 | # Send to Slack |
|
0 commit comments