1 | # Actions that should occur when a GitHub issue is assigned.
|
---|
2 | #
|
---|
3 | # Currently this will remove the `state:needs-owner` label when the issue is assigned to an owner.
|
---|
4 | #
|
---|
5 | # Copyright (c) Microsoft Corporation.
|
---|
6 | # SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | name: React to Issue Assignment
|
---|
9 |
|
---|
10 | on:
|
---|
11 | issues:
|
---|
12 | types: assigned
|
---|
13 |
|
---|
14 | jobs:
|
---|
15 | adjust-labels:
|
---|
16 | name: Adjust Issue Labels
|
---|
17 | runs-on: ubuntu-latest
|
---|
18 |
|
---|
19 | permissions:
|
---|
20 | contents: read
|
---|
21 | issues: write
|
---|
22 |
|
---|
23 | steps:
|
---|
24 | - uses: actions/checkout@v4
|
---|
25 |
|
---|
26 | - name: Remove Labels
|
---|
27 | env:
|
---|
28 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
---|
29 | run: |
|
---|
30 | # All labels here will be removed if present in the issue
|
---|
31 | LABELS_TO_REMOVE=("state:needs-owner")
|
---|
32 |
|
---|
33 | # Gather issue context information
|
---|
34 | ISSUE_NUMBER=$(jq --raw-output .issue.number "$GITHUB_EVENT_PATH")
|
---|
35 | OWNER=$(jq --raw-output .repository.owner.login "$GITHUB_EVENT_PATH")
|
---|
36 | REPO=$(jq --raw-output .repository.name "$GITHUB_EVENT_PATH")
|
---|
37 | LABELS=$(curl -s \
|
---|
38 | -H "Accept: application/vnd.github+json" \
|
---|
39 | -H "Authorization: Bearer $GITHUB_TOKEN" \
|
---|
40 | -H "X-GitHub-Api-Version: 2022-11-28" \
|
---|
41 | https://api.github.com/repos/$OWNER/$REPO/issues/$ISSUE_NUMBER/labels | jq -r '.[].name')
|
---|
42 |
|
---|
43 | # Remove labels
|
---|
44 | for LABEL in "${LABELS_TO_REMOVE[@]}"; do
|
---|
45 | if echo "$LABELS" | grep -q "$LABEL"; then
|
---|
46 | curl -X DELETE \
|
---|
47 | -s \
|
---|
48 | -H "Accept: application/vnd.github+json" \
|
---|
49 | -H "Authorization: Bearer $GITHUB_TOKEN" \
|
---|
50 | -H "X-GitHub-Api-Version: 2022-11-28" \
|
---|
51 | https://api.github.com/repos/$OWNER/$REPO/issues/$ISSUE_NUMBER/labels/"$LABEL" > /dev/null
|
---|
52 | echo "$LABEL removed from issue #$ISSUE_NUMBER"
|
---|
53 | else
|
---|
54 | echo "$LABEL not found on issue #$ISSUE_NUMBER"
|
---|
55 | fi
|
---|
56 | done
|
---|