|
| 1 | +# This workflow manages issue assignments and related label changes: |
| 2 | +# 1. When someone is assigned to an issue: |
| 3 | +# - Removes "stat:awaiting-triage" label |
| 4 | +# - Adds "stat:Investigating" label |
| 5 | +# 2. When all assignees are removed from an issue: |
| 6 | +# - Adds "stat:awaiting-triage" label |
| 7 | +# - Removes "stat:Investigating" label |
| 8 | +# 3. When "stat:Investigating" label is added: |
| 9 | +# - Automatically assigns the issue to the person who added the label |
| 10 | + |
| 11 | +name: Handle Issue Assignment and Labels |
| 12 | + |
| 13 | +on: |
| 14 | + issues: |
| 15 | + types: [assigned, unassigned, labeled] |
| 16 | + |
| 17 | +env: |
| 18 | + AWAITING-TRIAGE_LABEL: stat:awaiting-triage |
| 19 | + INVESTIGATING_LABEL: stat:Investigating |
| 20 | + |
| 21 | +jobs: |
| 22 | + handle_assignment: |
| 23 | + name: Handle Issue Assignment Changes |
| 24 | + if: ${{ !github.event.issue.pull_request && github.event.issue.state == 'open' }} |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + issues: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Handle Assignment Changes |
| 31 | + run: | |
| 32 | + if [[ "${{ github.event.action }}" == "assigned" ]]; then |
| 33 | + # Someone was assigned - remove awaiting-triage, add investigating |
| 34 | + echo "ADD=${{ env.INVESTIGATING_LABEL }}" >> $GITHUB_ENV |
| 35 | + echo "REMOVE=${{ env.AWAITING-TRIAGE_LABEL }}" >> $GITHUB_ENV |
| 36 | + elif [[ "${{ github.event.action }}" == "unassigned" ]]; then |
| 37 | + # Check if there are any remaining assignees |
| 38 | + ASSIGNEES=$(echo '${{ toJson(github.event.issue.assignees) }}' | jq length) |
| 39 | + if [[ "$ASSIGNEES" == "0" ]]; then |
| 40 | + # No assignees left - add awaiting-triage, remove investigating |
| 41 | + echo "ADD=${{ env.AWAITING-TRIAGE_LABEL }}" >> $GITHUB_ENV |
| 42 | + echo "REMOVE=${{ env.INVESTIGATING_LABEL }}" >> $GITHUB_ENV |
| 43 | + fi |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: Update Labels |
| 47 | + if: env.ADD != '' || env.REMOVE != '' |
| 48 | + run: gh issue edit "$NUMBER" --add-label "$ADD" --remove-label "$REMOVE" |
| 49 | + env: |
| 50 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + GH_REPO: ${{ github.repository }} |
| 52 | + NUMBER: ${{ github.event.issue.number }} |
| 53 | + |
| 54 | + handle_investigating_label: |
| 55 | + name: Handle Investigating Label Addition |
| 56 | + if: ${{ github.event.action == 'labeled' && github.event.label.name == 'stat:Investigating' && !github.event.issue.pull_request && github.event.issue.state == 'open' }} |
| 57 | + runs-on: ubuntu-latest |
| 58 | + permissions: |
| 59 | + issues: write |
| 60 | + |
| 61 | + steps: |
| 62 | + - name: Assign Issue to person that added Investigating Label |
| 63 | + run: | |
| 64 | + # Assign the issue to the person who added the label |
| 65 | + gh issue edit "$NUMBER" --add-assignee "$ACTOR" |
| 66 | + env: |
| 67 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + GH_REPO: ${{ github.repository }} |
| 69 | + NUMBER: ${{ github.event.issue.number }} |
| 70 | + ACTOR: ${{ github.actor }} |
0 commit comments