Skip to content

Commit 9401f06

Browse files
committed
ci(triage): fix filter-labels step
1 parent f6274bf commit 9401f06

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

.github/workflows/triage.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Triage
33
on:
44
issues:
55
types: [opened, reopened]
6-
pull_request_target:
6+
pull_request_target:
77
types: [opened]
88
branches:
99
- main
@@ -286,19 +286,23 @@ jobs:
286286
- name: Filter existing labels
287287
id: filter-labels
288288
run: |
289-
labels=$LABELS
290-
if [ "$labels" != "[]" ]; then
291-
gh api /repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \
292-
--method POST \
293-
--input - <<< "{\"labels\": $labels}"
294-
echo "Applied labels: $labels"
289+
existing_labels=$(echo $REPO_LABELS | jq -r '.[]')
290+
selected_labels=$(echo $USER_LABELS | jq -r '.[]')
291+
292+
valid_labels=()
293+
for label in $selected_labels; do
294+
if [ -n "$label" ] && echo "$existing_labels" | grep -q "^$label$"; then
295+
valid_labels+=("$label")
296+
fi
297+
done
298+
299+
if [ ${#valid_labels[@]} -eq 0 ]; then
300+
echo "valid_labels=[]" >> $GITHUB_OUTPUT
295301
else
296-
echo "No labels to apply"
302+
echo "valid_labels=$(printf '%s\n' "${valid_labels[@]}" | jq -R . | jq -c -s .)" >> $GITHUB_OUTPUT
297303
fi
298-
299-
# Use printf with environment variable to safely log reasoning and prevent command injection
300-
printf 'Reasoning: %s\n' "$REASONING"
301304
env:
305+
REPO_LABELS: ${{ steps.fetch-labels.outputs.labels_json }}
302306
USER_LABELS: ${{ toJson(fromJSON(steps.classify-issue.outputs.json).labels) }}
303307

304308
- name: Apply labels to issue

0 commit comments

Comments
 (0)