From 49201f3358a4c2272929593d1c23704ebdeba2c0 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Wed, 21 Oct 2026 02:13:00 +0300 Subject: [PATCH] Create validate_discussion.yml --- .github/workflows/validate_discussion.yml | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/validate_discussion.yml diff --git a/.github/workflows/validate_discussion.yml b/.github/workflows/validate_discussion.yml new file mode 100644 index 0000000000..0ca9774761 --- /dev/null +++ b/.github/workflows/validate_discussion.yml @@ -0,0 +1,66 @@ +name: Validate Discussions + +on: + discussion: + types: [created, edited] + +permissions: + contents: read + +jobs: + validate: + runs-on: ubuntu-latest + if: github.event.discussion.category.name == 'Channel Search' + steps: + - name: Checkout repository code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + + - uses: tibdex/github-app-token@0d49dd721133f900ebd5e0dff2810704e8defbc6 # v1.8.2 + if: ${{ !env.ACT }} + id: create-app-token + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.APP_PRIVATE_KEY }} + + - name: Setup Node.js + uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 + with: + node-version: 22 + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run discussion:validate + id: validator + continue-on-error: true + env: + RAW_BODY: ${{ github.event.discussion.body }} + DISC_NUMBER: ${{ github.event.discussion.number }} + GITHUB_TOKEN: ${{ steps.create-app-token.outputs.token || secrets.GITHUB_TOKEN }} + run: | + npm run discussion:validate -- \ + --number "$DISC_NUMBER" \ + --body "$RAW_BODY" + + - name: Handle Discussion Result + if: always() && hashFiles('temp/logs/result.json') != '' + env: + GH_TOKEN: ${{ steps.create-app-token.outputs.token }} + DISC_NUMBER: ${{ github.event.discussion.number }} + run: | + COMMENT=$(jq -r '.comment // empty' temp/logs/result.json) + LABEL=$(jq -r '.label // empty' temp/logs/result.json) + + if [ "${{ env.ACT }}" = "true" ]; then + echo "[MOCK] Comment: $COMMENT" + echo "[MOCK] Label: $LABEL" + else + if [ -n "$COMMENT" ] && [ "$COMMENT" != "null" ]; then + gh discussion comment $DISC_NUMBER --body "$COMMENT" + fi + + if [ -n "$LABEL" ] && [ "$LABEL" != "null" ]; then + gh discussion edit $DISC_NUMBER --add-label "$LABEL" + fi + fi \ No newline at end of file