Skip to content

Commit 0d88755

Browse files
Deep-Dark-ForestDeep-Dark-Forestwyc-26
authored
创建一些管理 Issues 和 PR 的 GitHub Actions (PCL-Community#155)
Co-authored-by: Deep-Dark-Forest <[email protected] signingkey = ~/.ssh/id_ed25519> Co-authored-by: wyc-26 <[email protected]>
1 parent bfaea32 commit 0d88755

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

.github/workflows/issue-close.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Close labeled issues
2+
3+
on:
4+
issues:
5+
types:
6+
- labeled
7+
8+
jobs:
9+
manage_issues:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Set up authentication
14+
run: echo "GITHUB_TOKEN=${{ secrets.BOT }}" >> $GITHUB_ENV
15+
16+
- name: Install jq
17+
run: sudo apt-get update && sudo apt-get install -y jq
18+
19+
- name: Handle labeled issues
20+
if: github.event.action == 'labeled'
21+
run: |
22+
if [[ "${{ github.event.label.name }}" == "❌ 拒绝" || "${{ github.event.label.name }}" == "😂 移交上游" || "${{ github.event.label.name }}" == "❌ 忽略" || "${{ github.event.label.name }}" == "❌ 第三方" || "${{ github.event.label.name }}" == "❌ 暂无计划"]]; then
23+
curl -X PATCH \
24+
-H "Authorization: token ${{ secrets.BOT }}" \
25+
-H "Accept: application/vnd.github.v3+json" \
26+
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \
27+
-d '{"state": "closed", "state_reason": "not_planned"}'
28+
elif [[ "${{ github.event.label.name }}" == "👌 完成" ]]; then
29+
curl -X PATCH \
30+
-H "Authorization: token ${{ secrets.BOT }}" \
31+
-H "Accept: application/vnd.github.v3+json" \
32+
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \
33+
-d '{"state": "closed", "state_reason": "completed"}'
34+
elif [[ "${{ github.event.label.name }}" == "❌ 重复" ]]; then
35+
curl -X PATCH \
36+
-H "Authorization: token ${{ secrets.BOT }}" \
37+
-H "Accept: application/vnd.github.v3+json" \
38+
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \
39+
-d '{"state": "closed", "state_reason": "duplicate"}'
40+
fi

.github/workflows/labels.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Add labels based on issue closure reason
2+
3+
on:
4+
issues:
5+
types: [closed]
6+
7+
jobs:
8+
add-labels:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check if the issue was closed as completed and add label
12+
uses: actions/github-script@v6
13+
with:
14+
github-token: ${{ secrets.BOT }}
15+
script: |
16+
if (context.payload.issue.state_reason === 'completed') {
17+
await github.rest.issues.addLabels({
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
issue_number: context.payload.issue.number,
21+
labels: ['👌 完成']
22+
});
23+
}
24+
25+
- name: Check if the issue was closed as duplicate and add label
26+
uses: actions/github-script@v6
27+
with:
28+
github-token: ${{ secrets.BOT }}
29+
script: |
30+
if (context.payload.issue.state_reason === 'duplicate') {
31+
await github.rest.issues.addLabels({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
issue_number: context.payload.issue.number,
35+
labels: ['❌ 重复']
36+
});
37+
}
38+
39+
- name: Check if the issue was closed as not planned and add label
40+
uses: actions/github-script@v6
41+
with:
42+
github-token: ${{ secrets.BOT }}
43+
script: |
44+
if (context.payload.issue.state_reason === 'not_planned') {
45+
await github.rest.issues.addLabels({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
issue_number: context.payload.issue.number,
49+
labels: ['❌ 忽略']
50+
});
51+
}
52+

.github/workflows/pr.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Auto Label and Close PRs
2+
3+
on:
4+
pull_request:
5+
types: [closed, labeled]
6+
7+
jobs:
8+
9+
label_on_merge:
10+
runs-on: ubuntu-latest
11+
if: github.event.pull_request.merged == true
12+
steps:
13+
- name: Add "👌 完成" label on merge
14+
uses: actions-ecosystem/action-add-labels@v1
15+
with:
16+
labels: "👌 完成"
17+
repo-token: ${{ secrets.BOT }}
18+
19+
close_pr_on_specific_labels:
20+
runs-on: ubuntu-latest
21+
if: github.event.action == 'labeled'
22+
steps:
23+
- name: Check for specific labels and close PR
24+
id: check_label
25+
run: |
26+
case "${{ github.event.label.name }}" in
27+
"❌ 忽略"|"❌ 拒绝"|"❌ 暂无计划"|"❌ 第三方"|"❌ 重复"|"😂 移交上游")
28+
echo "::set-output name=should_close::true"
29+
;;
30+
*)
31+
echo "::set-output name=should_close::false"
32+
;;
33+
esac
34+
- name: Debugging Information
35+
if: steps.check_label.outputs.should_close == 'true'
36+
env:
37+
BOT_TOKEN: ${{ secrets.BOT }}
38+
run: |
39+
echo "Repository: ${{ github.repository }}"
40+
echo "Pull Request Number: ${{ github.event.pull_number }}"
41+
- name: Close PR
42+
if: steps.check_label.outputs.should_close == 'true'
43+
env:
44+
BOT_TOKEN: ${{ secrets.BOT }}
45+
run: |
46+
curl -X PATCH \
47+
-H "Accept: application/vnd.github.v3+json" \
48+
-H "Authorization: token $BOT_TOKEN" \
49+
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_number }} \
50+
-d '{"state": "closed"}' \
51+
--verbose

0 commit comments

Comments
 (0)