summaryrefslogtreecommitdiffstats
path: root/.github/workflows/issue-assignment.yml
blob: 1c06ea9d44224f3ec9bdb41c95e7ecebb565136a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Actions that should occur when a GitHub issue is assigned.
#
# Currently this will remove the `state:needs-owner` label when the issue is assigned to an owner.
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent

name: React to Issue Assignment

on:
  issues:
    types: assigned

jobs:
  adjust-labels:
    name: Adjust Issue Labels
    runs-on: ubuntu-latest

    permissions:
      contents: read
      issues: write

    steps:
      - uses: actions/checkout@v4

      - name: Remove Labels
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          # All labels here will be removed if present in the issue
          LABELS_TO_REMOVE=("state:needs-owner")

          # Gather issue context information
          ISSUE_NUMBER=$(jq --raw-output .issue.number "$GITHUB_EVENT_PATH")
          OWNER=$(jq --raw-output .repository.owner.login "$GITHUB_EVENT_PATH")
          REPO=$(jq --raw-output .repository.name "$GITHUB_EVENT_PATH")
          LABELS=$(curl -s \
                        -H "Accept: application/vnd.github+json" \
                        -H "Authorization: Bearer $GITHUB_TOKEN" \
                        -H "X-GitHub-Api-Version: 2022-11-28" \
                        https://api.github.com/repos/$OWNER/$REPO/issues/$ISSUE_NUMBER/labels | jq -r '.[].name')

          # Remove labels
          for LABEL in "${LABELS_TO_REMOVE[@]}"; do
            if echo "$LABELS" | grep -q "$LABEL"; then
              curl -X DELETE \
                   -s \
                   -H "Accept: application/vnd.github+json" \
                   -H "Authorization: Bearer $GITHUB_TOKEN" \
                   -H "X-GitHub-Api-Version: 2022-11-28" \
                   https://api.github.com/repos/$OWNER/$REPO/issues/$ISSUE_NUMBER/labels/"$LABEL" > /dev/null
              echo "$LABEL removed from issue #$ISSUE_NUMBER"
            else
              echo "$LABEL not found on issue #$ISSUE_NUMBER"
            fi
          done