🩹 If user is login, their role should not be :guest, fix #16. #16
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: Push Change to Discord Webhook URL | |
on: | |
push: | |
branches: | |
- main | |
# Allow manual trigger | |
workflow_dispatch: | |
jobs: | |
send-to-discord-webhook-url: | |
runs-on: ubuntu-latest | |
steps: | |
- name: crawl-commit-message-headers | |
id: crawl-commit-message-headers | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const commitMessage = context.payload.head_commit.message; | |
const commitMessageHeaders = commitMessage.split('\n')[0]; | |
core.exportVariable('commitMessageHeaders', commitMessageHeaders); | |
- name: build-discord-webhook-payload | |
id: build-discord-webhook-payload | |
uses: actions/github-script@v7 | |
env: | |
# # sandbox webhook url | |
# DISCORD_WEBHOOK_URL: ${{ secrets.SANDBOX_DISCORD_WEBHOOK_URL }} | |
# real webhook url | |
DISCORD_WEBHOOK_URL: ${{ secrets.SPLIT_GAME_CHANNEL_DISCORD_WEBHOOK_URL }} | |
avatarHost: "https://raw.githubusercontent.com/side-project-at-SPT/split-front/main/src/assets/images/" | |
with: | |
script: | | |
const { commitMessageHeaders, DISCORD_WEBHOOK_URL: url, avatarHost } = process.env; | |
const availableAvatarUrls = ['1', '2', '3', '4'].map(id => `${avatarHost}${id}.png`); | |
const emojiMap = { | |
bump: '🔼 ', // 更新 | |
feat: '🚀 ', // 新功能 | |
fix: '🔧 ', // 修復 | |
docs: '📚 ', // 文件 | |
style: '🎨 ', // 格式 | |
refactor: '🔨 ', // 重構 | |
perf: '⚡ ', // 性能 | |
test: '🧪 ', // 測試 | |
build: '🏗️ ', // 構建 | |
ci: '🔬 ', // CI | |
chore: '🧹 ', // 雜務 | |
revert: '⏪ ', // 回滾 | |
default: '' // 其他 | |
}; | |
const wrapper = cmh => { | |
const [firstWord, ...rest] = cmh.split(':'); | |
const getEmoji = firstWord => emojiMap[firstWord] || emojiMap.default; | |
const emoji = getEmoji(firstWord); | |
return `${emoji}${cmh}`; | |
}; | |
const discordWebhookPayload = { | |
content: '# 企鵝搶地後端 update' + '\n' + wrapper(commitMessageHeaders) + ' ' + `([#${context.payload.head_commit.id.slice(0, 7)}](${context.payload.head_commit.url}))`, | |
username: '企鵝探險日誌', | |
avatar_url: availableAvatarUrls.sort(() => Math.random() - 0.5)[0] | |
}; | |
const req = new Request(url, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify(discordWebhookPayload) | |
}); | |
const res = await fetch(req); | |
if (!res.ok) { | |
throw new Error(`HTTP error! status: ${res.status}`); | |
} |