From bf83b0569ff5b731721788bccc88c1360a152278 Mon Sep 17 00:00:00 2001 From: Deep-Dark-Forest Date: Tue, 4 Feb 2025 16:38:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=83=A8=E5=88=86=20GitHub?= =?UTF-8?q?=20Actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/issue-close.yml | 34 ---------------------- .github/workflows/labels.yml | 48 ------------------------------- .github/workflows/pr.yml | 33 --------------------- 3 files changed, 115 deletions(-) delete mode 100644 .github/workflows/issue-close.yml delete mode 100644 .github/workflows/labels.yml delete mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/issue-close.yml b/.github/workflows/issue-close.yml deleted file mode 100644 index 252043c5..00000000 --- a/.github/workflows/issue-close.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Auto Close Issues Based on Labels - -on: - issues: - types: [labeled] - -jobs: - auto-close-issue: - runs-on: ubuntu-latest - steps: - # 处理 not_planned 关闭类型 - - name: Close as not planned - if: | - contains('❌ 拒绝,😂 移交上游,❌ 忽略,❌ 第三方,❌ 暂无计划', github.event.label.name) - env: - GITHUB_TOKEN: ${{ secrets.BOT }} - run: | - gh api \ - --method PATCH \ - /repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \ - -f state=closed \ - -f state_reason="not_planned" - - # 处理 completed 关闭类型 - - name: Close as completed - if: github.event.label.name == '👌 完成' - env: - GITHUB_TOKEN: ${{ secrets.BOT }} - run: | - gh api \ - --method PATCH \ - /repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \ - -f state=closed \ - -f state_reason="completed" \ No newline at end of file diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml deleted file mode 100644 index aa212708..00000000 --- a/.github/workflows/labels.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Manage Labels on Issue Close - -on: - issues: - types: [closed] - -jobs: - manage-labels: - runs-on: ubuntu-latest - steps: - - name: Handle labels based on close reason - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.BOT }} - script: | - const { issue, repository } = context.payload; - const labelsToRemove = ['⭕ 等待处理', '🚧 正在处理']; - const closedReason = issue.state_reason; - - // 移除旧标签 - for (const label of labelsToRemove) { - try { - await github.rest.issues.removeLabel({ - owner: repository.owner.login, - repo: repository.name, - issue_number: issue.number, - name: label - }); - } catch (error) { - if (error.status !== 404) throw error; - } - } - - // 根据关闭原因添加新标签 - const reasonMapping = { - 'completed': '👌 完成', - 'not_planned': '❌ 忽略', - 'duplicate': '❌ 重复' - }; - - if (reasonMapping[closedReason]) { - await github.rest.issues.addLabels({ - owner: repository.owner.login, - repo: repository.name, - issue_number: issue.number, - labels: [reasonMapping[closedReason]] - }); - } \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index 7f27962d..00000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: PR Label Automation - -on: - pull_request: - types: [labeled, closed] - -jobs: - handle_labels: - runs-on: ubuntu-latest - steps: - # 自动关闭带有特定标签的PR - - name: Close PR with specific labels - if: | - github.event.action == 'labeled' && - contains('❌ 拒绝,😂 移交上游,❌ 忽略,❌ 第三方,❌ 暂无计划,❌ 重复', github.event.label.name) - run: | - curl -sS -X PATCH \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${{ secrets.BOT }}" \ - "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \ - -d '{"state": "closed"}' - - # 合并后添加完成标签 - - name: Add merged label - if: | - github.event.action == 'closed' && - github.event.pull_request.merged == true - run: | - curl -sS -X POST \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${{ secrets.BOT }}" \ - "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels" \ - -d '{"labels":["👌 完成"]}' \ No newline at end of file