Skip to content

Workflow file for this run

name: Issue Management
on:
issues:
types:
- labeled
- closed
jobs:
manage_issues:
runs-on: ubuntu-latest
steps:
- name: Set up authentication
run: echo "GITHUB_TOKEN=${{ secrets.SHEEP }}" >> $GITHUB_ENV
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Handle labeled issues
if: github.event.action == 'labeled'
run: |
if [[ "${{ github.event.label.name }}" == "❌ 拒绝" || "${{ github.event.label.name }}" == "😂 移交上游" ]]; then
curl -X PATCH \
-H "Authorization: token ${{ secrets.SHEEP }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \
-d '{"state": "closed", "state_reason": "not_planned"}'
elif [[ "${{ github.event.label.name }}" == "👌 完成" ]]; then
curl -X PATCH \
-H "Authorization: token ${{ secrets.SHEEP }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \
-d '{"state": "closed", "state_reason": "completed"}'
fi
- name: Handle closed issues
if: github.event.action == 'closed'
run: |
existing_labels=$(curl -s -H "Authorization: token ${{ secrets.SHEEP }}" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} | jq -r '.labels | map(.name)')
if [[ "${{ github.event.issue.state_reason }}" == "duplicate" ]]; then
new_labels=$(echo $existing_labels | jq -c '. + ["❌ 重复"]' | jq -c '. | map(gsub("\\s+"; ""))')
curl -X PATCH \
-H "Authorization: token ${{ secrets.SHEEP }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \
-d '{"labels": '$new_labels'}'
elif [[ "${{ github.event.issue.state_reason }}" == "completed" ]]; then
new_labels=$(echo $existing_labels | jq -c '. + ["👌 完成"]' | jq -c '. | map(gsub("\\s+"; ""))')
curl -X PATCH \
-H "Authorization: token ${{ secrets.SHEEP }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }} \
-d '{"labels": '$new_labels'}'
fi