From aebda70834844181ac3a03affe3ab69d43f5c1fc Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 8 Jul 2026 18:36:25 +0800 Subject: [PATCH] ci(actions): use action notify webhook --- docs/backend/notify.md | 9 +---- scripts/ci/notify-actions.sh | 71 +++++++++++++----------------------- 2 files changed, 28 insertions(+), 52 deletions(-) diff --git a/docs/backend/notify.md b/docs/backend/notify.md index 60a53da2..9d70b1f8 100644 --- a/docs/backend/notify.md +++ b/docs/backend/notify.md @@ -1,8 +1,3 @@ -curl -X POST https://flow.banlv-ai.com/requirements/REQ-XXXXXXXX/development-complete \ +curl -X POST "https://flow.banlv-ai.com/webhooks/action-notify?chat_id=oc_xxx" \ -H "Content-Type: application/json" \ - -d '{ - "operator": "gitea", - "result": "ready_for_test", - "summary": "Gitea 内容操作已完成:这里写他完成了什么、提交/分支/链接", - "source": "gitea" - }' \ No newline at end of file + -d '{"message":"Gitea 内容操作完成,已同步。"}' \ No newline at end of file diff --git a/scripts/ci/notify-actions.sh b/scripts/ci/notify-actions.sh index 5e7fb8a8..691eb78e 100644 --- a/scripts/ci/notify-actions.sh +++ b/scripts/ci/notify-actions.sh @@ -5,36 +5,26 @@ warn() { printf 'Notification warning: %s\n' "$*" >&2 } -resolve_commit_message() { - if [ -n "${ACTION_NOTIFY_COMMIT_MESSAGE:-}" ]; then - printf '%s\n' "$ACTION_NOTIFY_COMMIT_MESSAGE" +generate_chat_id() { + if [ -n "${ACTION_NOTIFY_CHAT_ID:-}" ]; then + printf '%s' "$ACTION_NOTIFY_CHAT_ID" return 0 fi - if command -v git >/dev/null 2>&1; then - git log -1 --pretty=%B 2>/dev/null || true + if command -v node >/dev/null 2>&1; then + node <<'NODE' +const { randomUUID } = require("node:crypto"); +process.stdout.write(`oc_${randomUUID().replaceAll("-", "")}`); +NODE + return 0 fi -} -extract_requirement_id() { - printf '%s\n' "$1" | grep -Eo 'REQ-[A-Za-z0-9_-]+' | head -n 1 || true -} + if command -v openssl >/dev/null 2>&1; then + printf 'oc_%s' "$(openssl rand -hex 16)" + return 0 + fi -normalize_job_result() { - case "$1" in - success) - printf 'ready_for_test' - ;; - cancelled | canceled) - printf 'cancelled' - ;; - failure | failed) - printf 'failed' - ;; - *) - printf 'failed' - ;; - esac + printf 'oc_%s%s' "$(date +%s)" "$$" } branch_name="${BRANCH_NAME:-${GITHUB_REF_NAME:-}}" @@ -53,23 +43,15 @@ if [ -z "$short_sha" ]; then short_sha="unknown" fi -commit_message="$(resolve_commit_message)" -requirement_id="$(extract_requirement_id "$commit_message")" -if [ -z "$requirement_id" ]; then - warn "no REQ-* requirement id found in latest commit message, skip flow notification" - exit 0 -fi - base_url="${FLOW_NOTIFY_BASE_URL:-https://flow.banlv-ai.com}" base_url="${base_url%/}" -notify_url="$base_url/requirements/$requirement_id/development-complete" +chat_id="$(generate_chat_id)" deploy_env="${DEPLOY_ENV:-unknown}" image_tag="${IMAGE_VERSION_TAG:-unknown}" job_status="${ACTION_JOB_STATUS:-unknown}" workflow_name="${GITHUB_WORKFLOW:-Docker Image}" repository="${GITHUB_REPOSITORY:-cozsweet-frontend-nextjs}" -result="$(normalize_job_result "$job_status")" run_url="" if [ -n "${GITHUB_SERVER_URL:-}" ] && [ -n "${GITHUB_REPOSITORY:-}" ] && [ -n "${GITHUB_RUN_ID:-}" ]; then @@ -79,10 +61,7 @@ if [ -z "$run_url" ]; then run_url="${GITHUB_SERVER_URL:-unknown}" fi -export FLOW_NOTIFY_OPERATOR="gitea" -export FLOW_NOTIFY_SOURCE="gitea" -export FLOW_NOTIFY_RESULT="$result" -export FLOW_NOTIFY_SUMMARY="$(cat </dev/null; then - warn "failed to send flow notification for $requirement_id" + warn "failed to send action notification for $chat_id" exit 0 fi -echo "Sent flow notification for $requirement_id." +echo "Sent action notification for $chat_id."