Skip to content

Commit bbadb74

Browse files
committed
Update syntax, add on-close action
1 parent 0f0b3ab commit bbadb74

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

.github/workflows/autolabel.yaml

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,67 +13,34 @@ env:
1313
AWAITING_RESPONSE: stat:awaiting response
1414

1515
jobs:
16-
setup:
17-
name: Calculate Labels
16+
auto_label:
17+
name: Calculate and update issue labels
1818
if: ${{ !github.event.issue.pull_request }} && ${{ github.event.issue.state == 'open' }}
1919
runs-on: ubuntu-latest
20-
outputs:
21-
add_labels: ${{ steps.data.outputs.add_labels }}
22-
remove_labels: ${{ steps.data.outputs.remove_labels }}
20+
permissions:
21+
issues: write
2322

2423
steps:
25-
- name: Calculate Labels
26-
id: data
24+
- name: Calculate labels
2725
run: |
2826
ADD_LABELS=()
2927
REMOVE_LABELS=()
3028
3129
if [[ "${{ github.event.comment.author_association }}" == "MEMBER" ]]; then
32-
ADD_LABELS+=${{ env.AWAITING_RESPONSE}}
30+
ADD_LABELS+="${{ env.AWAITING_RESPONSE}}"
3331
else
34-
REMOVE_LABELS+=${{ env.AWAITING_RESPONSE}}
32+
REMOVE_LABELS+="${{ env.AWAITING_RESPONSE}}"
3533
fi
3634
37-
echo "add_labels=$(IFS=,; echo "${ADD_LABELS[*]}")" >> $GITHUB_OUTPUT
38-
echo "remove_labels=$(IFS=,; echo "${REMOVE_LABELS[*]}")" >> $GITHUB_OUTPUT
3935
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
36+
# Add further label logic here - uses bash
5537
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
38+
echo "ADD_LABELS=$(IFS=,; echo "${ADD_LABELS[*]}")" >> $GITHUB_ENV
39+
echo "REMOVE_LABELS=$(IFS=,; echo "${REMOVE_LABELS[*]}")" >> $GITHUB_ENV
6540
66-
- name: Test Print Command
67-
run: |
68-
echo "gh issue edit "$NUMBER" $ADD_LABEL $REMOVE_LABEL"
41+
- name: Update labels
42+
run: gh issue edit "$NUMBER" --add-label "$ADD_LABELS" --remove-label "$REMOVE_LABELS"
6943
env:
44+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45+
GH_REPO: ${{ github.repository }}
7046
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 }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Remove all labels when issue is closed
2+
3+
on:
4+
issues:
5+
types: [closed]
6+
7+
jobs:
8+
auto_label:
9+
name: Calculate and update issue labels
10+
if: ${{ !github.event.issue.pull_request }}
11+
runs-on: ubuntu-latest
12+
permissions:
13+
issues: write
14+
15+
steps:
16+
- name: Find labels
17+
id: data
18+
run: |
19+
# Use jq to parse the JSON array and convert to bash array
20+
LABELS=($(echo "$EXISTING_LABELS" | jq -r '.[]'))
21+
22+
# Format the labels for the gh command
23+
echo "REMOVE_LABELS=$(IFS=,; echo "${LABELS[*]}")" >> $GITHUB_ENV
24+
env:
25+
EXISTING_LABELS: ${{ toJson(github.event.issue.labels.*.name) }}
26+
27+
- name: Remove labels
28+
run: gh issue edit "$NUMBER" --remove-label "$REMOVE_LABELS"
29+
env:
30+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
GH_REPO: ${{ github.repository }}
32+
NUMBER: ${{ github.event.issue.number }}

0 commit comments

Comments
 (0)