-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e8efa0
commit 9b266ed
Showing
5 changed files
with
169 additions
and
38 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Discord Notification | ||
description: Send Discord Notification | ||
|
||
inputs: | ||
TYPE: | ||
description: "Embed Type" | ||
required: false | ||
TITLE: | ||
description: "Title" | ||
required: false | ||
DESCRIPTION: | ||
description: "Description" | ||
required: false | ||
AUTHOR_NAME: | ||
description: "Author Name" | ||
required: false | ||
AUTHOR_URL: | ||
description: "Author URL" | ||
required: false | ||
AUTHOR_ICON_URL: | ||
description: "Author Icon URL" | ||
required: false | ||
DISCORD_WEBHOOK_URL: | ||
description: "Discord Webhook URL" | ||
required: true | ||
|
||
runs: | ||
using: "composite" | ||
|
||
steps: | ||
- name: Send Discord Notification | ||
shell: bash | ||
run: | | ||
if [ "${{ inputs.TYPE }}" == "success" ]; then | ||
COLOR=5763207 | ||
elif [ "${{ inputs.TYPE }}" == "failure" ]; then | ||
COLOR=15548997 | ||
elif [ "${{ inputs.TYPE }}" == "info" ]; then | ||
COLOR=1752301 | ||
else | ||
COLOR=9868950 | ||
fi | ||
PAYLOAD=$(cat <<EOF | ||
{ | ||
"avatar_url": "https://raw.githubusercontent.com/daodaoedu/daodao-f2e/main/public/daodao-logo.webp", | ||
"username": "島島阿學", | ||
"embeds": [ | ||
{ | ||
"author": { | ||
"name": "${{ inputs.AUTHOR_NAME }}", | ||
"url": "${{ inputs.AUTHOR_URL }}", | ||
"icon_url": "${{ inputs.AUTHOR_ICON_URL }}" | ||
}, | ||
"title": "${{ inputs.TITLE }}", | ||
"description": "${{ inputs.DESCRIPTION }}", | ||
"color": $COLOR | ||
} | ||
] | ||
} | ||
EOF | ||
) | ||
response=$(curl -s -w "\n%{http_code}" -H "Content-Type: application/json" \ | ||
-X POST \ | ||
-d "$PAYLOAD" \ | ||
${{ inputs.DISCORD_WEBHOOK_URL }}) | ||
status_code=$(echo "$response" | tail -n1) | ||
response_body=$(echo "$response" | sed '$d') | ||
if [ "$status_code" -ge 400 ]; then | ||
echo "Error sending Discord notification" | ||
echo "Status code: $status_code" | ||
echo "Response: $response_body" | ||
exit 1 | ||
fi |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: PR Notification | ||
|
||
on: | ||
pull_request: | ||
branches: "**" | ||
|
||
env: | ||
TITLE: "## ${{ github.event.pull_request.title }}" | ||
PR_LINK: "PR Link: [PR #${{ github.event.number }}](${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.number }})" | ||
DESCRIPTION: "${{ github.event.pull_request.body || 'No description' }}" | ||
|
||
jobs: | ||
send_notification: | ||
name: Send Notification | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Send PR Notification | ||
uses: ./.github/actions/notification | ||
with: | ||
TYPE: info | ||
TITLE: "🔔 PR Notification" | ||
DESCRIPTION: "${{ env.TITLE }}\\n${{ env.PR_LINK }}\\n\\n${{ env.DESCRIPTION }}" | ||
AUTHOR_NAME: ${{ github.event.pull_request.user.name || github.event.pull_request.user.login }} | ||
AUTHOR_ICON_URL: ${{ github.event.pull_request.user.avatar_url }} | ||
DISCORD_WEBHOOK_URL: ${{ secrets.SANDBOX_DISCORD_WEBHOOK_URL }} |
Binary file not shown.
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