From b73beaa5c4858793b02ae06fe8aa11370a00e643 Mon Sep 17 00:00:00 2001 From: kaedeek Date: Sat, 18 Oct 2025 23:05:22 +0900 Subject: [PATCH] Fixend github.yml port2 --- .github/workflows/github.yml | 77 ++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 5acbd45..e54bc28 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -6,89 +6,88 @@ on: issues: types: [opened, closed, reopened, assigned, labeled, unlabeled] +permissions: + contents: read + jobs: send_notification: runs-on: ubuntu-latest steps: - name: Send Discord Notification + env: + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} + EVENT: ${{ github.event.action }} + EVENT_NAME: ${{ github.event_name }} + USER: ${{ github.actor }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_TITLE: ${{ github.event.pull_request.title }} + PR_URL: ${{ github.event.pull_request.html_url }} + PR_MERGED: ${{ github.event.pull_request.merged }} + ISSUE_NUMBER: ${{ github.event.issue.number }} + ISSUE_TITLE: ${{ github.event.issue.title }} + ISSUE_URL: ${{ github.event.issue.html_url }} + ASSIGNEE: ${{ github.event.assignee.login }} + LABEL: ${{ github.event.label.name }} run: | - EVENT="${{ github.event.action }}" - USER="${{ github.actor }}" - EVENT_NAME="${{ github.event_name }}" - + set -e MESSAGE="" if [ "$EVENT_NAME" = "pull_request" ]; then - PR_NUMBER="${{ github.event.pull_request.number }}" - PR_TITLE="${{ github.event.pull_request.title }}" - PR_URL="${{ github.event.pull_request.html_url }}" - MERGED="${{ github.event.pull_request.merged }}" - case "$EVENT" in opened) - MESSAGE="๐Ÿ“ข **Pull Request #${PR_NUMBER}** ใŒไฝœๆˆใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ไฝœ่€…: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $PR_TITLE\n๐Ÿ”— URL: $PR_URL" + MESSAGE="๐Ÿ“ข Pull Request #${PR_NUMBER} created by ${USER}\n**${PR_TITLE}**\n${PR_URL}" ;; closed) - if [ "$MERGED" = "true" ]; then - MESSAGE="๐ŸŽ‰ **Pull Request #${PR_NUMBER}** ใŒใƒžใƒผใ‚ธใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ใƒฆใƒผใ‚ถใƒผ: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $PR_TITLE\n๐Ÿ”— URL: $PR_URL" + if [ "$PR_MERGED" = "true" ]; then + MESSAGE="๐ŸŽ‰ Pull Request #${PR_NUMBER} merged by ${USER}\n**${PR_TITLE}**\n${PR_URL}" else - MESSAGE="โŒ **Pull Request #${PR_NUMBER}** ใŒใ‚ฏใƒญใƒผใ‚บใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ใƒฆใƒผใ‚ถใƒผ: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $PR_TITLE\n๐Ÿ”— URL: $PR_URL" + MESSAGE="โŒ Pull Request #${PR_NUMBER} closed by ${USER}\n**${PR_TITLE}**\n${PR_URL}" fi ;; reopened) - MESSAGE="๐Ÿ”„ **Pull Request #${PR_NUMBER}** ใŒๅ†ใ‚ชใƒผใƒ—ใƒณใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ใƒฆใƒผใ‚ถใƒผ: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $PR_TITLE\n๐Ÿ”— URL: $PR_URL" + MESSAGE="๐Ÿ”„ Pull Request #${PR_NUMBER} reopened by ${USER}\n**${PR_TITLE}**\n${PR_URL}" ;; assigned) - MESSAGE="๐Ÿ™‹ **Pull Request #${PR_NUMBER}** ใŒ $USER ใซใ‚ขใ‚ตใ‚คใƒณใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $PR_TITLE\n๐Ÿ”— URL: $PR_URL" + MESSAGE="๐Ÿ™‹ Pull Request #${PR_NUMBER} assigned to ${ASSIGNEE} by ${USER}\n**${PR_TITLE}**\n${PR_URL}" ;; review_requested) - REVIEWER="${{ github.event.requested_reviewers[0].login }}" - MESSAGE="๐Ÿ‘€ **Pull Request #${PR_NUMBER}** ใฎใƒฌใƒ“ใƒฅใƒผใŒ $REVIEWER ใซใƒชใ‚ฏใ‚จใ‚นใƒˆใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ใƒชใ‚ฏใ‚จใ‚นใ‚ฟใƒผ: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $PR_TITLE\n๐Ÿ”— URL: $PR_URL" + MESSAGE="๐Ÿ‘€ Review requested for PR #${PR_NUMBER} by ${USER}\n**${PR_TITLE}**\n${PR_URL}" ;; *) - MESSAGE="โš ๏ธ ๆœชๅฏพๅฟœใฎ Pull Request ใ‚คใƒ™ใƒณใƒˆ: $EVENT" + MESSAGE="โš  Unknown PR event: ${EVENT}" ;; esac elif [ "$EVENT_NAME" = "issues" ]; then - ISSUE_NUMBER="${{ github.event.issue.number }}" - ISSUE_TITLE="${{ github.event.issue.title }}" - ISSUE_URL="${{ github.event.issue.html_url }}" - case "$EVENT" in opened) - MESSAGE="๐Ÿ› **Issue #${ISSUE_NUMBER}** ใŒไฝœๆˆใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ไฝœ่€…: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $ISSUE_TITLE\n๐Ÿ”— URL: $ISSUE_URL" + MESSAGE="๐Ÿ› Issue #${ISSUE_NUMBER} opened by ${USER}\n**${ISSUE_TITLE}**\n${ISSUE_URL}" ;; closed) - MESSAGE="โœ… **Issue #${ISSUE_NUMBER}** ใŒใ‚ฏใƒญใƒผใ‚บใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ใƒฆใƒผใ‚ถใƒผ: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $ISSUE_TITLE\n๐Ÿ”— URL: $ISSUE_URL" + MESSAGE="โœ… Issue #${ISSUE_NUMBER} closed by ${USER}\n**${ISSUE_TITLE}**\n${ISSUE_URL}" ;; reopened) - MESSAGE="๐Ÿ”„ **Issue #${ISSUE_NUMBER}** ใŒๅ†ใ‚ชใƒผใƒ—ใƒณใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ใƒฆใƒผใ‚ถใƒผ: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $ISSUE_TITLE\n๐Ÿ”— URL: $ISSUE_URL" + MESSAGE="๐Ÿ”„ Issue #${ISSUE_NUMBER} reopened by ${USER}\n**${ISSUE_TITLE}**\n${ISSUE_URL}" ;; assigned) - ASSIGNEE="${{ github.event.assignee.login }}" - MESSAGE="๐Ÿ™‹ **Issue #${ISSUE_NUMBER}** ใŒ $ASSIGNEE ใซใ‚ขใ‚ตใ‚คใƒณใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ๆ“ไฝœ่€…: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $ISSUE_TITLE\n๐Ÿ”— URL: $ISSUE_URL" + MESSAGE="๐Ÿ™‹ Issue #${ISSUE_NUMBER} assigned to ${ASSIGNEE} by ${USER}\n**${ISSUE_TITLE}**\n${ISSUE_URL}" ;; labeled) - LABEL="${{ github.event.label.name }}" - MESSAGE="๐Ÿท๏ธ **Issue #${ISSUE_NUMBER}** ใซใƒฉใƒ™ใƒซ '${LABEL}' ใŒ่ฟฝๅŠ ใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ๆ“ไฝœ่€…: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $ISSUE_TITLE\n๐Ÿ”— URL: $ISSUE_URL" + MESSAGE="๐Ÿท๏ธ Label '${LABEL}' added to Issue #${ISSUE_NUMBER} by ${USER}\n**${ISSUE_TITLE}**\n${ISSUE_URL}" ;; unlabeled) - LABEL="${{ github.event.label.name }}" - MESSAGE="๐Ÿท๏ธ **Issue #${ISSUE_NUMBER}** ใ‹ใ‚‰ใƒฉใƒ™ใƒซ '${LABEL}' ใŒๅ‰Š้™คใ•ใ‚Œใพใ—ใŸ๏ผ\n๐Ÿ‘ค ๆ“ไฝœ่€…: $USER\n๐Ÿ“ ใ‚ฟใ‚คใƒˆใƒซ: $ISSUE_TITLE\n๐Ÿ”— URL: $ISSUE_URL" + MESSAGE="๐Ÿท๏ธ Label '${LABEL}' removed from Issue #${ISSUE_NUMBER} by ${USER}\n**${ISSUE_TITLE}**\n${ISSUE_URL}" ;; *) - MESSAGE="โš ๏ธ ๆœชๅฏพๅฟœใฎ Issue ใ‚คใƒ™ใƒณใƒˆ: $EVENT" + MESSAGE="โš  Unknown issue event: ${EVENT}" ;; esac - else - MESSAGE="โ“ ไธๆ˜Žใชใ‚คใƒ™ใƒณใƒˆใ‚ฟใ‚คใƒ—: $EVENT_NAME" fi - # JSONใ‚’ๅฎ‰ๅ…จใซ็”Ÿๆˆใ—ใฆ้€ไฟก๏ผˆๆ”น่กŒๅฏพๅฟœ๏ผ‰ - PAYLOAD=$(jq -n --arg content "$MESSAGE" '{content: $content}') + echo "Sending message to Discord..." + echo "$MESSAGE" - curl -s -o /dev/null -w "%{http_code}" -X POST \ + curl -X POST \ -H "Content-Type: application/json" \ - -d "$PAYLOAD" \ - "${{ secrets.DISCORD_WEBHOOK }}" \ No newline at end of file + -d "{\"content\": \"$MESSAGE\"}" \ + "$DISCORD_WEBHOOK"