Skip to content

Commit

Permalink
Error handling when sending notification
Browse files Browse the repository at this point in the history
  • Loading branch information
HiraiKyo committed Aug 8, 2024
1 parent ba39489 commit 5d5ce34
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/google-chat-notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ jobs:
PR_URL: ${{ github.event.pull_request.html_url }}
PR_ACTION: ${{ github.event.action }}
run: |
curl -X POST -H "Content-Type: application/json" -d '{
"text": "Pull Request ${{ env.PR_ACTION }}:\n${{ env.PR_TITLE }}\n${{ env.PR_URL }}"
}' ${{ env.WEBHOOK_URL }}
if [ -z "$WEBHOOK_URL" ]; then
echo "Error: WEBHOOK_URL is not set. Please check your GitHub Secrets."
exit 1
fi
MESSAGE="Pull Request $PR_ACTION:\\n$PR_TITLE\\n$PR_URL"
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "Content-Type: application/json" -d "{\"text\": \"$MESSAGE\"}" "$WEBHOOK_URL")
if [ "$RESPONSE" != "200" ]; then
echo "Error: Failed to send notification. HTTP status code: $RESPONSE"
exit 1
else
echo "Notification sent successfully"
fi

0 comments on commit 5d5ce34

Please sign in to comment.