From 352faed075f5915db7369c88b23465dca31453e5 Mon Sep 17 00:00:00 2001 From: kingmo888 <17401091+kingmo888@users.noreply.github.com> Date: Mon, 12 Aug 2024 11:25:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3ISSUES=E6=8F=90=E9=86=92?= =?UTF-8?q?=E5=BC=BA=E8=BF=AB=E7=97=87=EF=BC=8C=E6=9C=AAstart=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=85=B3=E9=97=AD=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/auto-close-issues.yml | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/auto-close-issues.yml diff --git a/.github/workflows/auto-close-issues.yml b/.github/workflows/auto-close-issues.yml new file mode 100644 index 0000000..493014e --- /dev/null +++ b/.github/workflows/auto-close-issues.yml @@ -0,0 +1,32 @@ +name: Auto Close Issues if Not Starred + +on: + issues: + types: [opened] + +jobs: + close_issue: + runs-on: ubuntu-latest + steps: + - name: Check if user has starred the repo + id: check_star + run: | + ISSUE_USER=$(jq -r '.issue.user.login' < $GITHUB_EVENT_PATH) + STARRED=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/user/starred/${{ github.repository }}" | \ + jq -r '.[].login' | grep -c "^$ISSUE_USER$" || true) + echo "::set-output name=starred::$STARRED" + + - name: Close issue if not starred + if: steps.check_star.outputs.starred == '0' + run: | + ISSUE_NUMBER=$(jq -r '.issue.number' < $GITHUB_EVENT_PATH) + curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER/comments \ + -d '{"body":"白嫖随便拿,但不接受无star的提问。本提问将自动关闭。Please star the project before submitting an issue."}' + + curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER \ + -d '{"state":"closed"}'