From 32f48cc4e12bc80b56ed3c9e18ece963ad9f6658 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Thu, 4 Jun 2026 12:35:00 +0800 Subject: [PATCH] ci: hide issue moderation script from logs --- .github/scripts/evaluate-issue-content.sh | 28 +++++++++++++++++++ .github/workflows/detect-abusive-content.yml | 29 ++++---------------- 2 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 .github/scripts/evaluate-issue-content.sh diff --git a/.github/scripts/evaluate-issue-content.sh b/.github/scripts/evaluate-issue-content.sh new file mode 100644 index 000000000..488eba418 --- /dev/null +++ b/.github/scripts/evaluate-issue-content.sh @@ -0,0 +1,28 @@ +set -euo pipefail + +issue_text="$( + jq -r ' + [ + .issue.title // "", + .issue.body // "" + ] | join("\n") + ' "$GITHUB_EVENT_PATH" +)" + +issue_number="$(jq -r '.issue.number' "$GITHUB_EVENT_PATH")" + +prefix="$(printf '\345\210\267')" +cn_target="$(printf '\346\230\237')" +ascii_target="$(printf '\163\164\141\162')" +pattern="${prefix}[[:space:]]*(${cn_target}|${ascii_target})" + +if grep -Eiq "$pattern" <<<"$issue_text"; then + matched=true +else + matched=false +fi + +{ + printf 'matched=%s\n' "$matched" + printf 'issue_number=%s\n' "$issue_number" +} >>"$GITHUB_OUTPUT" diff --git a/.github/workflows/detect-abusive-content.yml b/.github/workflows/detect-abusive-content.yml index b225a7727..e1b44b462 100644 --- a/.github/workflows/detect-abusive-content.yml +++ b/.github/workflows/detect-abusive-content.yml @@ -51,31 +51,14 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'issues' steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Evaluate issue content id: check - run: | - python3 - <<'PYEOF' - import json - import os - import re - - with open(os.environ["GITHUB_EVENT_PATH"], encoding="utf-8") as f: - event = json.load(f) - - issue = event["issue"] - text = "\n".join([ - issue.get("title") or "", - issue.get("body") or "", - ]) - - # Keep this intentionally narrow. It only matches "刷星" and - # case-insensitive variants of "刷star", including optional spaces. - matched = re.search(r"刷\s*(?:星|star)", text, re.IGNORECASE) is not None - - with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f: - f.write(f"matched={'true' if matched else 'false'}\n") - f.write(f"issue_number={issue['number']}\n") - PYEOF + run: bash .github/scripts/evaluate-issue-content.sh - name: Apply issue policy if: steps.check.outputs.matched == 'true'