|
| 1 | +name: Update issue labels |
| 2 | + |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: [created] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: ${{ github.workflow }}-${{ github.event.issue.number }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +# Define labels here |
| 12 | +env: |
| 13 | + AWAITING_RESPONSE: stat:awaiting response |
| 14 | + |
| 15 | +jobs: |
| 16 | + setup: |
| 17 | + name: Calculate Labels |
| 18 | + if: ${{ !github.event.issue.pull_request }} && ${{ github.event.issue.state == 'open' }} |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + add_labels: ${{ steps.data.outputs.add_labels }} |
| 22 | + remove_labels: ${{ steps.data.outputs.remove_labels }} |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Calculate Labels |
| 26 | + id: data |
| 27 | + run: | |
| 28 | + ADD_LABELS=() |
| 29 | + REMOVE_LABELS=() |
| 30 | +
|
| 31 | + if [[ "${{ github.event.comment.author_association }}" == "MEMBER" ]]; then |
| 32 | + ADD_LABELS+=${{ env.AWAITING_RESPONSE}} |
| 33 | + else |
| 34 | + REMOVE_LABELS+=${{ env.AWAITING_RESPONSE}} |
| 35 | + fi |
| 36 | +
|
| 37 | + echo "add_labels=$(IFS=,; echo "${ADD_LABELS[*]}")" >> $GITHUB_OUTPUT |
| 38 | + echo "remove_labels=$(IFS=,; echo "${REMOVE_LABELS[*]}")" >> $GITHUB_OUTPUT |
| 39 | +
|
| 40 | + manage_labels: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + permissions: |
| 43 | + issues: write |
| 44 | + needs: [setup] |
| 45 | + steps: |
| 46 | + - name: Calculate add labels |
| 47 | + id: add_labels |
| 48 | + if: ${{ needs.setup.outputs.add_labels != '' }} |
| 49 | + run: | |
| 50 | + COMMAND="" |
| 51 | + if [[ -n "${{ needs.setup.outputs.add_labels }}" ]]; then |
| 52 | + COMMAND+="--add-label \"${{ needs.setup.outputs.add_labels }}\"" |
| 53 | + fi |
| 54 | + echo "ADD_LABEL=$COMMAND" >> $GITHUB_ENV |
| 55 | +
|
| 56 | + - name: Calculate remove labels |
| 57 | + id: remove_labels |
| 58 | + if: ${{ needs.setup.outputs.remove_labels != '' }} |
| 59 | + run: | |
| 60 | + COMMAND="" |
| 61 | + if [[ -n "${{ needs.setup.outputs.remove_labels }}" ]]; then |
| 62 | + COMMAND+="--remove-label \"${{ needs.setup.outputs.remove_labels }}\"" |
| 63 | + fi |
| 64 | + echo "REMOVE_LABEL=$COMMAND" >> $GITHUB_ENV |
| 65 | +
|
| 66 | + - name: Test Print Command |
| 67 | + run: | |
| 68 | + echo "gh issue edit "$NUMBER" $ADD_LABEL $REMOVE_LABEL" |
| 69 | + env: |
| 70 | + NUMBER: ${{ github.event.issue.number }} |
| 71 | + |
| 72 | + |
| 73 | + # - run: gh issue edit "$NUMBER" --add-label "$ADD_LABELS" --remove-label "$REMOVE_LABELS" |
| 74 | + # env: |
| 75 | + # GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + # GH_REPO: ${{ github.repository }} |
| 77 | + # NUMBER: ${{ github.event.issue.number }} |
| 78 | + # ADD_LABELS: ${{ needs.setup.outputs.add_labels }} |
| 79 | + # REMOVE_LABELS: ${{ needs.setup.outputs.remove_labels }} |
0 commit comments